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