commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r3997 - gnuradio/branches/developers/eb/mb/pmt/src/lib


From: eb
Subject: [Commit-gnuradio] r3997 - gnuradio/branches/developers/eb/mb/pmt/src/lib
Date: Thu, 16 Nov 2006 22:53:44 -0700 (MST)

Author: eb
Date: 2006-11-16 22:53:44 -0700 (Thu, 16 Nov 2006)
New Revision: 3997

Modified:
   gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc
   gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h
   gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_int.h
   gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_io.cc
   gnuradio/branches/developers/eb/mb/pmt/src/lib/qa_pmt_prims.cc
   gnuradio/branches/developers/eb/mb/pmt/src/lib/qa_pmt_prims.h
Log:
pmt_exception now derives from std::logic_error.  Fixes in pmt_write.


Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc       2006-11-17 
00:20:30 UTC (rev 3996)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc       2006-11-17 
05:53:44 UTC (rev 3997)
@@ -36,23 +36,23 @@
 //                         Exceptions
 ////////////////////////////////////////////////////////////////////////////
 
-pmt_exception::pmt_exception(const char *msg, pmt_t obj)
-  : d_msg(msg), d_obj(obj)
+pmt_exception::pmt_exception(const std::string &msg, pmt_t obj)
+  : logic_error(msg + ": " + pmt_write_string(obj))
 {
 }
 
-pmt_wrong_type::pmt_wrong_type(const char *msg, pmt_t obj)
-  : pmt_exception(msg, obj)
+pmt_wrong_type::pmt_wrong_type(const std::string &msg, pmt_t obj)
+  : pmt_exception(msg + ": wrong_type ", obj)
 {
 }
 
-pmt_out_of_range::pmt_out_of_range(const char *msg, pmt_t obj)
-  : pmt_exception(msg, obj)
+pmt_out_of_range::pmt_out_of_range(const std::string &msg, pmt_t obj)
+  : pmt_exception(msg + ": out of range ", obj)
 {
 }
 
-pmt_notimplemented::pmt_notimplemented(const char *msg, pmt_t obj)
-  : pmt_exception(msg, obj)
+pmt_notimplemented::pmt_notimplemented(const std::string &msg, pmt_t obj)
+  : pmt_exception(msg + ": notimplemented ", obj)
 {
 }
 

Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h        2006-11-17 
00:20:30 UTC (rev 3996)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h        2006-11-17 
05:53:44 UTC (rev 3997)
@@ -28,6 +28,7 @@
 #include <string>
 #include <stdint.h>
 #include <iostream>
+#include <stdexcept>
 
 /*!
  * This file defines a polymorphic type and the operations on it.
@@ -49,33 +50,28 @@
 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 char *msg, pmt_t obj);
+  pmt_notimplemented(const std::string &msg, pmt_t obj);
 };
 
 /*
@@ -584,8 +580,16 @@
  */
 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

Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_int.h
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_int.h    2006-11-17 
00:20:30 UTC (rev 3996)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_int.h    2006-11-17 
05:53:44 UTC (rev 3997)
@@ -98,6 +98,7 @@
   pmt_integer(long value);
   //~pmt_integer(){}
 
+  bool is_number()  const { return true; }
   bool is_integer() const { return true; }
   long value() const { return d_value; }
 };
@@ -110,6 +111,7 @@
   pmt_real(double value);
   //~pmt_real(){}
 
+  bool is_number()  const { return true; }
   bool is_real() const { return true; }
   double value() const { return d_value; }
 };
@@ -122,6 +124,7 @@
   pmt_complex(std::complex<double> value);
   //~pmt_complex(){}
 
+  bool is_number()  const { return true; }
   bool is_complex() const { return true; }
   std::complex<double> value() const { return d_value; }
 };

Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_io.cc
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_io.cc    2006-11-17 
00:20:30 UTC (rev 3996)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt_io.cc    2006-11-17 
05:53:44 UTC (rev 3997)
@@ -25,6 +25,7 @@
 #include <vector>
 #include <pmt.h>
 #include "pmt_int.h"
+#include <sstream>
 
 static void
 pmt_write_list_tail(pmt_t obj, std::ostream &port)
@@ -78,17 +79,25 @@
     pmt_write_list_tail(obj, port);
   }
   else if (pmt_is_dict(obj)){
-    port << "#<dict " << obj << ">";
+    // FIXME
+    // port << "#<dict " << obj << ">";
+    port << "#<dict>";
   }
   else if (pmt_is_vector(obj)){
-    port << "#<vector " << obj << ">";
+    // FIXME
+    // port << "#<vector " << obj << ">";
+    port << "#<vector>";
   }
   else if (pmt_is_uniform_vector(obj)){
-    port << "#<uniform-vector " << obj << ">";
+    // FIXME
+    // port << "#<uniform-vector " << obj << ">";
+    port << "#<uniform-vector>";
   }
   else {
   error:
-    port << "#<" << obj << ">";
+    // FIXME
+    // port << "#<" << obj << ">";
+    port << "#<unknown>";
   }
 }
 
@@ -98,6 +107,14 @@
   return os;
 }
 
+std::string 
+pmt_write_string(pmt_t obj)
+{
+  std::ostringstream s;
+  s << obj;
+  return s.str();
+}
+
 pmt_t
 pmt_read(std::istream &port)
 {

Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/qa_pmt_prims.cc
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/qa_pmt_prims.cc      
2006-11-17 00:20:30 UTC (rev 3996)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/qa_pmt_prims.cc      
2006-11-17 05:53:44 UTC (rev 3997)
@@ -282,3 +282,14 @@
   CPPUNIT_ASSERT(pmt_equal(keys, pmt_dict_keys(dict)));
   CPPUNIT_ASSERT(pmt_equal(vals, pmt_dict_values(dict)));
 }
+
+void
+qa_pmt_prims::test_io()
+{
+  pmt_t k0 = pmt_string_to_symbol("k0");
+  pmt_t k1 = pmt_string_to_symbol("k1");
+  pmt_t k2 = pmt_string_to_symbol("k2");
+  pmt_t k3 = pmt_string_to_symbol("k3");
+
+  CPPUNIT_ASSERT_EQUAL(std::string("k0"), pmt_write_string(k0));
+}

Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/qa_pmt_prims.h
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/qa_pmt_prims.h       
2006-11-17 00:20:30 UTC (rev 3996)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/qa_pmt_prims.h       
2006-11-17 05:53:44 UTC (rev 3997)
@@ -38,6 +38,7 @@
   CPPUNIT_TEST(test_equivalence);
   CPPUNIT_TEST(test_misc);
   CPPUNIT_TEST(test_dict);
+  CPPUNIT_TEST(test_io);
   CPPUNIT_TEST_SUITE_END();
 
  private:
@@ -51,6 +52,7 @@
   void test_equivalence();
   void test_misc();
   void test_dict();
+  void test_io();
 };
 
 #endif /* INCLUDED_QA_PMT_PRIMS_H */





reply via email to

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