GNU Radio 3.7.1 C++ API
pmt.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006,2009,2010,2013 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_PMT_H
00024 #define INCLUDED_PMT_H
00025 
00026 #include <pmt/api.h>
00027 #include <boost/intrusive_ptr.hpp>
00028 #include <boost/shared_ptr.hpp>
00029 #include <boost/any.hpp>
00030 #include <complex>
00031 #include <string>
00032 #include <stdint.h>
00033 #include <iosfwd>
00034 #include <stdexcept>
00035 #include <vector>
00036 
00037 namespace gr {
00038   namespace messages {
00039     class msg_accepter;
00040   }
00041 }
00042 
00043 /*!
00044  * This file defines a polymorphic type and the operations on it.
00045  *
00046  * It draws heavily on the idea of scheme and lisp data types.
00047  * The interface parallels that in Guile 1.8, with the notable
00048  * exception that these objects are transparently reference counted.
00049  */
00050 
00051 namespace pmt {
00052 
00053 /*!
00054  * \brief base class of all pmt types
00055  */
00056 class pmt_base;
00057 
00058 /*!
00059  * \brief typedef for shared pointer (transparent reference counting).
00060  * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
00061  */
00062 typedef boost::intrusive_ptr<pmt_base> pmt_t;
00063 
00064 extern PMT_API void intrusive_ptr_add_ref(pmt_base*);
00065 extern PMT_API void intrusive_ptr_release(pmt_base*);
00066 
00067 class PMT_API exception : public std::logic_error
00068 {
00069 public:
00070   exception(const std::string &msg, pmt_t obj);
00071 };
00072 
00073 class PMT_API wrong_type : public exception
00074 {
00075 public:
00076   wrong_type(const std::string &msg, pmt_t obj);
00077 };
00078 
00079 class PMT_API out_of_range : public exception
00080 {
00081 public:
00082   out_of_range(const std::string &msg, pmt_t obj);
00083 };
00084 
00085 class PMT_API notimplemented : public exception
00086 {
00087 public:
00088   notimplemented(const std::string &msg, pmt_t obj);
00089 };
00090 
00091 /*
00092  * ------------------------------------------------------------------------
00093  * Booleans.  Two constants, #t and #f.
00094  *
00095  * In predicates, anything that is not #f is considered true.
00096  * I.e., there is a single false value, #f.
00097  * ------------------------------------------------------------------------
00098  */
00099 extern PMT_API const pmt_t PMT_T;       //< \#t : boolean true constant
00100 extern PMT_API const pmt_t PMT_F;       //< \#f : boolean false constant
00101 
00102 //! Return true if obj is \#t or \#f, else return false.
00103 PMT_API bool is_bool(pmt_t obj);
00104 
00105 //! Return false if obj is \#f, else return true.
00106 PMT_API bool is_true(pmt_t obj);
00107 
00108 //! Return true if obj is \#f, else return true.
00109 PMT_API bool is_false(pmt_t obj);
00110 
00111 //! Return \#f is val is false, else return \#t.
00112 PMT_API pmt_t from_bool(bool val);
00113 
00114 //! Return true if val is pmt::True, return false when val is pmt::PMT_F,
00115 // else raise wrong_type exception.
00116 PMT_API bool to_bool(pmt_t val);
00117 
00118 /*
00119  * ------------------------------------------------------------------------
00120  *                             Symbols
00121  * ------------------------------------------------------------------------
00122  */
00123 
00124 //! Return true if obj is a symbol, else false.
00125 PMT_API bool is_symbol(const pmt_t& obj);
00126 
00127 //! Return the symbol whose name is \p s.
00128 PMT_API pmt_t string_to_symbol(const std::string &s);
00129 
00130 //! Alias for pmt_string_to_symbol
00131 PMT_API pmt_t intern(const std::string &s);
00132 
00133 
00134 /*!
00135  * If \p is a symbol, return the name of the symbol as a string.
00136  * Otherwise, raise the wrong_type exception.
00137  */
00138 PMT_API const std::string symbol_to_string(const pmt_t& sym);
00139 
00140 /*
00141  * ------------------------------------------------------------------------
00142  *           Numbers: we support integer, real and complex
00143  * ------------------------------------------------------------------------
00144  */
00145 
00146 //! Return true if obj is any kind of number, else false.
00147 PMT_API bool is_number(pmt_t obj);
00148 
00149 /*
00150  * ------------------------------------------------------------------------
00151  *                             Integers
00152  * ------------------------------------------------------------------------
00153  */
00154 
00155 //! Return true if \p x is an integer number, else false
00156 PMT_API bool is_integer(pmt_t x);
00157 
00158 //! Return the pmt value that represents the integer \p x.
00159 PMT_API pmt_t from_long(long x);
00160 
00161 /*!
00162  * \brief Convert pmt to long if possible.
00163  *
00164  * When \p x represents an exact integer that fits in a long,
00165  * return that integer.  Else raise an exception, either wrong_type
00166  * when x is not an exact integer, or out_of_range when it doesn't fit.
00167  */
00168 PMT_API long to_long(pmt_t x);
00169 
00170 /*
00171  * ------------------------------------------------------------------------
00172  *                             uint64_t
00173  * ------------------------------------------------------------------------
00174  */
00175 
00176 //! Return true if \p x is an uint64 number, else false
00177 PMT_API bool is_uint64(pmt_t x);
00178 
00179 //! Return the pmt value that represents the uint64 \p x.
00180 PMT_API pmt_t from_uint64(uint64_t x);
00181 
00182 /*!
00183  * \brief Convert pmt to uint64 if possible.
00184  *
00185  * When \p x represents an exact integer that fits in a uint64,
00186  * return that uint64.  Else raise an exception, either wrong_type
00187  * when x is not an exact uint64, or out_of_range when it doesn't fit.
00188  */
00189 PMT_API uint64_t to_uint64(pmt_t x);
00190 
00191 /*
00192  * ------------------------------------------------------------------------
00193  *                              Reals
00194  * ------------------------------------------------------------------------
00195  */
00196 
00197 /*
00198  * \brief Return true if \p obj is a real number, else false.
00199  */
00200 PMT_API bool is_real(pmt_t obj);
00201 
00202 //! Return the pmt value that represents double \p x.
00203 PMT_API pmt_t from_double(double x);
00204 
00205 /*!
00206  * \brief Convert pmt to double if possible.
00207  *
00208  * Returns the number closest to \p val that is representable
00209  * as a double.  The argument \p val must be a real or integer, otherwise
00210  * a wrong_type exception is raised.
00211  */
00212 PMT_API double to_double(pmt_t x);
00213 
00214 /*
00215  * ------------------------------------------------------------------------
00216  *                             Complex
00217  * ------------------------------------------------------------------------
00218  */
00219 
00220 /*!
00221  * \brief return true if \p obj is a complex number, false otherwise.
00222  */
00223 PMT_API bool is_complex(pmt_t obj);
00224 
00225 //! Return a complex number constructed of the given real and imaginary parts.
00226 PMT_API pmt_t make_rectangular(double re, double im);
00227 
00228 //! Return a complex number constructed of the given real and imaginary parts.
00229 PMT_API pmt_t from_complex(double re, double im);
00230 
00231 //! Return a complex number constructed of the given a complex number.
00232 PMT_API pmt_t from_complex(const std::complex<double> &z);
00233 
00234 //! Return a complex number constructed of the given real and imaginary parts.
00235 PMT_API pmt_t pmt_from_complex(double re, double im);
00236 
00237 //! Return a complex number constructed of the given a complex number.
00238 PMT_API pmt_t pmt_from_complex(const std::complex<double> &z);
00239 
00240 /*!
00241  * If \p z is complex, real or integer, return the closest complex<double>.
00242  * Otherwise, raise the wrong_type exception.
00243  */
00244 PMT_API std::complex<double> to_complex(pmt_t z);
00245 
00246 /*
00247  * ------------------------------------------------------------------------
00248  *                              Pairs
00249  * ------------------------------------------------------------------------
00250  */
00251 
00252 extern PMT_API const pmt_t PMT_NIL;     //< the empty list
00253 
00254 //! Return true if \p x is the empty list, otherwise return false.
00255 PMT_API bool is_null(const pmt_t& x);
00256 
00257 //! Return true if \p obj is a pair, else false.
00258 PMT_API bool is_pair(const pmt_t& obj);
00259 
00260 //! Return a newly allocated pair whose car is \p x and whose cdr is \p y.
00261 PMT_API pmt_t cons(const pmt_t& x, const pmt_t& y);
00262 
00263 //! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type.
00264 PMT_API pmt_t car(const pmt_t& pair);
00265 
00266 //! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type.
00267 PMT_API pmt_t cdr(const pmt_t& pair);
00268 
00269 //! Stores \p value in the car field of \p pair.
00270 PMT_API void set_car(pmt_t pair, pmt_t value);
00271 
00272 //! Stores \p value in the cdr field of \p pair.
00273 PMT_API void set_cdr(pmt_t pair, pmt_t value);
00274 
00275 PMT_API pmt_t caar(pmt_t pair);
00276 PMT_API pmt_t cadr(pmt_t pair);
00277 PMT_API pmt_t cdar(pmt_t pair);
00278 PMT_API pmt_t cddr(pmt_t pair);
00279 PMT_API pmt_t caddr(pmt_t pair);
00280 PMT_API pmt_t cadddr(pmt_t pair);
00281 
00282 /*
00283  * ------------------------------------------------------------------------
00284  *                                Tuples
00285  *
00286  * Store a fixed number of objects.  Tuples are not modifiable, and thus
00287  * are excellent for use as messages.  Indexing is zero based.
00288  * Access time to an element is O(1).
00289  * ------------------------------------------------------------------------
00290  */
00291 
00292 //! Return true if \p x is a tuple, othewise false.
00293 PMT_API bool is_tuple(pmt_t x);
00294 
00295 PMT_API pmt_t make_tuple();
00296 PMT_API pmt_t make_tuple(const pmt_t &e0);
00297 PMT_API pmt_t make_tuple(const pmt_t &e0, const pmt_t &e1);
00298 PMT_API pmt_t make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2);
00299 PMT_API pmt_t make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3);
00300 PMT_API pmt_t make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4);
00301 PMT_API pmt_t make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5);
00302 PMT_API pmt_t make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6);
00303 PMT_API pmt_t make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6, const pmt_t &e7);
00304 PMT_API pmt_t make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6, const pmt_t &e7, const pmt_t &e8);
00305 PMT_API pmt_t make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6, const pmt_t &e7, const pmt_t &e8, const pmt_t &e9);
00306 
00307 /*!
00308  * If \p x is a vector or proper list, return a tuple containing the elements of x
00309  */
00310 PMT_API pmt_t to_tuple(const pmt_t &x);
00311 
00312 /*!
00313  * Return the contents of position \p k of \p tuple.
00314  * \p k must be a valid index of \p tuple.
00315  */
00316 PMT_API pmt_t tuple_ref(const pmt_t &tuple, size_t k);
00317 
00318 /*
00319  * ------------------------------------------------------------------------
00320  *                             Vectors
00321  *
00322  * These vectors can hold any kind of objects.  Indexing is zero based.
00323  * ------------------------------------------------------------------------
00324  */
00325 
00326 //! Return true if \p x is a vector, othewise false.
00327 PMT_API bool is_vector(pmt_t x);
00328 
00329 //! Make a vector of length \p k, with initial values set to \p fill
00330 PMT_API pmt_t make_vector(size_t k, pmt_t fill);
00331 
00332 /*!
00333  * Return the contents of position \p k of \p vector.
00334  * \p k must be a valid index of \p vector.
00335  */
00336 PMT_API pmt_t vector_ref(pmt_t vector, size_t k);
00337 
00338 //! Store \p obj in position \p k.
00339 PMT_API void vector_set(pmt_t vector, size_t k, pmt_t obj);
00340 
00341 //! Store \p fill in every position of \p vector
00342 PMT_API void vector_fill(pmt_t vector, pmt_t fill);
00343 
00344 /*
00345  * ------------------------------------------------------------------------
00346  *                    Binary Large Objects (BLOBs)
00347  *
00348  * Handy for passing around uninterpreted chunks of memory.
00349  * ------------------------------------------------------------------------
00350  */
00351 
00352 //! Return true if \p x is a blob, othewise false.
00353 PMT_API bool is_blob(pmt_t x);
00354 
00355 /*!
00356  * \brief Make a blob given a pointer and length in bytes
00357  *
00358  * \param buf is the pointer to data to use to create blob
00359  * \param len is the size of the data in bytes.
00360  *
00361  * The data is copied into the blob.
00362  */
00363 PMT_API pmt_t make_blob(const void *buf, size_t len);
00364 
00365 //! Return a pointer to the blob's data
00366 PMT_API const void *blob_data(pmt_t blob);
00367 
00368 //! Return the blob's length in bytes
00369 PMT_API size_t blob_length(pmt_t blob);
00370 
00371 /*!
00372  * <pre>
00373  * ------------------------------------------------------------------------
00374  *                     Uniform Numeric Vectors
00375  *
00376  * A uniform numeric vector is a vector whose elements are all of single
00377  * numeric type.  pmt offers uniform numeric vectors for signed and
00378  * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
00379  * floating point values, and complex floating-point numbers of these
00380  * two sizes.  Indexing is zero based.
00381  *
00382  * The names of the functions include these tags in their names:
00383  *
00384  *    u8  unsigned 8-bit integers
00385  *    s8  signed 8-bit integers
00386  *   u16  unsigned 16-bit integers
00387  *   s16  signed 16-bit integers
00388  *   u32  unsigned 32-bit integers
00389  *   s32  signed 32-bit integers
00390  *   u64  unsigned 64-bit integers
00391  *   s64  signed 64-bit integers
00392  *   f32  the C++ type float
00393  *   f64  the C++ type double
00394  *   c32  the C++ type complex<float>
00395  *   c64  the C++ type complex<double>
00396  * ------------------------------------------------------------------------
00397  * </pre>
00398  */
00399 
00400 //! true if \p x is any kind of uniform numeric vector
00401 PMT_API bool is_uniform_vector(pmt_t x);
00402 
00403 PMT_API bool is_u8vector(pmt_t x);
00404 PMT_API bool is_s8vector(pmt_t x);
00405 PMT_API bool is_u16vector(pmt_t x);
00406 PMT_API bool is_s16vector(pmt_t x);
00407 PMT_API bool is_u32vector(pmt_t x);
00408 PMT_API bool is_s32vector(pmt_t x);
00409 PMT_API bool is_u64vector(pmt_t x);
00410 PMT_API bool is_s64vector(pmt_t x);
00411 PMT_API bool is_f32vector(pmt_t x);
00412 PMT_API bool is_f64vector(pmt_t x);
00413 PMT_API bool is_c32vector(pmt_t x);
00414 PMT_API bool is_c64vector(pmt_t x);
00415 
00416 PMT_API pmt_t make_u8vector(size_t k, uint8_t fill);
00417 PMT_API pmt_t make_s8vector(size_t k, int8_t fill);
00418 PMT_API pmt_t make_u16vector(size_t k, uint16_t fill);
00419 PMT_API pmt_t make_s16vector(size_t k, int16_t fill);
00420 PMT_API pmt_t make_u32vector(size_t k, uint32_t fill);
00421 PMT_API pmt_t make_s32vector(size_t k, int32_t fill);
00422 PMT_API pmt_t make_u64vector(size_t k, uint64_t fill);
00423 PMT_API pmt_t make_s64vector(size_t k, int64_t fill);
00424 PMT_API pmt_t make_f32vector(size_t k, float fill);
00425 PMT_API pmt_t make_f64vector(size_t k, double fill);
00426 PMT_API pmt_t make_c32vector(size_t k, std::complex<float> fill);
00427 PMT_API pmt_t make_c64vector(size_t k, std::complex<double> fill);
00428 
00429 PMT_API pmt_t init_u8vector(size_t k, const uint8_t *data);
00430 PMT_API pmt_t init_u8vector(size_t k, const std::vector<uint8_t> &data);
00431 PMT_API pmt_t init_s8vector(size_t k, const int8_t *data);
00432 PMT_API pmt_t init_s8vector(size_t k, const std::vector<int8_t> &data);
00433 PMT_API pmt_t init_u16vector(size_t k, const uint16_t *data);
00434 PMT_API pmt_t init_u16vector(size_t k, const std::vector<uint16_t> &data);
00435 PMT_API pmt_t init_s16vector(size_t k, const int16_t *data);
00436 PMT_API pmt_t init_s16vector(size_t k, const std::vector<int16_t> &data);
00437 PMT_API pmt_t init_u32vector(size_t k, const uint32_t *data);
00438 PMT_API pmt_t init_u32vector(size_t k, const std::vector<uint32_t> &data);
00439 PMT_API pmt_t init_s32vector(size_t k, const int32_t *data);
00440 PMT_API pmt_t init_s32vector(size_t k, const std::vector<int32_t> &data);
00441 PMT_API pmt_t init_u64vector(size_t k, const uint64_t *data);
00442 PMT_API pmt_t init_u64vector(size_t k, const std::vector<uint64_t> &data);
00443 PMT_API pmt_t init_s64vector(size_t k, const int64_t *data);
00444 PMT_API pmt_t init_s64vector(size_t k, const std::vector<int64_t> &data);
00445 PMT_API pmt_t init_f32vector(size_t k, const float *data);
00446 PMT_API pmt_t init_f32vector(size_t k, const std::vector<float> &data);
00447 PMT_API pmt_t init_f64vector(size_t k, const double *data);
00448 PMT_API pmt_t init_f64vector(size_t k, const std::vector<double> &data);
00449 PMT_API pmt_t init_c32vector(size_t k, const std::complex<float> *data);
00450 PMT_API pmt_t init_c32vector(size_t k, const std::vector<std::complex<float> > &data);
00451 PMT_API pmt_t init_c64vector(size_t k, const std::complex<double> *data);
00452 PMT_API pmt_t init_c64vector(size_t k, const std::vector<std::complex<double> > &data);
00453 
00454 PMT_API uint8_t  u8vector_ref(pmt_t v, size_t k);
00455 PMT_API int8_t   s8vector_ref(pmt_t v, size_t k);
00456 PMT_API uint16_t u16vector_ref(pmt_t v, size_t k);
00457 PMT_API int16_t  s16vector_ref(pmt_t v, size_t k);
00458 PMT_API uint32_t u32vector_ref(pmt_t v, size_t k);
00459 PMT_API int32_t  s32vector_ref(pmt_t v, size_t k);
00460 PMT_API uint64_t u64vector_ref(pmt_t v, size_t k);
00461 PMT_API int64_t  s64vector_ref(pmt_t v, size_t k);
00462 PMT_API float    f32vector_ref(pmt_t v, size_t k);
00463 PMT_API double   f64vector_ref(pmt_t v, size_t k);
00464 PMT_API std::complex<float>  c32vector_ref(pmt_t v, size_t k);
00465 PMT_API std::complex<double> c64vector_ref(pmt_t v, size_t k);
00466 
00467 PMT_API void u8vector_set(pmt_t v, size_t k, uint8_t x);  //< v[k] = x
00468 PMT_API void s8vector_set(pmt_t v, size_t k, int8_t x);
00469 PMT_API void u16vector_set(pmt_t v, size_t k, uint16_t x);
00470 PMT_API void s16vector_set(pmt_t v, size_t k, int16_t x);
00471 PMT_API void u32vector_set(pmt_t v, size_t k, uint32_t x);
00472 PMT_API void s32vector_set(pmt_t v, size_t k, int32_t x);
00473 PMT_API void u64vector_set(pmt_t v, size_t k, uint64_t x);
00474 PMT_API void s64vector_set(pmt_t v, size_t k, int64_t x);
00475 PMT_API void f32vector_set(pmt_t v, size_t k, float x);
00476 PMT_API void f64vector_set(pmt_t v, size_t k, double x);
00477 PMT_API void c32vector_set(pmt_t v, size_t k, std::complex<float> x);
00478 PMT_API void c64vector_set(pmt_t v, size_t k, std::complex<double> x);
00479 
00480 // Return const pointers to the elements
00481 
00482 PMT_API const void *uniform_vector_elements(pmt_t v, size_t &len);  //< works with any; len is in bytes
00483 
00484 PMT_API const uint8_t  *u8vector_elements(pmt_t v, size_t &len);  //< len is in elements
00485 PMT_API const int8_t   *s8vector_elements(pmt_t v, size_t &len);  //< len is in elements
00486 PMT_API const uint16_t *u16vector_elements(pmt_t v, size_t &len); //< len is in elements
00487 PMT_API const int16_t  *s16vector_elements(pmt_t v, size_t &len); //< len is in elements
00488 PMT_API const uint32_t *u32vector_elements(pmt_t v, size_t &len); //< len is in elements
00489 PMT_API const int32_t  *s32vector_elements(pmt_t v, size_t &len); //< len is in elements
00490 PMT_API const uint64_t *u64vector_elements(pmt_t v, size_t &len); //< len is in elements
00491 PMT_API const int64_t  *s64vector_elements(pmt_t v, size_t &len); //< len is in elements
00492 PMT_API const float    *f32vector_elements(pmt_t v, size_t &len); //< len is in elements
00493 PMT_API const double   *f64vector_elements(pmt_t v, size_t &len); //< len is in elements
00494 PMT_API const std::complex<float>  *c32vector_elements(pmt_t v, size_t &len); //< len is in elements
00495 PMT_API const std::complex<double> *c64vector_elements(pmt_t v, size_t &len); //< len is in elements
00496 
00497 // len is in elements
00498 PMT_API const std::vector<uint8_t>  u8vector_elements(pmt_t v);
00499 PMT_API const std::vector<int8_t>   s8vector_elements(pmt_t v);
00500 PMT_API const std::vector<uint16_t> u16vector_elements(pmt_t v);
00501 PMT_API const std::vector<int16_t>  s16vector_elements(pmt_t v);
00502 PMT_API const std::vector<uint32_t> u32vector_elements(pmt_t v);
00503 PMT_API const std::vector<int32_t>  s32vector_elements(pmt_t v);
00504 PMT_API const std::vector<uint64_t> u64vector_elements(pmt_t v);
00505 PMT_API const std::vector<int64_t>  s64vector_elements(pmt_t v);
00506 PMT_API const std::vector<float>    f32vector_elements(pmt_t v);
00507 PMT_API const std::vector<double>   f64vector_elements(pmt_t v);
00508 PMT_API const std::vector<std::complex<float> > c32vector_elements(pmt_t v);
00509 PMT_API const std::vector<std::complex<double> > c64vector_elements(pmt_t v);
00510 
00511 // len is in elements
00512 PMT_API const std::vector<uint8_t>  pmt_u8vector_elements(pmt_t v);
00513 PMT_API const std::vector<int8_t>   pmt_s8vector_elements(pmt_t v);
00514 PMT_API const std::vector<uint16_t> pmt_u16vector_elements(pmt_t v);
00515 PMT_API const std::vector<int16_t>  pmt_s16vector_elements(pmt_t v);
00516 PMT_API const std::vector<uint32_t> pmt_u32vector_elements(pmt_t v);
00517 PMT_API const std::vector<int32_t>  pmt_s32vector_elements(pmt_t v);
00518 PMT_API const std::vector<uint64_t> pmt_u64vector_elements(pmt_t v);
00519 PMT_API const std::vector<int64_t>  pmt_s64vector_elements(pmt_t v);
00520 PMT_API const std::vector<float>    pmt_f32vector_elements(pmt_t v);
00521 PMT_API const std::vector<double>   pmt_f64vector_elements(pmt_t v);
00522 PMT_API const std::vector<std::complex<float> > pmt_c32vector_elements(pmt_t v);
00523 PMT_API const std::vector<std::complex<double> > pmt_c64vector_elements(pmt_t v);
00524 
00525 // Return non-const pointers to the elements
00526 
00527 PMT_API void *uniform_vector_writable_elements(pmt_t v, size_t &len);  //< works with any; len is in bytes
00528 
00529 PMT_API uint8_t  *u8vector_writable_elements(pmt_t v, size_t &len);  //< len is in elements
00530 PMT_API int8_t   *s8vector_writable_elements(pmt_t v, size_t &len);  //< len is in elements
00531 PMT_API uint16_t *u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00532 PMT_API int16_t  *s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00533 PMT_API uint32_t *u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00534 PMT_API int32_t  *s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00535 PMT_API uint64_t *u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00536 PMT_API int64_t  *s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00537 PMT_API float    *f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00538 PMT_API double   *f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00539 PMT_API std::complex<float>  *c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00540 PMT_API std::complex<double> *c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00541 
00542 /*
00543  * ------------------------------------------------------------------------
00544  *         Dictionary (a.k.a associative array, hash, map)
00545  *
00546  * This is a functional data structure that is persistent.  Updating a
00547  * functional data structure does not destroy the existing version, but
00548  * rather creates a new version that coexists with the old.
00549  * ------------------------------------------------------------------------
00550  */
00551 
00552 //! Return true if \p obj is a dictionary
00553 PMT_API bool is_dict(const pmt_t &obj);
00554 
00555 //! Make an empty dictionary
00556 PMT_API pmt_t make_dict();
00557 
00558 //! Return a new dictionary with \p key associated with \p value.
00559 PMT_API pmt_t dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value);
00560 
00561 //! Return a new dictionary with \p key removed.
00562 PMT_API pmt_t dict_delete(const pmt_t &dict, const pmt_t &key);
00563 
00564 //! Return true if \p key exists in \p dict
00565 PMT_API bool  dict_has_key(const pmt_t &dict, const pmt_t &key);
00566 
00567 //! If \p key exists in \p dict, return associated value; otherwise return \p not_found.
00568 PMT_API pmt_t dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t &not_found);
00569 
00570 //! Return list of (key . value) pairs
00571 PMT_API pmt_t dict_items(pmt_t dict);
00572 
00573 //! Return list of keys
00574 PMT_API pmt_t dict_keys(pmt_t dict);
00575 
00576 //! Return list of values
00577 PMT_API pmt_t dict_values(pmt_t dict);
00578 
00579 /*
00580  * ------------------------------------------------------------------------
00581  *   Any (wraps boost::any -- can be used to wrap pretty much anything)
00582  *
00583  * Cannot be serialized or used across process boundaries.
00584  * See http://www.boost.org/doc/html/any.html
00585  * ------------------------------------------------------------------------
00586  */
00587 
00588 //! Return true if \p obj is an any
00589 PMT_API bool is_any(pmt_t obj);
00590 
00591 //! make an any
00592 PMT_API pmt_t make_any(const boost::any &any);
00593 
00594 //! Return underlying boost::any
00595 PMT_API boost::any any_ref(pmt_t obj);
00596 
00597 //! Store \p any in \p obj
00598 PMT_API void any_set(pmt_t obj, const boost::any &any);
00599 
00600 
00601 /*
00602  * ------------------------------------------------------------------------
00603  *    msg_accepter -- pmt representation of pmt::msg_accepter
00604  * ------------------------------------------------------------------------
00605  */
00606 //! Return true if \p obj is a msg_accepter
00607 PMT_API bool is_msg_accepter(const pmt_t &obj);
00608 
00609 //! make a msg_accepter
00610 PMT_API pmt_t make_msg_accepter(boost::shared_ptr<gr::messages::msg_accepter> ma);
00611 
00612 //! Return underlying msg_accepter
00613 PMT_API boost::shared_ptr<gr::messages::msg_accepter> msg_accepter_ref(const pmt_t &obj);
00614 
00615 /*
00616  * ------------------------------------------------------------------------
00617  *                        General functions
00618  * ------------------------------------------------------------------------
00619  */
00620 
00621 //! Return true if x and y are the same object; otherwise return false.
00622 PMT_API bool eq(const pmt_t& x, const pmt_t& y);
00623 
00624 /*!
00625  * \brief Return true if x and y should normally be regarded as the same object, else false.
00626  *
00627  * <pre>
00628  * eqv returns true if:
00629  *   x and y are the same object.
00630  *   x and y are both \#t or both \#f.
00631  *   x and y are both symbols and their names are the same.
00632  *   x and y are both numbers, and are numerically equal.
00633  *   x and y are both the empty list (nil).
00634  *   x and y are pairs or vectors that denote same location in store.
00635  * </pre>
00636  */
00637 PMT_API bool eqv(const pmt_t& x, const pmt_t& y);
00638 
00639 /*!
00640  * pmt::equal recursively compares the contents of pairs and vectors,
00641  * applying pmt::eqv on other objects such as numbers and symbols.
00642  * pmt::equal may fail to terminate if its arguments are circular data
00643  * structures.
00644  */
00645 PMT_API bool equal(const pmt_t& x, const pmt_t& y);
00646 
00647 
00648 //! Return the number of elements in v
00649 PMT_API size_t length(const pmt_t& v);
00650 
00651 /*!
00652  * \brief Find the first pair in \p alist whose car field is \p obj
00653  *  and return that pair.
00654  *
00655  * \p alist (for "association list") must be a list of pairs.  If no pair
00656  * in \p alist has \p obj as its car then \#f is returned.
00657  * Uses pmt::eq to compare \p obj with car fields of the pairs in \p alist.
00658  */
00659 PMT_API pmt_t assq(pmt_t obj, pmt_t alist);
00660 
00661 /*!
00662  * \brief Find the first pair in \p alist whose car field is \p obj
00663  *  and return that pair.
00664  *
00665  * \p alist (for "association list") must be a list of pairs.  If no pair
00666  * in \p alist has \p obj as its car then \#f is returned.
00667  * Uses pmt::eqv to compare \p obj with car fields of the pairs in \p alist.
00668  */
00669 PMT_API pmt_t assv(pmt_t obj, pmt_t alist);
00670 
00671 /*!
00672  * \brief Find the first pair in \p alist whose car field is \p obj
00673  *  and return that pair.
00674  *
00675  * \p alist (for "association list") must be a list of pairs.  If no pair
00676  * in \p alist has \p obj as its car then \#f is returned.
00677  * Uses pmt::equal to compare \p obj with car fields of the pairs in \p alist.
00678  */
00679 PMT_API pmt_t assoc(pmt_t obj, pmt_t alist);
00680 
00681 /*!
00682  * \brief Apply \p proc element-wise to the elements of list and returns
00683  * a list of the results, in order.
00684  *
00685  * \p list must be a list.  The dynamic order in which \p proc is
00686  * applied to the elements of \p list is unspecified.
00687  */
00688 PMT_API pmt_t map(pmt_t proc(const pmt_t&), pmt_t list);
00689 
00690 /*!
00691  * \brief reverse \p list.
00692  *
00693  * \p list must be a proper list.
00694  */
00695 PMT_API pmt_t reverse(pmt_t list);
00696 
00697 /*!
00698  * \brief destructively reverse \p list.
00699  *
00700  * \p list must be a proper list.
00701  */
00702 PMT_API pmt_t reverse_x(pmt_t list);
00703 
00704 /*!
00705  * \brief (acons x y a) == (cons (cons x y) a)
00706  */
00707 inline static pmt_t
00708 acons(pmt_t x, pmt_t y, pmt_t a)
00709 {
00710   return cons(cons(x, y), a);
00711 }
00712 
00713 /*!
00714  * \brief locates \p nth element of \n list where the car is the 'zeroth' element.
00715  */
00716 PMT_API pmt_t nth(size_t n, pmt_t list);
00717 
00718 /*!
00719  * \brief returns the tail of \p list that would be obtained by calling
00720  * cdr \p n times in succession.
00721  */
00722 PMT_API pmt_t nthcdr(size_t n, pmt_t list);
00723 
00724 /*!
00725  * \brief Return the first sublist of \p list whose car is \p obj.
00726  * If \p obj does not occur in \p list, then \#f is returned.
00727  * pmt::memq use pmt::eq to compare \p obj with the elements of \p list.
00728  */
00729 PMT_API pmt_t memq(pmt_t obj, pmt_t list);
00730 
00731 /*!
00732  * \brief Return the first sublist of \p list whose car is \p obj.
00733  * If \p obj does not occur in \p list, then \#f is returned.
00734  * pmt::memv use pmt::eqv to compare \p obj with the elements of \p list.
00735  */
00736 PMT_API pmt_t memv(pmt_t obj, pmt_t list);
00737 
00738 /*!
00739  * \brief Return the first sublist of \p list whose car is \p obj.
00740  * If \p obj does not occur in \p list, then \#f is returned.
00741  * pmt::member use pmt::equal to compare \p obj with the elements of \p list.
00742  */
00743 PMT_API pmt_t member(pmt_t obj, pmt_t list);
00744 
00745 /*!
00746  * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise.
00747  * Comparisons are done with pmt::eqv.
00748  */
00749 PMT_API bool subsetp(pmt_t list1, pmt_t list2);
00750 
00751 /*!
00752  * \brief Return a list of length 1 containing \p x1
00753  */
00754 PMT_API pmt_t list1(const pmt_t& x1);
00755 
00756 /*!
00757  * \brief Return a list of length 2 containing \p x1, \p x2
00758  */
00759 PMT_API pmt_t list2(const pmt_t& x1, const pmt_t& x2);
00760 
00761 /*!
00762  * \brief Return a list of length 3 containing \p x1, \p x2, \p x3
00763  */
00764 PMT_API pmt_t list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3);
00765 
00766 /*!
00767  * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4
00768  */
00769 PMT_API pmt_t list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4);
00770 
00771 /*!
00772  * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5
00773  */
00774 PMT_API pmt_t list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5);
00775 
00776 /*!
00777  * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p
00778  * x5, \p x6
00779  */
00780 PMT_API pmt_t list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6);
00781 
00782 /*!
00783  * \brief Return \p list with \p item added to it.
00784  */
00785 PMT_API pmt_t list_add(pmt_t list, const pmt_t& item);
00786 
00787 /*!
00788  * \brief Return \p list with \p item removed from it.
00789  */
00790 PMT_API pmt_t list_rm(pmt_t list, const pmt_t& item);
00791 
00792 /*!
00793  * \brief Return bool of \p list contains \p item
00794  */
00795 PMT_API bool list_has(pmt_t list, const pmt_t& item);
00796 
00797 
00798 /*
00799  * ------------------------------------------------------------------------
00800  *                           read / write
00801  * ------------------------------------------------------------------------
00802  */
00803 extern PMT_API const pmt_t PMT_EOF;     //< The end of file object
00804 
00805 //! return true if obj is the EOF object, otherwise return false.
00806 PMT_API bool is_eof_object(pmt_t obj);
00807 
00808 /*!
00809  * read converts external representations of pmt objects into the
00810  * objects themselves.  Read returns the next object parsable from
00811  * the given input port, updating port to point to the first
00812  * character past the end of the external representation of the
00813  * object.
00814  *
00815  * If an end of file is encountered in the input before any
00816  * characters are found that can begin an object, then an end of file
00817  * object is returned.   The port remains open, and further attempts
00818  * to read will also return an end of file object.  If an end of file
00819  * is encountered after the beginning of an object's external
00820  * representation, but the external representation is incomplete and
00821  * therefore not parsable, an error is signaled.
00822  */
00823 PMT_API pmt_t read(std::istream &port);
00824 
00825 /*!
00826  * Write a written representation of \p obj to the given \p port.
00827  */
00828 PMT_API void write(pmt_t obj, std::ostream &port);
00829 
00830 /*!
00831  * Return a string representation of \p obj.
00832  * This is the same output as would be generated by pmt::write.
00833  */
00834 PMT_API std::string write_string(pmt_t obj);
00835 
00836 
00837 PMT_API std::ostream& operator<<(std::ostream &os, pmt_t obj);
00838 
00839 /*!
00840  * \brief Write pmt string representation to stdout.
00841  */
00842 PMT_API void print(pmt_t v);
00843 
00844 
00845 /*
00846  * ------------------------------------------------------------------------
00847  *                    portable byte stream representation
00848  * ------------------------------------------------------------------------
00849  */
00850 /*!
00851  * \brief Write portable byte-serial representation of \p obj to \p sink
00852  */
00853 PMT_API bool serialize(pmt_t obj, std::streambuf &sink);
00854 
00855 /*!
00856  * \brief Create obj from portable byte-serial representation
00857  */
00858 PMT_API pmt_t deserialize(std::streambuf &source);
00859 
00860 
00861 PMT_API void dump_sizeof();     // debugging
00862 
00863 /*!
00864  * \brief Provide a simple string generating interface to pmt's serialize function
00865  */
00866 PMT_API std::string serialize_str(pmt_t obj);
00867 
00868 /*!
00869  * \brief Provide a simple string generating interface to pmt's deserialize function
00870  */
00871 PMT_API pmt_t deserialize_str(std::string str);
00872 
00873 /*!
00874  * \brief Provide a comparator function object to allow pmt use in stl types
00875  */
00876 class comperator {
00877     public:
00878         bool operator()(pmt::pmt_t const& p1, pmt::pmt_t const& p2) const
00879             { return pmt::eqv(p1,p2)?false:p1.get()>p2.get(); }
00880     };
00881 
00882 } /* namespace pmt */
00883 
00884 #include <pmt/pmt_sugar.h>
00885 
00886 #endif /* INCLUDED_PMT_H */