commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 03/07: pmt: adding pmt.uniform_vector_items


From: git
Subject: [Commit-gnuradio] [gnuradio] 03/07: pmt: adding pmt.uniform_vector_itemsize(pmt_t vector), returns the size per item in bytes within a uniform vector for any kind of uniform vector
Date: Fri, 16 May 2014 23:49:30 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 496c74a460bb7fe472f5ee4b8861b65a0f488331
Author: Tim O'Shea <address@hidden>
Date:   Wed May 14 19:44:34 2014 -0400

    pmt: adding pmt.uniform_vector_itemsize(pmt_t vector), returns the size per 
item in bytes within a uniform vector for any kind of uniform vector
---
 gnuradio-runtime/include/pmt/pmt.h        |  3 +++
 gnuradio-runtime/lib/pmt/pmt.cc           | 10 ++++++++++
 gnuradio-runtime/lib/pmt/pmt_int.h        |  1 +
 gnuradio-runtime/lib/pmt/unv_template.h.t |  1 +
 gnuradio-runtime/python/pmt/qa_pmt.py     |  2 ++
 gnuradio-runtime/swig/pmt_swig.i          |  1 +
 6 files changed, 18 insertions(+)

diff --git a/gnuradio-runtime/include/pmt/pmt.h 
b/gnuradio-runtime/include/pmt/pmt.h
index 3cae2f2..5929975 100644
--- a/gnuradio-runtime/include/pmt/pmt.h
+++ b/gnuradio-runtime/include/pmt/pmt.h
@@ -411,6 +411,9 @@ PMT_API bool is_f64vector(pmt_t x);
 PMT_API bool is_c32vector(pmt_t x);
 PMT_API bool is_c64vector(pmt_t x);
 
+//! item size in bytes if \p x is any kind of uniform numeric vector
+PMT_API size_t uniform_vector_itemsize(pmt_t x);
+
 PMT_API pmt_t make_u8vector(size_t k, uint8_t fill);
 PMT_API pmt_t make_s8vector(size_t k, int8_t fill);
 PMT_API pmt_t make_u16vector(size_t k, uint16_t fill);
diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index 7760c02..8315100 100644
--- a/gnuradio-runtime/lib/pmt/pmt.cc
+++ b/gnuradio-runtime/lib/pmt/pmt.cc
@@ -760,6 +760,14 @@ is_uniform_vector(pmt_t x)
   return x->is_uniform_vector();
 }
 
+size_t
+uniform_vector_itemsize(pmt_t vector)
+{
+  if (!vector->is_uniform_vector())
+    throw wrong_type("pmt_uniform_vector_itemsize", vector);
+  return _uniform_vector(vector)->itemsize();
+}
+
 const void *
 uniform_vector_elements(pmt_t vector, size_t &len)
 {
@@ -776,6 +784,8 @@ uniform_vector_writable_elements(pmt_t vector, size_t &len)
   return _uniform_vector(vector)->uniform_writable_elements(len);
 }
 
+
+
 ////////////////////////////////////////////////////////////////////////////
 //                            Dictionaries
 ////////////////////////////////////////////////////////////////////////////
diff --git a/gnuradio-runtime/lib/pmt/pmt_int.h 
b/gnuradio-runtime/lib/pmt/pmt_int.h
index aceb7b7..ca90c5a 100644
--- a/gnuradio-runtime/lib/pmt/pmt_int.h
+++ b/gnuradio-runtime/lib/pmt/pmt_int.h
@@ -238,6 +238,7 @@ public:
   virtual const void *uniform_elements(size_t &len) = 0;
   virtual void *uniform_writable_elements(size_t &len) = 0;
   virtual size_t length() const = 0;
+  virtual size_t itemsize() const = 0;
 };
 
 #include "pmt_unv_int.h"
diff --git a/gnuradio-runtime/lib/pmt/unv_template.h.t 
b/gnuradio-runtime/lib/pmt/unv_template.h.t
index 83ba0be..93ca684 100644
--- a/gnuradio-runtime/lib/pmt/unv_template.h.t
+++ b/gnuradio-runtime/lib/pmt/unv_template.h.t
@@ -14,6 +14,7 @@ public:
 
   bool address@hidden@vector() const { return true; }
   size_t length() const { return d_v.size(); }
+  size_t itemsize() const { return sizeof(@TYPE@); }
   @TYPE@ ref(size_t k) const;
   void set(size_t k, @TYPE@ x);
   const @TYPE@ *elements(size_t &len);
diff --git a/gnuradio-runtime/python/pmt/qa_pmt.py 
b/gnuradio-runtime/python/pmt/qa_pmt.py
index 2a72fa6..5c1af2c 100755
--- a/gnuradio-runtime/python/pmt/qa_pmt.py
+++ b/gnuradio-runtime/python/pmt/qa_pmt.py
@@ -43,6 +43,7 @@ class test_pmt(unittest.TestCase):
         s = pmt.serialize_str(v)
         d = pmt.deserialize_str(s)
         self.assertTrue(pmt.equal(v, d))
+        self.assertEqual(pmt.uniform_vector_itemsize(v), 4)
 
     def test04(self):
         v = pmt.init_f64vector(3, [11, -22, 33])
@@ -91,6 +92,7 @@ class test_pmt(unittest.TestCase):
         s = pmt.serialize_str(v)
         d = pmt.deserialize_str(s)
         self.assertTrue(pmt.equal(v, d))
+        self.assertEqual(pmt.uniform_vector_itemsize(v), 8)
 
     def test12(self):
         v = pmt.init_c64vector(3, [11 + -101j, -22 + 202j, 33 + -303j])
diff --git a/gnuradio-runtime/swig/pmt_swig.i b/gnuradio-runtime/swig/pmt_swig.i
index 2c0444f..5ea612b 100644
--- a/gnuradio-runtime/swig/pmt_swig.i
+++ b/gnuradio-runtime/swig/pmt_swig.i
@@ -170,6 +170,7 @@ namespace pmt{
   bool is_f64vector(pmt_t x);
   bool is_c32vector(pmt_t x);
   bool is_c64vector(pmt_t x);
+  size_t uniform_vector_itemsize(pmt_t x);
   pmt_t make_u8vector(size_t k, uint8_t fill);
   pmt_t make_s8vector(size_t k, int8_t fill);
   pmt_t make_u16vector(size_t k, uint16_t fill);



reply via email to

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