aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-11-12 15:45:52 -0800
committerJosh Blum <josh@joshknows.com>2011-11-12 15:45:52 -0800
commitdd782308940e4b206e798eb2f0fa203b6e8c7f07 (patch)
tree9111a6128a4351ca7d9773e5ee4d057871ffd7b7 /host/include
parent74106084ed94668f11777f856e9b42e80b5d6599 (diff)
downloaduhd-dd782308940e4b206e798eb2f0fa203b6e8c7f07.tar.gz
uhd-dd782308940e4b206e798eb2f0fa203b6e8c7f07.tar.bz2
uhd-dd782308940e4b206e798eb2f0fa203b6e8c7f07.zip
convert: made conversion functions into classes so they can keep state
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/convert.hpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/host/include/uhd/convert.hpp b/host/include/uhd/convert.hpp
index c42edfdec..6cc729819 100644
--- a/host/include/uhd/convert.hpp
+++ b/host/include/uhd/convert.hpp
@@ -20,17 +20,35 @@
#include <uhd/config.hpp>
#include <uhd/types/ref_vector.hpp>
+#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/operators.hpp>
#include <string>
namespace uhd{ namespace convert{
- typedef uhd::ref_vector<void *> output_type;
- typedef uhd::ref_vector<const void *> input_type;
+ //! A conversion class that implements a conversion from inputs -> outputs.
+ class converter{
+ public:
+ typedef boost::shared_ptr<converter> sptr;
+ typedef uhd::ref_vector<void *> output_type;
+ typedef uhd::ref_vector<const void *> input_type;
- //! input vectors, output vectors, num samples, scale factor
- typedef boost::function<void(const input_type&, const output_type&, const size_t, const double)> function_type;
+ //! Set the scale factor (used in floating point conversions)
+ virtual void set_scalar(const double) = 0;
+
+ //! The public conversion method to convert inputs -> outputs
+ UHD_INLINE void conv(const input_type &in, const output_type &out, const size_t num){
+ if (num != 0) (*this)(in, out, num);
+ }
+
+ private:
+ //! Callable method: input vectors, output vectors, num samples
+ virtual void operator()(const input_type&, const output_type&, const size_t) = 0;
+ };
+
+ //! Conversion factory function typedef
+ typedef boost::function<converter::sptr(void)> function_type;
/*!
* Describe the priority of a converter function.
@@ -43,7 +61,8 @@ namespace uhd{ namespace convert{
PRIORITY_GENERAL = 0,
PRIORITY_LIBORC = 1,
PRIORITY_SIMD = 2,
- PRIORITY_CUSTOM = 3,
+ PRIORITY_TABLE = 3,
+ PRIORITY_CUSTOM = 4,
PRIORITY_EMPTY = -1,
};
@@ -62,19 +81,19 @@ namespace uhd{ namespace convert{
/*!
* Register a converter function.
* \param id identify the conversion
- * \param fcn a pointer to the converter
+ * \param fcn makes a new converter
* \param prio the function priority
*/
UHD_API void register_converter(
const id_type &id,
- function_type fcn,
- priority_type prio
+ const function_type &fcn,
+ const priority_type prio
);
/*!
- * Get a converter function.
+ * Get a converter factory function.
* \param id identify the conversion
- * \return the converter function
+ * \return the converter factory function
*/
UHD_API function_type get_converter(const id_type &id);