X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=pmt%2Fsrc%2Flib%2Fpmt.h;h=24963fee71be791b93f44872f03802c7325f8334;hb=fe781ab6591ad46b6ebb7ce425fc225c49461e70;hp=0499a16c11349975e329a970a67907425fbd009b;hpb=86f5c92427b3f4bb30536d76cf63c3fca388fb2f;p=debian%2Fgnuradio diff --git a/pmt/src/lib/pmt.h b/pmt/src/lib/pmt.h index 0499a16c..24963fee 100644 --- a/pmt/src/lib/pmt.h +++ b/pmt/src/lib/pmt.h @@ -1,12 +1,12 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) + * the Free Software Foundation; either version 3, or (at your option) * any later version. * * GNU Radio is distributed in the hope that it will be useful, @@ -24,10 +24,12 @@ #define INCLUDED_PMT_H #include +#include #include #include #include -#include +#include +#include /*! * This file defines a polymorphic type and the operations on it. @@ -49,27 +51,28 @@ class pmt_base; typedef boost::shared_ptr pmt_t; -class pmt_exception +class pmt_exception : public std::logic_error { - const char *d_msg; - pmt_t d_obj; - public: - pmt_exception(const char *msg, pmt_t obj); - const char *msg() { return d_msg; } - pmt_t obj() { return d_obj; } + pmt_exception(const std::string &msg, pmt_t obj); }; class pmt_wrong_type : public pmt_exception { public: - pmt_wrong_type(const char *msg, pmt_t obj); + pmt_wrong_type(const std::string &msg, pmt_t obj); }; class pmt_out_of_range : public pmt_exception { public: - pmt_out_of_range(const char *msg, pmt_t obj); + pmt_out_of_range(const std::string &msg, pmt_t obj); +}; + +class pmt_notimplemented : public pmt_exception +{ +public: + pmt_notimplemented(const std::string &msg, pmt_t obj); }; /* @@ -80,22 +83,22 @@ public: * I.e., there is a single false value, #f. * ------------------------------------------------------------------------ */ -extern const pmt_t PMT_BOOL_T; //< #t : boolean true constant -extern const pmt_t PMT_BOOL_F; //< #f : boolean false constant +extern const pmt_t PMT_T; //< \#t : boolean true constant +extern const pmt_t PMT_F; //< \#f : boolean false constant -//! Return true if obj is #t or #f, else return false. +//! Return true if obj is \#t or \#f, else return false. bool pmt_is_bool(pmt_t obj); -//! Return false if obj is #f, else return true. +//! Return false if obj is \#f, else return true. bool pmt_is_true(pmt_t obj); -//! Return true if obj is #f, else return true. +//! Return true if obj is \#f, else return true. bool pmt_is_false(pmt_t obj); -//! Return #f is val is false, else return #t. +//! Return \#f is val is false, else return \#t. pmt_t pmt_from_bool(bool val); -//! Return true if val is PMT_BOOL_T, return false when val is PMT_BOOL_F, +//! Return true if val is PMT_T, return false when val is PMT_F, // else raise wrong_type exception. bool pmt_to_bool(pmt_t val); @@ -106,16 +109,20 @@ bool pmt_to_bool(pmt_t val); */ //! Return true if obj is a symbol, else false. -bool pmt_is_symbol(pmt_t obj); +bool pmt_is_symbol(const pmt_t& obj); //! Return the symbol whose name is \p s. pmt_t pmt_string_to_symbol(const std::string &s); +//! Alias for pmt_string_to_symbol +pmt_t pmt_intern(const std::string &s); + + /*! * If \p is a symbol, return the name of the symbol as a string. * Otherwise, raise the wrong_type exception. */ -const std::string pmt_symbol_to_string(pmt_t sym); +const std::string pmt_symbol_to_string(const pmt_t& sym); /* * ------------------------------------------------------------------------ @@ -199,19 +206,19 @@ std::complex pmt_to_complex(pmt_t z); extern const pmt_t PMT_NIL; //< the empty list //! Return true if \p x is the empty list, otherwise return false. -bool pmt_is_null(pmt_t x); +bool pmt_is_null(const pmt_t& x); //! Return true if \p obj is a pair, else false. -bool pmt_is_pair(pmt_t obj); +bool pmt_is_pair(const pmt_t& obj); //! Return a newly allocated pair whose car is \p x and whose cdr is \p y. -pmt_t pmt_cons(pmt_t x, pmt_t y); +pmt_t pmt_cons(const pmt_t& x, const pmt_t& y); //! If \p pair is a pair, return the car of the \p pair, otherwise raise wrong_type. -pmt_t pmt_car(pmt_t pair); +pmt_t pmt_car(const pmt_t& pair); //! If \p pair is a pair, return the cdr of the \p pair, otherwise raise wrong_type. -pmt_t pmt_cdr(pmt_t pair); +pmt_t pmt_cdr(const pmt_t& pair); //! Stores \p value in the car field of \p pair. void pmt_set_car(pmt_t pair, pmt_t value); @@ -219,6 +226,13 @@ void pmt_set_car(pmt_t pair, pmt_t value); //! Stores \p value in the cdr field of \p pair. void pmt_set_cdr(pmt_t pair, pmt_t value); +pmt_t pmt_caar(pmt_t pair); +pmt_t pmt_cadr(pmt_t pair); +pmt_t pmt_cdar(pmt_t pair); +pmt_t pmt_cddr(pmt_t pair); +pmt_t pmt_caddr(pmt_t pair); +pmt_t pmt_cadddr(pmt_t pair); + /* * ------------------------------------------------------------------------ * Vectors @@ -361,20 +375,20 @@ const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< le // Return non-const pointers to the elements -void *pmt_uniform_vector_writeable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes - -uint8_t *pmt_u8vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -int8_t *pmt_s8vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -uint16_t *pmt_u16vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -int16_t *pmt_s16vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -uint32_t *pmt_u32vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -int32_t *pmt_s32vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -uint64_t *pmt_u64vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -int64_t *pmt_s64vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -float *pmt_f32vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -double *pmt_f64vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c32vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c64vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +void *pmt_uniform_vector_writable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes + +uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements /* * ------------------------------------------------------------------------ @@ -406,6 +420,28 @@ pmt_t pmt_dict_keys(pmt_t dict); //! Return list of values pmt_t pmt_dict_values(pmt_t dict); +/* + * ------------------------------------------------------------------------ + * Any (wraps boost::any -- can be used to wrap pretty much anything) + * + * Cannot be serialized or used across process boundaries. + * See http://www.boost.org/doc/html/any.html + * ------------------------------------------------------------------------ + */ + +//! Return true if \p obj is an any +bool pmt_is_any(pmt_t obj); + +//! make an any +pmt_t pmt_make_any(const boost::any &any); + +//! Return underlying boost::any +boost::any pmt_any_ref(pmt_t obj); + +//! Store \p any in \p obj +void pmt_any_set(pmt_t obj, const boost::any &any); + + /* * ------------------------------------------------------------------------ * General functions @@ -413,7 +449,7 @@ pmt_t pmt_dict_values(pmt_t dict); */ //! Return true if x and y are the same object; otherwise return false. -bool pmt_eq(pmt_t x, pmt_t y); +bool pmt_eq(const pmt_t& x, const pmt_t& y); /*! * \brief Return true if x and y should normally be regarded as the same object, else false. @@ -421,14 +457,14 @@ bool pmt_eq(pmt_t x, pmt_t y); *
  * eqv returns true if:
  *   x and y are the same object.
- *   x and y are both #t or both #f.
+ *   x and y are both \#t or both \#f.
  *   x and y are both symbols and their names are the same.
  *   x and y are both numbers, and are numerically equal.
  *   x and y are both the empty list (nil).
  *   x and y are pairs or vectors that denote same location in store.
  * 
*/ -bool pmt_eqv(pmt_t x, pmt_t y); +bool pmt_eqv(const pmt_t& x, const pmt_t& y); /*! * pmt_equal recursively compares the contents of pairs and vectors, @@ -436,18 +472,18 @@ bool pmt_eqv(pmt_t x, pmt_t y); * pmt_equal may fail to terminate if its arguments are circular data * structures. */ -bool pmt_equal(pmt_t x, pmt_t y); +bool pmt_equal(const pmt_t& x, const pmt_t& y); //! Return the number of elements in v -size_t pmt_length(pmt_t v); +size_t pmt_length(const pmt_t& v); /*! * \brief Find the first pair in \p alist whose car field is \p obj * and return that pair. * * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then #f is returned. + * in \p alist has \p obj as its car then \#f is returned. * Uses pmt_eq to compare \p obj with car fields of the pairs in \p alist. */ pmt_t pmt_assq(pmt_t obj, pmt_t alist); @@ -457,7 +493,7 @@ pmt_t pmt_assq(pmt_t obj, pmt_t alist); * and return that pair. * * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then #f is returned. + * in \p alist has \p obj as its car then \#f is returned. * Uses pmt_eqv to compare \p obj with car fields of the pairs in \p alist. */ pmt_t pmt_assv(pmt_t obj, pmt_t alist); @@ -467,7 +503,7 @@ pmt_t pmt_assv(pmt_t obj, pmt_t alist); * and return that pair. * * \p alist (for "association list") must be a list of pairs. If no pair - * in \p alist has \p obj as its car then #f is returned. + * in \p alist has \p obj as its car then \#f is returned. * Uses pmt_equal to compare \p obj with car fields of the pairs in \p alist. */ pmt_t pmt_assoc(pmt_t obj, pmt_t alist); @@ -479,7 +515,7 @@ pmt_t pmt_assoc(pmt_t obj, pmt_t alist); * \p list must be a list. The dynamic order in which \p proc is * applied to the elements of \p list is unspecified. */ -pmt_t pmt_map(pmt_t proc(pmt_t), pmt_t list); +pmt_t pmt_map(pmt_t proc(const pmt_t&), pmt_t list); /*! * \brief reverse \p list. @@ -504,6 +540,81 @@ pmt_acons(pmt_t x, pmt_t y, pmt_t a) return pmt_cons(pmt_cons(x, y), a); } +/*! + * \brief locates \p nth element of \n list where the car is the 'zeroth' element. + */ +pmt_t pmt_nth(size_t n, pmt_t list); + +/*! + * \brief returns the tail of \p list that would be obtained by calling + * cdr \p n times in succession. + */ +pmt_t pmt_nthcdr(size_t n, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memq use pmt_eq to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memq(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_memv use pmt_eqv to compare \p obj with the elements of \p list. + */ +pmt_t pmt_memv(pmt_t obj, pmt_t list); + +/*! + * \brief Return the first sublist of \p list whose car is \p obj. + * If \p obj does not occur in \p list, then \#f is returned. + * pmt_member use pmt_equal to compare \p obj with the elements of \p list. + */ +pmt_t pmt_member(pmt_t obj, pmt_t list); + +/*! + * \brief Return true if every element of \p list1 appears in \p list2, and false otherwise. + * Comparisons are done with pmt_eqv. + */ +bool pmt_subsetp(pmt_t list1, pmt_t list2); + +/*! + * \brief Return a list of length 1 containing \p x1 + */ +pmt_t pmt_list1(const pmt_t& x1); + +/*! + * \brief Return a list of length 2 containing \p x1, \p x2 + */ +pmt_t pmt_list2(const pmt_t& x1, const pmt_t& x2); + +/*! + * \brief Return a list of length 3 containing \p x1, \p x2, \p x3 + */ +pmt_t pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3); + +/*! + * \brief Return a list of length 4 containing \p x1, \p x2, \p x3, \p x4 + */ +pmt_t pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4); + +/*! + * \brief Return a list of length 5 containing \p x1, \p x2, \p x3, \p x4, \p x5 + */ +pmt_t pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5); + +/*! + * \brief Return a list of length 6 containing \p x1, \p x2, \p x3, \p x4, \p + * x5, \p x6 + */ +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); + +/*! + * \brief Return \p list with \p item added to it. + */ +pmt_t pmt_list_add(pmt_t list, const pmt_t& item); + + /* * ------------------------------------------------------------------------ * read / write @@ -536,6 +647,16 @@ pmt_t pmt_read(std::istream &port); */ void pmt_write(pmt_t obj, std::ostream &port); +/*! + * Return a string representation of \p obj. + * This is the same output as would be generated by pmt_write. + */ +std::string pmt_write_string(pmt_t obj); + + +std::ostream& operator<<(std::ostream &os, pmt_t obj); + + /* * ------------------------------------------------------------------------ * portable byte stream representation @@ -544,11 +665,14 @@ void pmt_write(pmt_t obj, std::ostream &port); /*! * \brief Write portable byte-serial representation of \p obj to \p sink */ -void pmt_serialize(pmt_t obj, std::ostream &sink); +bool pmt_serialize(pmt_t obj, std::streambuf &sink); /*! * \brief Create obj from portable byte-serial representation */ -pmt_t pmt_deserialize(std::istream &source); +pmt_t pmt_deserialize(std::streambuf &source); + + +void pmt_dump_sizeof(); // debugging #endif /* INCLUDED_PMT_H */