[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r3412 - gnuradio/branches/developers/eb/mb/pmt/src/lib
From: |
eb |
Subject: |
[Commit-gnuradio] r3412 - gnuradio/branches/developers/eb/mb/pmt/src/lib |
Date: |
Fri, 25 Aug 2006 13:56:24 -0600 (MDT) |
Author: eb
Date: 2006-08-25 13:56:23 -0600 (Fri, 25 Aug 2006)
New Revision: 3412
Added:
gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_io.cc
Modified:
gnuradio/branches/developers/eb/mb/pmt/src/lib/Makefile.am
gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc
gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h
Log:
implemented pmt_write and <<
Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/Makefile.am 2006-08-25
17:57:15 UTC (rev 3411)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/Makefile.am 2006-08-25
19:56:23 UTC (rev 3412)
@@ -59,6 +59,7 @@
# These are the source files that go into the pmt shared library
libpmt_la_SOURCES = \
pmt.cc \
+ pmt_io.cc \
pmt_unv.cc
# magic flags
Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc 2006-08-25
17:57:15 UTC (rev 3411)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc 2006-08-25
19:56:23 UTC (rev 3412)
@@ -51,6 +51,11 @@
{
}
+pmt_unimplemented::pmt_unimplemented(const char *msg, pmt_t obj)
+ : pmt_exception(msg, obj)
+{
+}
+
////////////////////////////////////////////////////////////////////////////
// Dynamic Casts
////////////////////////////////////////////////////////////////////////////
@@ -782,6 +787,7 @@
if (pmt_is_pair(list)){
list = pmt_cdr(list);
n--;
+ continue;
}
if (pmt_is_null(list))
return PMT_NIL;
Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h 2006-08-25
17:57:15 UTC (rev 3411)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h 2006-08-25
19:56:23 UTC (rev 3412)
@@ -72,6 +72,12 @@
pmt_out_of_range(const char *msg, pmt_t obj);
};
+class pmt_unimplemented : public pmt_exception
+{
+public:
+ pmt_unimplemented(const char *msg, pmt_t obj);
+};
+
/*
* ------------------------------------------------------------------------
* Booleans. Two constants, #t and #f.
@@ -551,6 +557,8 @@
*/
void pmt_write(pmt_t obj, std::ostream &port);
+std::ostream& operator<<(std::ostream &os, pmt_t obj);
+
/*
* ------------------------------------------------------------------------
* portable byte stream representation
Added: gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_io.cc
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_io.cc
(rev 0)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_io.cc 2006-08-25
19:56:23 UTC (rev 3412)
@@ -0,0 +1,121 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 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)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <vector>
+#include <pmt.h>
+#include "pmt_int.h"
+
+static void
+pmt_write_list_tail(pmt_t obj, std::ostream &port)
+{
+ pmt_write(pmt_car(obj), port); // write the car
+ obj = pmt_cdr(obj); // step to cdr
+
+ if (pmt_is_null(obj)) // ()
+ port << ")";
+
+ else if (pmt_is_pair(obj)){ // normal list
+ port << " ";
+ pmt_write_list_tail(obj, port);
+ }
+ else { // dotted pair
+ port << " . ";
+ pmt_write(obj, port);
+ port << ")";
+ }
+}
+
+void
+pmt_write(pmt_t obj, std::ostream &port)
+{
+ if (pmt_is_bool(obj)){
+ if (pmt_is_true(obj))
+ port << "#t";
+ else
+ port << "#f";
+ }
+ else if (pmt_is_symbol(obj)){
+ port << pmt_symbol_to_string(obj);
+ }
+ else if (pmt_is_number(obj)){
+ if (pmt_is_integer(obj))
+ port << pmt_to_long(obj);
+ else if (pmt_is_real(obj))
+ port << pmt_to_double(obj);
+ else if (pmt_is_complex(obj)){
+ std::complex<double> c = pmt_to_complex(obj);
+ port << c.real() << '+' << c.imag() << 'i';
+ }
+ else
+ goto error;
+ }
+ else if (pmt_is_null(obj)){
+ port << "()";
+ }
+ else if (pmt_is_pair(obj)){
+ port << "(";
+ pmt_write_list_tail(obj, port);
+ }
+ else if (pmt_is_dict(obj)){
+ port << "#<dict " << obj << ">";
+ }
+ else if (pmt_is_vector(obj)){
+ port << "#<vector " << obj << ">";
+ }
+ else if (pmt_is_uniform_vector(obj)){
+ port << "#<uniform-vector " << obj << ">";
+ }
+ else {
+ error:
+ port << "#<" << obj << ">";
+ }
+}
+
+std::ostream& operator<<(std::ostream &os, pmt_t obj)
+{
+ pmt_write(obj, os);
+ return os;
+}
+
+pmt_t
+pmt_read(std::istream &port)
+{
+ throw pmt_unimplemented("unimplemented: pmt_read", PMT_NIL);
+}
+
+void
+pmt_serialize(pmt_t obj, std::ostream &sink)
+{
+ throw pmt_unimplemented("unimplemented: pmt_serialize", obj);
+}
+
+/*!
+ * \brief Create obj from portable byte-serial representation
+ */
+pmt_t
+pmt_deserialize(std::istream &source)
+{
+ throw pmt_unimplemented("unimplemented: pmt_deserialize", PMT_NIL);
+}
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r3412 - gnuradio/branches/developers/eb/mb/pmt/src/lib,
eb <=