/* -*- 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,
#define INCLUDED_PMT_H
#include <boost/shared_ptr.hpp>
+#include <boost/any.hpp>
#include <complex>
#include <string>
#include <stdint.h>
-#include <iostream>
+#include <iosfwd>
+#include <stdexcept>
/*!
* This file defines a polymorphic type and the operations on it.
typedef boost::shared_ptr<pmt_base> 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);
};
/*
* 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);
*/
//! 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);
/*
* ------------------------------------------------------------------------
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);
//! 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
// 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<float> *pmt_c32vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements
-std::complex<double> *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<float> *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
+std::complex<double> *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements
/*
* ------------------------------------------------------------------------
//! 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
*/
//! 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.
* <pre>
* 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.
* </pre>
*/
-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,
* 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);
* 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);
* 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);
* \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.
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
*/
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
/*!
* \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 */