GNU Radio 3.6.5 C++ API

pmt.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006,2009,2010 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 <gruel/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 gruel {
00038   class msg_accepter;
00039 };
00040 
00041 /*!
00042  * This file defines a polymorphic type and the operations on it.
00043  *
00044  * It draws heavily on the idea of scheme and lisp data types.
00045  * The interface parallels that in Guile 1.8, with the notable
00046  * exception that these objects are transparently reference counted.
00047  */
00048 
00049 namespace pmt {
00050 
00051 /*!
00052  * \brief base class of all pmt types
00053  */
00054 class pmt_base;
00055 
00056 /*!
00057  * \brief typedef for shared pointer (transparent reference counting).
00058  * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
00059  */
00060 typedef boost::intrusive_ptr<pmt_base> pmt_t;
00061 
00062 extern GRUEL_API void intrusive_ptr_add_ref(pmt_base*);
00063 extern GRUEL_API void intrusive_ptr_release(pmt_base*);
00064 
00065 class GRUEL_API pmt_exception : public std::logic_error
00066 {
00067 public:
00068   pmt_exception(const std::string &msg, pmt_t obj);
00069 };
00070 
00071 class GRUEL_API pmt_wrong_type : public pmt_exception
00072 {
00073 public:
00074   pmt_wrong_type(const std::string &msg, pmt_t obj);
00075 };
00076 
00077 class GRUEL_API pmt_out_of_range : public pmt_exception
00078 {
00079 public:
00080   pmt_out_of_range(const std::string &msg, pmt_t obj);
00081 };
00082 
00083 class GRUEL_API pmt_notimplemented : public pmt_exception
00084 {
00085 public:
00086   pmt_notimplemented(const std::string &msg, pmt_t obj);
00087 };
00088 
00089 /*
00090  * ------------------------------------------------------------------------
00091  * Booleans.  Two constants, #t and #f.
00092  *
00093  * In predicates, anything that is not #f is considered true.
00094  * I.e., there is a single false value, #f.
00095  * ------------------------------------------------------------------------
00096  */
00097 extern GRUEL_API const pmt_t PMT_T;     //< \#t : boolean true constant
00098 extern GRUEL_API const pmt_t PMT_F;     //< \#f : boolean false constant
00099 
00100 //! Return true if obj is \#t or \#f, else return false.
00101 GRUEL_API bool pmt_is_bool(pmt_t obj);
00102 
00103 //! Return false if obj is \#f, else return true.
00104 GRUEL_API bool pmt_is_true(pmt_t obj);
00105 
00106 //! Return true if obj is \#f, else return true.
00107 GRUEL_API bool pmt_is_false(pmt_t obj);
00108 
00109 //! Return \#f is val is false, else return \#t.
00110 GRUEL_API pmt_t pmt_from_bool(bool val);
00111 
00112 //! Return true if val is PMT_T, return false when val is PMT_F,
00113 // else raise wrong_type exception.
00114 GRUEL_API bool pmt_to_bool(pmt_t val);
00115 
00116 /*
00117  * ------------------------------------------------------------------------
00118  *                             Symbols
00119  * ------------------------------------------------------------------------
00120  */
00121 
00122 //! Return true if obj is a symbol, else false.
00123 GRUEL_API bool pmt_is_symbol(const pmt_t& obj);
00124 
00125 //! Return the symbol whose name is \p s.
00126 GRUEL_API pmt_t pmt_string_to_symbol(const std::string &s);
00127 
00128 //! Alias for pmt_string_to_symbol
00129 GRUEL_API pmt_t pmt_intern(const std::string &s);
00130 
00131 
00132 /*!
00133  * If \p is a symbol, return the name of the symbol as a string.
00134  * Otherwise, raise the wrong_type exception.
00135  */
00136 GRUEL_API const std::string pmt_symbol_to_string(const pmt_t& sym);
00137 
00138 /*
00139  * ------------------------------------------------------------------------
00140  *           Numbers: we support integer, real and complex
00141  * ------------------------------------------------------------------------
00142  */
00143 
00144 //! Return true if obj is any kind of number, else false.
00145 GRUEL_API bool pmt_is_number(pmt_t obj);
00146 
00147 /*
00148  * ------------------------------------------------------------------------
00149  *                             Integers
00150  * ------------------------------------------------------------------------
00151  */
00152 
00153 //! Return true if \p x is an integer number, else false
00154 GRUEL_API bool pmt_is_integer(pmt_t x);
00155 
00156 //! Return the pmt value that represents the integer \p x.
00157 GRUEL_API pmt_t pmt_from_long(long x);
00158 
00159 /*!
00160  * \brief Convert pmt to long if possible.
00161  *
00162  * When \p x represents an exact integer that fits in a long,
00163  * return that integer.  Else raise an exception, either wrong_type
00164  * when x is not an exact integer, or out_of_range when it doesn't fit.
00165  */
00166 GRUEL_API long pmt_to_long(pmt_t x);
00167 
00168 /*
00169  * ------------------------------------------------------------------------
00170  *                             uint64_t
00171  * ------------------------------------------------------------------------
00172  */
00173 
00174 //! Return true if \p x is an uint64 number, else false
00175 GRUEL_API bool pmt_is_uint64(pmt_t x);
00176 
00177 //! Return the pmt value that represents the uint64 \p x.
00178 GRUEL_API pmt_t pmt_from_uint64(uint64_t x);
00179 
00180 /*!
00181  * \brief Convert pmt to uint64 if possible.
00182  *
00183  * When \p x represents an exact integer that fits in a uint64,
00184  * return that uint64.  Else raise an exception, either wrong_type
00185  * when x is not an exact uint64, or out_of_range when it doesn't fit.
00186  */
00187 GRUEL_API uint64_t pmt_to_uint64(pmt_t x);
00188 
00189 /*
00190  * ------------------------------------------------------------------------
00191  *                              Reals
00192  * ------------------------------------------------------------------------
00193  */
00194 
00195 /*
00196  * \brief Return true if \p obj is a real number, else false.
00197  */
00198 GRUEL_API bool pmt_is_real(pmt_t obj);
00199 
00200 //! Return the pmt value that represents double \p x.
00201 GRUEL_API pmt_t pmt_from_double(double x);
00202 
00203 /*!
00204  * \brief Convert pmt to double if possible.
00205  *
00206  * Returns the number closest to \p val that is representable
00207  * as a double.  The argument \p val must be a real or integer, otherwise
00208  * a wrong_type exception is raised.
00209  */
00210 GRUEL_API double pmt_to_double(pmt_t x);
00211 
00212 /*
00213  * ------------------------------------------------------------------------
00214  *                             Complex
00215  * ------------------------------------------------------------------------
00216  */
00217 
00218 /*!
00219  * \brief return true if \p obj is a complex number, false otherwise.
00220  */
00221 GRUEL_API bool pmt_is_complex(pmt_t obj);
00222 
00223 //! Return a complex number constructed of the given real and imaginary parts.
00224 GRUEL_API pmt_t pmt_make_rectangular(double re, double im);
00225 
00226 //! Return a complex number constructed of the given real and imaginary parts.
00227 GRUEL_API pmt_t pmt_from_complex(double re, double im);
00228 
00229 //! Return a complex number constructed of the given a complex number.
00230 GRUEL_API pmt_t pmt_from_complex(const std::complex<double> &z);
00231 
00232 /*!
00233  * If \p z is complex, real or integer, return the closest complex<double>.
00234  * Otherwise, raise the wrong_type exception.
00235  */
00236 GRUEL_API std::complex<double> pmt_to_complex(pmt_t z);
00237 
00238 /*
00239  * ------------------------------------------------------------------------
00240  *                              Pairs
00241  * ------------------------------------------------------------------------
00242  */
00243 
00244 extern GRUEL_API const pmt_t PMT_NIL;   //< the empty list
00245 
00246 //! Return true if \p x is the empty list, otherwise return false.
00247 GRUEL_API bool pmt_is_null(const pmt_t& x);
00248 
00249 //! Return true if \p obj is a pair, else false.
00250 GRUEL_API bool pmt_is_pair(const pmt_t& obj);
00251 
00252 //! Return a newly allocated pair whose car is \p x and whose cdr is \p y.
00253 GRUEL_API pmt_t pmt_cons(const pmt_t& x, const pmt_t& y);
00254 
00255 //! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type.
00256 GRUEL_API pmt_t pmt_car(const pmt_t& pair);
00257 
00258 //! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type.
00259 GRUEL_API pmt_t pmt_cdr(const pmt_t& pair);
00260 
00261 //! Stores \p value in the car field of \p pair.
00262 GRUEL_API void pmt_set_car(pmt_t pair, pmt_t value);
00263 
00264 //! Stores \p value in the cdr field of \p pair.
00265 GRUEL_API void pmt_set_cdr(pmt_t pair, pmt_t value);
00266 
00267 GRUEL_API pmt_t pmt_caar(pmt_t pair);
00268 GRUEL_API pmt_t pmt_cadr(pmt_t pair);
00269 GRUEL_API pmt_t pmt_cdar(pmt_t pair);
00270 GRUEL_API pmt_t pmt_cddr(pmt_t pair);
00271 GRUEL_API pmt_t pmt_caddr(pmt_t pair);
00272 GRUEL_API pmt_t pmt_cadddr(pmt_t pair);
00273 
00274 /*
00275  * ------------------------------------------------------------------------
00276  *                                Tuples
00277  *
00278  * Store a fixed number of objects.  Tuples are not modifiable, and thus
00279  * are excellent for use as messages.  Indexing is zero based.
00280  * Access time to an element is O(1).
00281  * ------------------------------------------------------------------------
00282  */
00283 
00284 //! Return true if \p x is a tuple, othewise false.
00285 GRUEL_API bool pmt_is_tuple(pmt_t x);
00286 
00287 GRUEL_API pmt_t pmt_make_tuple();
00288 GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0);
00289 GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1);
00290 GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2);
00291 GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3);
00292 GRUEL_API pmt_t pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4);
00293 GRUEL_API pmt_t pmt_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);
00294 GRUEL_API pmt_t pmt_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);
00295 GRUEL_API pmt_t pmt_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);
00296 GRUEL_API pmt_t pmt_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);
00297 GRUEL_API pmt_t pmt_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);
00298 
00299 /*!
00300  * If \p x is a vector or proper list, return a tuple containing the elements of x
00301  */
00302 GRUEL_API pmt_t pmt_to_tuple(const pmt_t &x);
00303 
00304 /*!
00305  * Return the contents of position \p k of \p tuple.
00306  * \p k must be a valid index of \p tuple.
00307  */
00308 GRUEL_API pmt_t pmt_tuple_ref(const pmt_t &tuple, size_t k);
00309 
00310 /*
00311  * ------------------------------------------------------------------------
00312  *                             Vectors
00313  *
00314  * These vectors can hold any kind of objects.  Indexing is zero based.
00315  * ------------------------------------------------------------------------
00316  */
00317 
00318 //! Return true if \p x is a vector, othewise false.
00319 GRUEL_API bool pmt_is_vector(pmt_t x);
00320 
00321 //! Make a vector of length \p k, with initial values set to \p fill
00322 GRUEL_API pmt_t pmt_make_vector(size_t k, pmt_t fill);
00323 
00324 /*!
00325  * Return the contents of position \p k of \p vector.
00326  * \p k must be a valid index of \p vector.
00327  */
00328 GRUEL_API pmt_t pmt_vector_ref(pmt_t vector, size_t k);
00329 
00330 //! Store \p obj in position \p k.
00331 GRUEL_API void pmt_vector_set(pmt_t vector, size_t k, pmt_t obj);
00332 
00333 //! Store \p fill in every position of \p vector
00334 GRUEL_API void pmt_vector_fill(pmt_t vector, pmt_t fill);
00335 
00336 /*
00337  * ------------------------------------------------------------------------
00338  *                    Binary Large Objects (BLOBs)
00339  *
00340  * Handy for passing around uninterpreted chunks of memory.
00341  * ------------------------------------------------------------------------
00342  */
00343 
00344 //! Return true if \p x is a blob, othewise false.
00345 GRUEL_API bool pmt_is_blob(pmt_t x);
00346 
00347 /*!
00348  * \brief Make a blob given a pointer and length in bytes
00349  *
00350  * \param buf is the pointer to data to use to create blob
00351  * \param len is the size of the data in bytes.
00352  *
00353  * The data is copied into the blob.
00354  */
00355 GRUEL_API pmt_t pmt_make_blob(const void *buf, size_t len);
00356 
00357 //! Return a pointer to the blob's data
00358 GRUEL_API const void *pmt_blob_data(pmt_t blob);
00359 
00360 //! Return the blob's length in bytes
00361 GRUEL_API size_t pmt_blob_length(pmt_t blob);
00362 
00363 /*!
00364  * <pre>
00365  * ------------------------------------------------------------------------
00366  *                     Uniform Numeric Vectors
00367  *
00368  * A uniform numeric vector is a vector whose elements are all of single
00369  * numeric type.  pmt offers uniform numeric vectors for signed and
00370  * unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers, two sizes of
00371  * floating point values, and complex floating-point numbers of these
00372  * two sizes.  Indexing is zero based.
00373  *
00374  * The names of the functions include these tags in their names:
00375  *
00376  *    u8  unsigned 8-bit integers
00377  *    s8  signed 8-bit integers
00378  *   u16  unsigned 16-bit integers
00379  *   s16  signed 16-bit integers
00380  *   u32  unsigned 32-bit integers
00381  *   s32  signed 32-bit integers
00382  *   u64  unsigned 64-bit integers
00383  *   s64  signed 64-bit integers
00384  *   f32  the C++ type float
00385  *   f64  the C++ type double
00386  *   c32  the C++ type complex<float>
00387  *   c64  the C++ type complex<double>
00388  * ------------------------------------------------------------------------
00389  * </pre>
00390  */
00391 
00392 //! true if \p x is any kind of uniform numeric vector
00393 GRUEL_API bool pmt_is_uniform_vector(pmt_t x);
00394 
00395 GRUEL_API bool pmt_is_u8vector(pmt_t x);
00396 GRUEL_API bool pmt_is_s8vector(pmt_t x);
00397 GRUEL_API bool pmt_is_u16vector(pmt_t x);
00398 GRUEL_API bool pmt_is_s16vector(pmt_t x);
00399 GRUEL_API bool pmt_is_u32vector(pmt_t x);
00400 GRUEL_API bool pmt_is_s32vector(pmt_t x);
00401 GRUEL_API bool pmt_is_u64vector(pmt_t x);
00402 GRUEL_API bool pmt_is_s64vector(pmt_t x);
00403 GRUEL_API bool pmt_is_f32vector(pmt_t x);
00404 GRUEL_API bool pmt_is_f64vector(pmt_t x);
00405 GRUEL_API bool pmt_is_c32vector(pmt_t x);
00406 GRUEL_API bool pmt_is_c64vector(pmt_t x);
00407 
00408 GRUEL_API pmt_t pmt_make_u8vector(size_t k, uint8_t fill);
00409 GRUEL_API pmt_t pmt_make_s8vector(size_t k, int8_t fill);
00410 GRUEL_API pmt_t pmt_make_u16vector(size_t k, uint16_t fill);
00411 GRUEL_API pmt_t pmt_make_s16vector(size_t k, int16_t fill);
00412 GRUEL_API pmt_t pmt_make_u32vector(size_t k, uint32_t fill);
00413 GRUEL_API pmt_t pmt_make_s32vector(size_t k, int32_t fill);
00414 GRUEL_API pmt_t pmt_make_u64vector(size_t k, uint64_t fill);
00415 GRUEL_API pmt_t pmt_make_s64vector(size_t k, int64_t fill);
00416 GRUEL_API pmt_t pmt_make_f32vector(size_t k, float fill);
00417 GRUEL_API pmt_t pmt_make_f64vector(size_t k, double fill);
00418 GRUEL_API pmt_t pmt_make_c32vector(size_t k, std::complex<float> fill);
00419 GRUEL_API pmt_t pmt_make_c64vector(size_t k, std::complex<double> fill);
00420 
00421 GRUEL_API pmt_t pmt_init_u8vector(size_t k, const uint8_t *data);
00422 GRUEL_API pmt_t pmt_init_u8vector(size_t k, const std::vector<uint8_t> &data);
00423 GRUEL_API pmt_t pmt_init_s8vector(size_t k, const int8_t *data);
00424 GRUEL_API pmt_t pmt_init_s8vector(size_t k, const std::vector<int8_t> &data);
00425 GRUEL_API pmt_t pmt_init_u16vector(size_t k, const uint16_t *data);
00426 GRUEL_API pmt_t pmt_init_u16vector(size_t k, const std::vector<uint16_t> &data);
00427 GRUEL_API pmt_t pmt_init_s16vector(size_t k, const int16_t *data);
00428 GRUEL_API pmt_t pmt_init_s16vector(size_t k, const std::vector<int16_t> &data);
00429 GRUEL_API pmt_t pmt_init_u32vector(size_t k, const uint32_t *data);
00430 GRUEL_API pmt_t pmt_init_u32vector(size_t k, const std::vector<uint32_t> &data);
00431 GRUEL_API pmt_t pmt_init_s32vector(size_t k, const int32_t *data);
00432 GRUEL_API pmt_t pmt_init_s32vector(size_t k, const std::vector<int32_t> &data);
00433 GRUEL_API pmt_t pmt_init_u64vector(size_t k, const uint64_t *data);
00434 GRUEL_API pmt_t pmt_init_u64vector(size_t k, const std::vector<uint64_t> &data);
00435 GRUEL_API pmt_t pmt_init_s64vector(size_t k, const int64_t *data);
00436 GRUEL_API pmt_t pmt_init_s64vector(size_t k, const std::vector<int64_t> &data);
00437 GRUEL_API pmt_t pmt_init_f32vector(size_t k, const float *data);
00438 GRUEL_API pmt_t pmt_init_f32vector(size_t k, const std::vector<float> &data);
00439 GRUEL_API pmt_t pmt_init_f64vector(size_t k, const double *data);
00440 GRUEL_API pmt_t pmt_init_f64vector(size_t k, const std::vector<double> &data);
00441 GRUEL_API pmt_t pmt_init_c32vector(size_t k, const std::complex<float> *data);
00442 GRUEL_API pmt_t pmt_init_c32vector(size_t k, const std::vector<std::complex<float> > &data);
00443 GRUEL_API pmt_t pmt_init_c64vector(size_t k, const std::complex<double> *data);
00444 GRUEL_API pmt_t pmt_init_c64vector(size_t k, const std::vector<std::complex<double> > &data);
00445 
00446 GRUEL_API uint8_t  pmt_u8vector_ref(pmt_t v, size_t k);
00447 GRUEL_API int8_t   pmt_s8vector_ref(pmt_t v, size_t k);
00448 GRUEL_API uint16_t pmt_u16vector_ref(pmt_t v, size_t k);
00449 GRUEL_API int16_t  pmt_s16vector_ref(pmt_t v, size_t k);
00450 GRUEL_API uint32_t pmt_u32vector_ref(pmt_t v, size_t k);
00451 GRUEL_API int32_t  pmt_s32vector_ref(pmt_t v, size_t k);
00452 GRUEL_API uint64_t pmt_u64vector_ref(pmt_t v, size_t k);
00453 GRUEL_API int64_t  pmt_s64vector_ref(pmt_t v, size_t k);
00454 GRUEL_API float    pmt_f32vector_ref(pmt_t v, size_t k);
00455 GRUEL_API double   pmt_f64vector_ref(pmt_t v, size_t k);
00456 GRUEL_API std::complex<float>  pmt_c32vector_ref(pmt_t v, size_t k);
00457 GRUEL_API std::complex<double> pmt_c64vector_ref(pmt_t v, size_t k);
00458 
00459 GRUEL_API void pmt_u8vector_set(pmt_t v, size_t k, uint8_t x);  //< v[k] = x
00460 GRUEL_API void pmt_s8vector_set(pmt_t v, size_t k, int8_t x);
00461 GRUEL_API void pmt_u16vector_set(pmt_t v, size_t k, uint16_t x);
00462 GRUEL_API void pmt_s16vector_set(pmt_t v, size_t k, int16_t x);
00463 GRUEL_API void pmt_u32vector_set(pmt_t v, size_t k, uint32_t x);
00464 GRUEL_API void pmt_s32vector_set(pmt_t v, size_t k, int32_t x);
00465 GRUEL_API void pmt_u64vector_set(pmt_t v, size_t k, uint64_t x);
00466 GRUEL_API void pmt_s64vector_set(pmt_t v, size_t k, int64_t x);
00467 GRUEL_API void pmt_f32vector_set(pmt_t v, size_t k, float x);
00468 GRUEL_API void pmt_f64vector_set(pmt_t v, size_t k, double x);
00469 GRUEL_API void pmt_c32vector_set(pmt_t v, size_t k, std::complex<float> x);
00470 GRUEL_API void pmt_c64vector_set(pmt_t v, size_t k, std::complex<double> x);
00471 
00472 // Return const pointers to the elements
00473 
00474 GRUEL_API const void *pmt_uniform_vector_elements(pmt_t v, size_t &len);  //< works with any; len is in bytes
00475 
00476 GRUEL_API const uint8_t  *pmt_u8vector_elements(pmt_t v, size_t &len);  //< len is in elements
00477 GRUEL_API const int8_t   *pmt_s8vector_elements(pmt_t v, size_t &len);  //< len is in elements
00478 GRUEL_API const uint16_t *pmt_u16vector_elements(pmt_t v, size_t &len); //< len is in elements
00479 GRUEL_API const int16_t  *pmt_s16vector_elements(pmt_t v, size_t &len); //< len is in elements
00480 GRUEL_API const uint32_t *pmt_u32vector_elements(pmt_t v, size_t &len); //< len is in elements
00481 GRUEL_API const int32_t  *pmt_s32vector_elements(pmt_t v, size_t &len); //< len is in elements
00482 GRUEL_API const uint64_t *pmt_u64vector_elements(pmt_t v, size_t &len); //< len is in elements
00483 GRUEL_API const int64_t  *pmt_s64vector_elements(pmt_t v, size_t &len); //< len is in elements
00484 GRUEL_API const float    *pmt_f32vector_elements(pmt_t v, size_t &len); //< len is in elements
00485 GRUEL_API const double   *pmt_f64vector_elements(pmt_t v, size_t &len); //< len is in elements
00486 GRUEL_API const std::complex<float>  *pmt_c32vector_elements(pmt_t v, size_t &len); //< len is in elements
00487 GRUEL_API const std::complex<double> *pmt_c64vector_elements(pmt_t v, size_t &len); //< len is in elements
00488 
00489 // len is in elements
00490 GRUEL_API const std::vector<uint8_t>  pmt_u8vector_elements(pmt_t v);
00491 GRUEL_API const std::vector<int8_t>   pmt_s8vector_elements(pmt_t v);
00492 GRUEL_API const std::vector<uint16_t> pmt_u16vector_elements(pmt_t v);
00493 GRUEL_API const std::vector<int16_t>  pmt_s16vector_elements(pmt_t v);
00494 GRUEL_API const std::vector<uint32_t> pmt_u32vector_elements(pmt_t v);
00495 GRUEL_API const std::vector<int32_t>  pmt_s32vector_elements(pmt_t v);
00496 GRUEL_API const std::vector<uint64_t> pmt_u64vector_elements(pmt_t v);
00497 GRUEL_API const std::vector<int64_t>  pmt_s64vector_elements(pmt_t v);
00498 GRUEL_API const std::vector<float>    pmt_f32vector_elements(pmt_t v);
00499 GRUEL_API const std::vector<double>   pmt_f64vector_elements(pmt_t v);
00500 GRUEL_API const std::vector<std::complex<float> > pmt_c32vector_elements(pmt_t v);
00501 GRUEL_API const std::vector<std::complex<double> > pmt_c64vector_elements(pmt_t v);
00502 
00503 // Return non-const pointers to the elements
00504 
00505 GRUEL_API void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len);  //< works with any; len is in bytes
00506 
00507 GRUEL_API uint8_t  *pmt_u8vector_writable_elements(pmt_t v, size_t &len);  //< len is in elements
00508 GRUEL_API int8_t   *pmt_s8vector_writable_elements(pmt_t v, size_t &len);  //< len is in elements
00509 GRUEL_API uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00510 GRUEL_API int16_t  *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00511 GRUEL_API uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00512 GRUEL_API int32_t  *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00513 GRUEL_API uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00514 GRUEL_API int64_t  *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00515 GRUEL_API float    *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00516 GRUEL_API double   *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00517 GRUEL_API std::complex<float>  *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00518 GRUEL_API std::complex<double> *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
00519 
00520 /*
00521  * ------------------------------------------------------------------------
00522  *         Dictionary (a.k.a associative array, hash, map)
00523  *
00524  * This is a functional data structure that is persistent.  Updating a
00525  * functional data structure does not destroy the existing version, but
00526  * rather creates a new version that coexists with the old.
00527  * ------------------------------------------------------------------------
00528  */
00529 
00530 //! Return true if \p obj is a dictionary
00531 GRUEL_API bool pmt_is_dict(const pmt_t &obj);
00532 
00533 //! Make an empty dictionary
00534 GRUEL_API pmt_t pmt_make_dict();
00535 
00536 //! Return a new dictionary with \p key associated with \p value.
00537 GRUEL_API pmt_t pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value);
00538 
00539 //! Return a new dictionary with \p key removed.
00540 GRUEL_API pmt_t pmt_dict_delete(const pmt_t &dict, const pmt_t &key);
00541 
00542 //! Return true if \p key exists in \p dict
00543 GRUEL_API bool  pmt_dict_has_key(const pmt_t &dict, const pmt_t &key);
00544 
00545 //! If \p key exists in \p dict, return associated value; otherwise return \p not_found.
00546 GRUEL_API pmt_t pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t &not_found);
00547 
00548 //! Return list of (key . value) pairs
00549 GRUEL_API pmt_t pmt_dict_items(pmt_t dict);
00550 
00551 //! Return list of keys
00552 GRUEL_API pmt_t pmt_dict_keys(pmt_t dict);
00553 
00554 //! Return list of values
00555 GRUEL_API pmt_t pmt_dict_values(pmt_t dict);
00556 
00557 /*
00558  * ------------------------------------------------------------------------
00559  *   Any (wraps boost::any -- can be used to wrap pretty much anything)
00560  *
00561  * Cannot be serialized or used across process boundaries.
00562  * See http://www.boost.org/doc/html/any.html
00563  * ------------------------------------------------------------------------
00564  */
00565 
00566 //! Return true if \p obj is an any
00567 GRUEL_API bool pmt_is_any(pmt_t obj);
00568 
00569 //! make an any
00570 GRUEL_API pmt_t pmt_make_any(const boost::any &any);
00571 
00572 //! Return underlying boost::any
00573 GRUEL_API boost::any pmt_any_ref(pmt_t obj);
00574 
00575 //! Store \p any in \p obj
00576 GRUEL_API void pmt_any_set(pmt_t obj, const boost::any &any);
00577 
00578 
00579 /*
00580  * ------------------------------------------------------------------------
00581  *    msg_accepter -- pmt representation of gruel::msg_accepter
00582  * ------------------------------------------------------------------------
00583  */
00584 //! Return true if \p obj is a msg_accepter
00585 GRUEL_API bool pmt_is_msg_accepter(const pmt_t &obj);
00586 
00587 //! make a msg_accepter
00588 GRUEL_API pmt_t pmt_make_msg_accepter(boost::shared_ptr<gruel::msg_accepter> ma);
00589 
00590 //! Return underlying msg_accepter
00591 GRUEL_API boost::shared_ptr<gruel::msg_accepter> pmt_msg_accepter_ref(const pmt_t &obj);
00592 
00593 /*
00594  * ------------------------------------------------------------------------
00595  *                        General functions
00596  * ------------------------------------------------------------------------
00597  */
00598 
00599 //! Return true if x and y are the same object; otherwise return false.
00600 GRUEL_API bool pmt_eq(const pmt_t& x, const pmt_t& y);
00601 
00602 /*!
00603  * \brief Return true if x and y should normally be regarded as the same object, else false.
00604  *
00605  * <pre>
00606  * eqv returns true if:
00607  *   x and y are the same object.
00608  *   x and y are both \#t or both \#f.
00609  *   x and y are both symbols and their names are the same.
00610  *   x and y are both numbers, and are numerically equal.
00611  *   x and y are both the empty list (nil).
00612  *   x and y are pairs or vectors that denote same location in store.
00613  * </pre>
00614  */
00615 GRUEL_API bool pmt_eqv(const pmt_t& x, const pmt_t& y);
00616 
00617 /*!
00618  * pmt_equal recursively compares the contents of pairs and vectors,
00619  * applying pmt_eqv on other objects such as numbers and symbols.
00620  * pmt_equal may fail to terminate if its arguments are circular data
00621  * structures.
00622  */
00623 GRUEL_API bool pmt_equal(const pmt_t& x, const pmt_t& y);
00624 
00625 
00626 //! Return the number of elements in v
00627 GRUEL_API size_t pmt_length(const pmt_t& v);
00628 
00629 /*!
00630  * \brief Find the first pair in \p alist whose car field is \p obj
00631  *  and return that pair.
00632  *
00633  * \p alist (for "association list") must be a list of pairs.  If no pair
00634  * in \p alist has \p obj as its car then \#f is returned.
00635  * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist.
00636  */
00637 GRUEL_API pmt_t pmt_assq(pmt_t obj, pmt_t alist);
00638 
00639 /*!
00640  * \brief Find the first pair in \p alist whose car field is \p obj
00641  *  and return that pair.
00642  *
00643  * \p alist (for "association list") must be a list of pairs.  If no pair
00644  * in \p alist has \p obj as its car then \#f is returned.
00645  * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist.
00646  */
00647 GRUEL_API pmt_t pmt_assv(pmt_t obj, pmt_t alist);
00648 
00649 /*!
00650  * \brief Find the first pair in \p alist whose car field is \p obj
00651  *  and return that pair.
00652  *
00653  * \p alist (for "association list") must be a list of pairs.  If no pair
00654  * in \p alist has \p obj as its car then \#f is returned.
00655  * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist.
00656  */
00657 GRUEL_API pmt_t pmt_assoc(pmt_t obj, pmt_t alist);
00658 
00659 /*!
00660  * \brief Apply \p proc element-wise to the elements of list and returns
00661  * a list of the results, in order.
00662  *
00663  * \p list must be a list.  The dynamic order in which \p proc is
00664  * applied to the elements of \p list is unspecified.
00665  */
00666 GRUEL_API pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list);
00667 
00668 /*!
00669  * \brief reverse \p list.
00670  *
00671  * \p list must be a proper list.
00672  */
00673 GRUEL_API pmt_t pmt_reverse(pmt_t list);
00674 
00675 /*!
00676  * \brief destructively reverse \p list.
00677  *
00678  * \p list must be a proper list.
00679  */
00680 GRUEL_API pmt_t pmt_reverse_x(pmt_t list);
00681 
00682 /*!
00683  * \brief (acons x y a) == (cons (cons x y) a)
00684  */
00685 inline static pmt_t
00686 pmt_acons(pmt_t x, pmt_t y, pmt_t a)
00687 {
00688   return pmt_cons(pmt_cons(x, y), a);
00689 }
00690 
00691 /*!
00692  * \brief locates \p nth element of \n list where the car is the 'zeroth' element.
00693  */
00694 GRUEL_API pmt_t pmt_nth(size_t n, pmt_t list);
00695 
00696 /*!
00697  * \brief returns the tail of \p list that would be obtained by calling
00698  * cdr \p n times in succession.
00699  */
00700 GRUEL_API pmt_t pmt_nthcdr(size_t n, pmt_t list);
00701 
00702 /*!
00703  * \brief Return the first sublist of \p list whose car is \p obj.
00704  * If \p obj does not occur in \p list, then \#f is returned.
00705  * pmt_memq use pmt_eq to compare \p obj with the elements of \p list.
00706  */
00707 GRUEL_API pmt_t pmt_memq(pmt_t obj, pmt_t list);
00708 
00709 /*!
00710  * \brief Return the first sublist of \p list whose car is \p obj.
00711  * If \p obj does not occur in \p list, then \#f is returned.
00712  * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list.
00713  */
00714 GRUEL_API pmt_t pmt_memv(pmt_t obj, pmt_t list);
00715 
00716 /*!
00717  * \brief Return the first sublist of \p list whose car is \p obj.
00718  * If \p obj does not occur in \p list, then \#f is returned.
00719  * pmt_member use pmt_equal to compare \p obj with the elements of \p list.
00720  */
00721 GRUEL_API pmt_t pmt_member(pmt_t obj, pmt_t list);
00722 
00723 /*!
00724  * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise.
00725  * Comparisons are done with pmt_eqv.
00726  */
00727 GRUEL_API bool pmt_subsetp(pmt_t list1, pmt_t list2);
00728 
00729 /*!
00730  * \brief Return a list of length 1 containing \p x1
00731  */
00732 GRUEL_API pmt_t pmt_list1(const pmt_t& x1);
00733 
00734 /*!
00735  * \brief Return a list of length 2 containing \p x1, \p x2
00736  */
00737 GRUEL_API pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2);
00738 
00739 /*!
00740  * \brief Return a list of length 3 containing \p x1, \p x2, \p x3
00741  */
00742 GRUEL_API pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3);
00743 
00744 /*!
00745  * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4
00746  */
00747 GRUEL_API pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4);
00748 
00749 /*!
00750  * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5
00751  */
00752 GRUEL_API pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5);
00753 
00754 /*!
00755  * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p
00756  * x5, \p x6
00757  */
00758 GRUEL_API pmt_t pmt_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);
00759 
00760 /*!
00761  * \brief Return \p list with \p item added to it.
00762  */
00763 GRUEL_API pmt_t pmt_list_add(pmt_t list, const pmt_t& item);
00764 
00765 /*!
00766  * \brief Return \p list with \p item removed from it.
00767  */
00768 GRUEL_API pmt_t pmt_list_rm(pmt_t list, const pmt_t& item);
00769 
00770 /*!
00771  * \brief Return bool of \p list contains \p item
00772  */
00773 GRUEL_API bool pmt_list_has(pmt_t list, const pmt_t& item);
00774 
00775 
00776 /*
00777  * ------------------------------------------------------------------------
00778  *                           read / write
00779  * ------------------------------------------------------------------------
00780  */
00781 extern GRUEL_API const pmt_t PMT_EOF;   //< The end of file object
00782 
00783 //! return true if obj is the EOF object, otherwise return false.
00784 GRUEL_API bool pmt_is_eof_object(pmt_t obj);
00785 
00786 /*!
00787  * read converts external representations of pmt objects into the
00788  * objects themselves.  Read returns the next object parsable from
00789  * the given input port, updating port to point to the first
00790  * character past the end of the external representation of the
00791  * object.
00792  *
00793  * If an end of file is encountered in the input before any
00794  * characters are found that can begin an object, then an end of file
00795  * object is returned.   The port remains open, and further attempts
00796  * to read will also return an end of file object.  If an end of file
00797  * is encountered after the beginning of an object's external
00798  * representation, but the external representation is incomplete and
00799  * therefore not parsable, an error is signaled.
00800  */
00801 GRUEL_API pmt_t pmt_read(std::istream &port);
00802 
00803 /*!
00804  * Write a written representation of \p obj to the given \p port.
00805  */
00806 GRUEL_API void pmt_write(pmt_t obj, std::ostream &port);
00807 
00808 /*!
00809  * Return a string representation of \p obj.
00810  * This is the same output as would be generated by pmt_write.
00811  */
00812 GRUEL_API std::string pmt_write_string(pmt_t obj);
00813 
00814 
00815 GRUEL_API std::ostream& operator<<(std::ostream &os, pmt_t obj);
00816 
00817 /*!
00818  * \brief Write pmt string representation to stdout.
00819  */
00820 GRUEL_API void pmt_print(pmt_t v);
00821 
00822 
00823 /*
00824  * ------------------------------------------------------------------------
00825  *                    portable byte stream representation
00826  * ------------------------------------------------------------------------
00827  */
00828 /*!
00829  * \brief Write portable byte-serial representation of \p obj to \p sink
00830  */
00831 GRUEL_API bool pmt_serialize(pmt_t obj, std::streambuf &sink);
00832 
00833 /*!
00834  * \brief Create obj from portable byte-serial representation
00835  */
00836 GRUEL_API pmt_t pmt_deserialize(std::streambuf &source);
00837 
00838 
00839 GRUEL_API void pmt_dump_sizeof();       // debugging
00840 
00841 /*!
00842  * \brief Provide a simple string generating interface to pmt's serialize function
00843  */
00844 GRUEL_API std::string pmt_serialize_str(pmt_t obj);
00845 
00846 /*!
00847  * \brief Provide a simple string generating interface to pmt's deserialize function
00848  */
00849 GRUEL_API pmt_t pmt_deserialize_str(std::string str);
00850 
00851 /*!
00852  * \brief Provide a comparator function object to allow pmt use in stl types
00853  */
00854 class pmt_comperator {
00855     public:
00856         bool operator()(pmt::pmt_t const& p1, pmt::pmt_t const& p2) const
00857             { return pmt::pmt_eqv(p1,p2)?false:p1.get()>p2.get(); }
00858     };
00859 
00860 } /* namespace pmt */
00861 
00862 #include <gruel/pmt_sugar.h>
00863 
00864 #endif /* INCLUDED_PMT_H */