From 488161a32831041e7f3fa96c9156e261b502ab4b Mon Sep 17 00:00:00 2001
From: Josh Blum
Date: Sat, 27 Oct 2012 22:31:26 -0700
Subject: authored a pretty complete pmc_to_pmt
---
PMC | 2 +-
lib/gr_block.cpp | 7 ++-
lib/pmx_helper.hpp | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 163 insertions(+), 4 deletions(-)
create mode 100644 lib/pmx_helper.hpp
diff --git a/PMC b/PMC
index cdff870..7d96189 160000
--- a/PMC
+++ b/PMC
@@ -1 +1 @@
-Subproject commit cdff8704f16ba4b4ce8532020d16cd831d259a88
+Subproject commit 7d96189a250a2ad14acd8a900ff4b114266a6648
diff --git a/lib/gr_block.cpp b/lib/gr_block.cpp
index f8c1d0d..c25177c 100644
--- a/lib/gr_block.cpp
+++ b/lib/gr_block.cpp
@@ -15,6 +15,7 @@
// along with this program. If not, see .
#include "element_impl.hpp"
+#include "pmx_helper.hpp"
#include
#include
@@ -155,9 +156,9 @@ static gr_tag_t Tag2gr_tag(const gnuradio::Tag &tag)
{
gr_tag_t t;
t.offset = tag.offset;
- t.key = tag.key? tag.key.cast() : pmt::pmt_t();
- t.value = tag.value? tag.value.cast() : pmt::pmt_t();
- t.srcid = tag.srcid? tag.srcid.cast() : pmt::pmt_t();
+ t.key = tag.key? tag.key.as() : pmt::pmt_t();
+ t.value = tag.value? tag.value.as() : pmt::pmt_t();
+ t.srcid = tag.srcid? tag.srcid.as() : pmt::pmt_t();
return t;
}
diff --git a/lib/pmx_helper.hpp b/lib/pmx_helper.hpp
new file mode 100644
index 0000000..bb009e2
--- /dev/null
+++ b/lib/pmx_helper.hpp
@@ -0,0 +1,158 @@
+//
+// Copyright 2012 Josh Blum
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+
+#ifndef INCLUDED_LIBGRAS_PMX_HELPER_HPP
+#define INCLUDED_LIBGRAS_PMX_HELPER_HPP
+
+#include
+#include
+#include
+#include
+
+namespace pmt
+{
+
+inline pmt_t pmc_to_pmt(const PMCC &p)
+{
+ if (not p) return pmt::pmt_t();
+
+ #define decl_pmc_to_pmt(type, conv) if (p.is()) return conv(p.as())
+
+ decl_pmc_to_pmt(bool, pmt_from_bool);
+ decl_pmc_to_pmt(std::string, pmt_string_to_symbol);
+
+ //numeric types
+ decl_pmc_to_pmt(int8_t, pmt_from_long);
+ decl_pmc_to_pmt(int16_t, pmt_from_long);
+ decl_pmc_to_pmt(int32_t, pmt_from_long);
+ decl_pmc_to_pmt(uint8_t, pmt_from_long);
+ decl_pmc_to_pmt(uint16_t, pmt_from_long);
+ decl_pmc_to_pmt(uint32_t, pmt_from_long);
+ decl_pmc_to_pmt(int64_t, pmt_from_uint64);
+ decl_pmc_to_pmt(uint64_t, pmt_from_uint64);
+ decl_pmc_to_pmt(float, pmt_from_double);
+ decl_pmc_to_pmt(double, pmt_from_double);
+ #define pmt_from_complex(x) pmt_make_rectangular((x).real(), (x).imag())
+ decl_pmc_to_pmt(std::complex, pmt_from_complex);
+ decl_pmc_to_pmt(std::complex, pmt_from_complex);
+
+ //pair container
+ if (p.is())
+ {
+ const PMCPair &pr = p.as();
+ return pmt_cons(pmc_to_pmt(pr.first), pmc_to_pmt(pr.second));
+ }
+
+ //fucking tuples
+/*
+for i in range(11):
+ args = list()
+ for j in range(i):
+ args.append('pmc_to_pmt(p.as >()[%d])'%(i, j))
+ print ' if (p.is >())'%i
+ print ' return pmt_make_tuple(%s);'%(', '.join(args),)
+*/
+ if (p.is >())
+ return pmt_make_tuple();
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]));
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]));
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]));
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]));
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]));
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5]));
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5]), pmc_to_pmt(p.as >()[6]));
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5]), pmc_to_pmt(p.as >()[6]), pmc_to_pmt(p.as >()[7]));
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5]), pmc_to_pmt(p.as >()[6]), pmc_to_pmt(p.as >()[7]), pmc_to_pmt(p.as >()[8]));
+ if (p.is >())
+ return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5]), pmc_to_pmt(p.as >()[6]), pmc_to_pmt(p.as >()[7]), pmc_to_pmt(p.as >()[8]), pmc_to_pmt(p.as >()[9]));
+
+ //vectors
+ if (p.is())
+ {
+ const PMCList &l = p.as();
+ pmt_t v = pmt_make_vector(l.size(), pmt_t());
+ for (size_t i = 0; i < l.size(); i++)
+ {
+ pmt_vector_set(v, i, pmc_to_pmt(l[i]));
+ }
+ return v;
+ }
+
+ //numeric arrays
+ #define decl_pmc_to_pmt_numeric_array(type, suffix) \
+ if (p.is >()) return pmt_init_ ## suffix ## vector(p.as >().size(), &p.as >()[0])
+ decl_pmc_to_pmt_numeric_array(uint8_t, u8);
+ decl_pmc_to_pmt_numeric_array(uint16_t, u16);
+ decl_pmc_to_pmt_numeric_array(uint32_t, u32);
+ decl_pmc_to_pmt_numeric_array(uint64_t, u64);
+ decl_pmc_to_pmt_numeric_array(int8_t, s8);
+ decl_pmc_to_pmt_numeric_array(int16_t, s16);
+ decl_pmc_to_pmt_numeric_array(int32_t, s32);
+ decl_pmc_to_pmt_numeric_array(int64_t, s64);
+ decl_pmc_to_pmt_numeric_array(float, f32);
+ decl_pmc_to_pmt_numeric_array(double, f64);
+ decl_pmc_to_pmt_numeric_array(std::complex, c32);
+ decl_pmc_to_pmt_numeric_array(std::complex, c64);
+
+ //dictionary
+ if (p.is())
+ {
+ const PMCDict &m = p.as();
+ pmt_t d = pmt_make_dict();
+ BOOST_FOREACH(const PMCPair &pr, m)
+ {
+ d = pmt_dict_add(d, pmc_to_pmt(pr.first), pmc_to_pmt(pr.second));
+ }
+ return d;
+ }
+
+ //set
+ if (p.is())
+ {
+ const PMCSet &s = p.as();
+ pmt_t l; //start w/ null - think this is ok
+ BOOST_FOREACH(const PMCC &elem, s)
+ {
+ l = pmt_list_add(l, pmc_to_pmt(elem));
+ }
+ return l;
+ }
+
+ //is it already a pmt?
+ if (p.is()) return p.as();
+
+ //backup plan... boost::any
+ return pmt_make_any(p);
+
+}
+
+inline PMC pmt_to_pmc(const pmt_t &p)
+{
+
+}
+
+}
+
+#endif /*INCLUDED_LIBGRAS_PMX_HELPER_HPP*/
--
cgit