aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/convert/convert_impl.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-10-03 16:46:00 -0700
committerJosh Blum <josh@joshknows.com>2011-11-03 20:37:10 -0700
commit75b7967fac3ec72fb35c542da23491215d53a8bb (patch)
treefa588c1e71bb7cbc751d2f5738bb37aad5cfec45 /host/lib/convert/convert_impl.cpp
parentc480414fea7948dedd9428f545dfff90f4c8f2c8 (diff)
downloaduhd-75b7967fac3ec72fb35c542da23491215d53a8bb.tar.gz
uhd-75b7967fac3ec72fb35c542da23491215d53a8bb.tar.bz2
uhd-75b7967fac3ec72fb35c542da23491215d53a8bb.zip
convert: reworked convert to use new identification standard
Diffstat (limited to 'host/lib/convert/convert_impl.cpp')
-rw-r--r--host/lib/convert/convert_impl.cpp117
1 files changed, 71 insertions, 46 deletions
diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp
index 9b2cdcdc9..2ead2f5b4 100644
--- a/host/lib/convert/convert_impl.cpp
+++ b/host/lib/convert/convert_impl.cpp
@@ -18,11 +18,40 @@
#include <uhd/convert.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
+#include <uhd/types/dict.hpp>
#include <uhd/exception.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/format.hpp>
+#include <complex>
using namespace uhd;
-#include "convert_pred.hpp"
+bool convert::operator==(const convert::id_type &lhs, const convert::id_type &rhs){
+ return
+ (lhs.input_markup == rhs.input_markup) and
+ (lhs.num_inputs == rhs.num_inputs) and
+ (lhs.output_markup == rhs.output_markup) and
+ (lhs.num_outputs == rhs.num_outputs) and
+ (lhs.args == rhs.args)
+ ;
+}
+
+std::string convert::id_type::to_pp_string(void) const{
+ return str(boost::format(
+ "conversion ID\n"
+ " Input markup: %s\n"
+ " Num inputs: %d\n"
+ " Output markup: %s\n"
+ " Num outputs: %d\n"
+ " Optional args: %s\n"
+ )
+ % this->input_markup
+ % this->num_inputs
+ % this->output_markup
+ % this->num_outputs
+ % this->args
+ );
+}
/***********************************************************************
* Define types for the function tables
@@ -30,56 +59,34 @@ using namespace uhd;
struct fcn_table_entry_type{
convert::priority_type prio;
convert::function_type fcn;
- fcn_table_entry_type(void)
- : prio(convert::PRIORITY_EMPTY), fcn(NULL){
- /* NOP */
- }
};
-typedef std::vector<fcn_table_entry_type> fcn_table_type;
/***********************************************************************
* Setup the table registry
**********************************************************************/
-UHD_SINGLETON_FCN(fcn_table_type, get_cpu_to_otw_table);
-UHD_SINGLETON_FCN(fcn_table_type, get_otw_to_cpu_table);
-
-fcn_table_type &get_table(dir_type dir){
- switch(dir){
- case DIR_OTW_TO_CPU: return get_otw_to_cpu_table();
- case DIR_CPU_TO_OTW: return get_cpu_to_otw_table();
- }
- UHD_THROW_INVALID_CODE_PATH();
-}
+typedef uhd::dict<convert::id_type, fcn_table_entry_type> fcn_table_type;
+UHD_SINGLETON_FCN(fcn_table_type, get_table);
/***********************************************************************
* The registry functions
**********************************************************************/
void uhd::convert::register_converter(
- const std::string &markup,
+ const id_type &id,
function_type fcn,
priority_type prio
){
- //extract the predicate and direction from the markup
- dir_type dir;
- pred_type pred = make_pred(markup, dir);
-
//get a reference to the function table
- fcn_table_type &table = get_table(dir);
-
- //resize the table so that its at least pred+1
- if (table.size() <= pred) table.resize(pred+1);
+ fcn_table_type &table = get_table();
//register the function if higher priority
- if (table[pred].prio < prio){
- table[pred].fcn = fcn;
- table[pred].prio = prio;
+ if (not table.has_key(id) or table[id].prio < prio){
+ table[id].fcn = fcn;
+ table[id].prio = prio;
}
//----------------------------------------------------------------//
- UHD_LOGV(always) << "register_converter: " << markup << std::endl
+ UHD_LOGV(always) << "register_converter: " << id.to_pp_string() << std::endl
<< " prio: " << prio << std::endl
- << " pred: " << pred << std::endl
- << " dir: " << dir << std::endl
<< std::endl
;
//----------------------------------------------------------------//
@@ -88,22 +95,40 @@ void uhd::convert::register_converter(
/***********************************************************************
* The converter functions
**********************************************************************/
-const convert::function_type &convert::get_converter_cpu_to_otw(
- const io_type_t &io_type,
- const otw_type_t &otw_type,
- size_t num_input_buffs,
- size_t num_output_buffs
-){
- pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs);
- return get_cpu_to_otw_table().at(pred).fcn;
+convert::function_type convert::get_converter(const id_type &id){
+ if (get_table().has_key(id)) return get_table()[id].fcn;
+ throw uhd::key_error("Cannot find a conversion routine for " + id.to_pp_string());
}
-const convert::function_type &convert::get_converter_otw_to_cpu(
- const io_type_t &io_type,
- const otw_type_t &otw_type,
- size_t num_input_buffs,
- size_t num_output_buffs
+/***********************************************************************
+ * Mappings for item markup to byte size for all items we can
+ **********************************************************************/
+typedef uhd::dict<std::string, size_t> item_size_type;
+UHD_SINGLETON_FCN(item_size_type, get_item_size_table);
+
+void register_bytes_per_item(
+ const std::string &markup, const size_t size
){
- pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs);
- return get_otw_to_cpu_table().at(pred).fcn;
+ get_item_size_table()[markup] = size;
+}
+
+size_t convert::get_bytes_per_item(const std::string &markup){
+ if (get_item_size_table().has_key(markup)) return get_item_size_table()[markup];
+ throw uhd::key_error("Cannot find an item size " + markup);
+}
+
+UHD_STATIC_BLOCK(convert_register_item_sizes){
+ //register standard complex types
+ get_item_size_table()["fc64"] = sizeof(std::complex<double>);
+ get_item_size_table()["fc32"] = sizeof(std::complex<float>);
+ get_item_size_table()["sc32"] = sizeof(std::complex<boost::int32_t>);
+ get_item_size_table()["sc16"] = sizeof(std::complex<boost::int16_t>);
+ get_item_size_table()["sc8"] = sizeof(std::complex<boost::int8_t>);
+
+ //register standard real types
+ get_item_size_table()["f64"] = sizeof(double);
+ get_item_size_table()["f32"] = sizeof(float);
+ get_item_size_table()["s32"] = sizeof(boost::int32_t);
+ get_item_size_table()["s16"] = sizeof(boost::int16_t);
+ get_item_size_table()["s8"] = sizeof(boost::int8_t);
}