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