commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] pmt/src/lib pmt.h


From: Eric Blossom
Subject: [Commit-gnuradio] pmt/src/lib pmt.h
Date: Mon, 26 Jun 2006 19:37:39 +0000

CVSROOT:        /sources/gnuradio
Module name:    pmt
Changes by:     Eric Blossom <eb>       06/06/26 19:37:39

Modified files:
        src/lib        : pmt.h 

Log message:
        work-in-progress

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pmt/src/lib/pmt.h?cvsroot=gnuradio&r1=1.1.1.1&r2=1.2

Patches:
Index: pmt.h
===================================================================
RCS file: /sources/gnuradio/pmt/src/lib/pmt.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -b -r1.1.1.1 -r1.2
--- pmt.h       26 Jun 2006 04:50:48 -0000      1.1.1.1
+++ pmt.h       26 Jun 2006 19:37:39 -0000      1.2
@@ -23,6 +23,158 @@
 #ifndef INCLUDED_PMT_H
 #define INCLUDED_PMT_H
 
+#include <boost/shared_ptr.hpp>
+#include <complex>
+#include <string>
 
+/*!
+ * This file defines a polymorphic type and the operations on it.
+ *
+ * If draws heavily on the idea of scheme and lisp data types.
+ * The interface parallels that in Guile 1.8, with the notable
+ * exception that these objects are transparently reference counted.
+ */
+
+/*!
+ * \brief abstract base class of all pmt types
+ */
+class pmt_base {
+protected:
+  virtual ~pmt_base() = 0;
+};
+
+/*!
+ * \brief typedef for shared pointer (transparent reference counting).
+ * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
+ */
+typedef boost::shared_ptr<pmt_base> pmt_t;
+
+/*
+ * ------------------------------------------------------------------------
+ * Booleans.  Two constants #t and #f.
+ *
+ * In predicates, anything that is not #f is considered true.
+ * 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
+
+//! 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.
+bool pmt_is_false(pmt_t obj);
+
+//! Return true if obj is #t or #f, else return false.
+bool pmt_is_bool(pmt_t obj);
+
+//! 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, 
+// else throw 'wrong-type' exception.
+bool pmt_to_bool(pmt_t val);
+
+/*
+ * ------------------------------------------------------------------------
+ *                            Symbols
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if obj is a symbol, else false.
+bool pmt_is_symbol(pmt_t obj);
+
+//! Return the symbol whose name is \p s.
+pmt_t pmt_string_to_symbol(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);
+
+/*
+ * ------------------------------------------------------------------------
+ *           Numbers: we support integer, real and complex
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if obj is any kind of number, else false.
+bool pmt_is_number(pmt_t obj);
+
+/*
+ * ------------------------------------------------------------------------
+ *                            Integers
+ * ------------------------------------------------------------------------
+ */
+
+//! Return true if \p x is an integer number, else false
+bool pmt_is_integer(pmt_t x);
+
+/*!
+ * \brief Convert pmt to long if possible.
+ *
+ * When \p x represents an exact integer that fits in a long,
+ * return that integer.  Else raise an exception, either wrong_type
+ * when x is not an exact integer, or out_of_range when it doesn't fit.
+ */
+long pmt_to_long(pmt_t x);
+
+//! Return the pmt value that represents integer \p x.
+pmt_t pmt_from_long(long x);
+
+/*
+ * ------------------------------------------------------------------------
+ *                             Reals
+ * ------------------------------------------------------------------------
+ */
+
+/*
+ * \brief Return true if \p obj is a real number, else false.
+ *
+ * Note that the sets of integer and rational values form subsets of the set
+ * of real numbers, so the predicate will also be fulfilled if \p obj is
+ * an integer number or rational number. (Rationals are not implemented.)
+ */
+bool pmt_is_real(pmt_t obj);
+
+/*!
+ * \brief Convert pmt to double if possible.
+ *
+ * Returns the number closest to \p val that is representable
+ * as a double.  The argument \p val must be a real number, otherwise
+ * a wrong_type exception is raised.
+ */
+double pmt_to_double(pmt_t x);
+
+//! Return the pmt value that represents double \p x.
+pmt_t pmt_from_double(double x);
+
+/*
+ * ------------------------------------------------------------------------
+ *                            Complex
+ * ------------------------------------------------------------------------
+ */
+
+/*!
+ * \brief return true if \p obj is a complex number, false otherwise.
+ *
+ * Note that the sets of real, rational and integer values form subsets of
+ * the subsets of the set of complex numbers, i.e., the predicate will
+ * also be fulfilled if \p obj is a real, rational or integer number.
+ */
+bool pmt_is_complex(pmt_t obj);
+
+/*!
+ * If \p z is complex, return the closest complex<double>.
+ * Otherwise, raise the wrong_type exception.
+ */
+std::complex<double> pmt_to_complex(pmt_t z);
+
+/*!
+ * Return a complex number constructed of the given real and imaginary parts.
+ */
+pmt_t pmt_c_make_rectangular(double re, double im);
 
 #endif /* INCLUDED_PMT_H */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]