diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/gain_handler.hpp | 68 | ||||
-rw-r--r-- | host/include/uhd/utils.hpp | 7 |
2 files changed, 36 insertions, 39 deletions
diff --git a/host/include/uhd/gain_handler.hpp b/host/include/uhd/gain_handler.hpp index 06800315a..fade86f53 100644 --- a/host/include/uhd/gain_handler.hpp +++ b/host/include/uhd/gain_handler.hpp @@ -15,11 +15,9 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#include <boost/shared_ptr.hpp> #include <uhd/wax.hpp> -#include <uhd/props.hpp> +#include <boost/shared_ptr.hpp> #include <boost/function.hpp> -#include <boost/bind.hpp> #ifndef INCLUDED_UHD_GAIN_HANDLER_HPP #define INCLUDED_UHD_GAIN_HANDLER_HPP @@ -29,29 +27,41 @@ namespace uhd{ class gain_handler{ public: typedef boost::shared_ptr<gain_handler> sptr; + typedef boost::function<bool(const wax::obj &, const wax::obj &)> is_equal_t; - template <class T> gain_handler( - wax::obj *wax_obj_ptr, const T &gain_prop, - const T &gain_min_prop, const T &gain_max_prop, - const T &gain_step_prop, const T &gain_names_prop - ){ - _wax_obj_ptr = wax_obj_ptr; - _gain_prop = gain_prop; - _gain_min_prop = gain_min_prop; - _gain_max_prop = gain_max_prop; - _gain_step_prop = gain_step_prop; - _gain_names_prop = gain_names_prop; - _is_equal = boost::bind(&gain_handler::is_equal<T>, _1, _2); - } + /*! + * A set of properties for dealing with gains. + */ + struct gain_props_t{ + wax::obj gain_val_prop; + wax::obj gain_min_prop; + wax::obj gain_max_prop; + wax::obj gain_step_prop; + wax::obj gain_names_prop; + gain_props_t(void); //default constructor + }; - ~gain_handler(void); + /*! + * Make a new gain handler. + * The construction arguments are agnostic to the property type. + * It is up to the caller to provide an "is_equal" function that + * can tell weather two properties (in a wax obj) are equal. + * \param link a link to the wax obj with properties + * \param gain_props a struct of properties keys + * \param is_equal the function that tests for equal properties + */ + static sptr make( + const wax::obj &link, + const gain_props_t &gain_props, + is_equal_t is_equal + ); /*! * Intercept gets for overall gain, min, max, step. * Ensures that the gain name is valid. * \return true for handled, false to pass on */ - bool intercept_get(const wax::obj &key, wax::obj &val); + virtual bool intercept_get(const wax::obj &key, wax::obj &val) = 0; /*! * Intercept sets for overall gain. @@ -59,27 +69,10 @@ public: * Ensures that the new gain is within range. * \return true for handled, false to pass on */ - bool intercept_set(const wax::obj &key, const wax::obj &val); - -private: - - wax::obj *_wax_obj_ptr; - wax::obj _gain_prop; - wax::obj _gain_min_prop; - wax::obj _gain_max_prop; - wax::obj _gain_step_prop; - wax::obj _gain_names_prop; + virtual bool intercept_set(const wax::obj &key, const wax::obj &val) = 0; /*! - * Verify that the key is valid: - * If its a named prop for gain, ensure that name is valid. - * If the name if not valid, throw a std::invalid_argument. - * The name can only be valid if its in the list of gain names. - */ - void _check_key(const wax::obj &key); - - /* - * Private interface to test if two wax types are equal: + * Function template to test if two wax types are equal: * The constructor will bind an instance of this for a specific type. * This bound equals functions allows the intercept methods to be non-templated. */ @@ -91,7 +84,6 @@ private: return false; } } - boost::function<bool(const wax::obj &, const wax::obj &)> _is_equal; }; diff --git a/host/include/uhd/utils.hpp b/host/include/uhd/utils.hpp index e4cfd098b..5d6a18b3a 100644 --- a/host/include/uhd/utils.hpp +++ b/host/include/uhd/utils.hpp @@ -26,7 +26,7 @@ /*! * Defines a static code block that will be called before main() */ -#define STATIC_BLOCK(_name, _code) struct _name{_name(void){_code}} _name +#define STATIC_BLOCK(_x) struct _x{_x();}_x;_x::_x() /*! * Useful templated functions and classes that I like to pretend are part of stl @@ -55,6 +55,11 @@ namespace std{ return tmp; } + template<class T, class Iterable, class Function> + T reduce(Iterable iterable, Function fcn, T init = 0){ + return reduce(iterable.begin(), iterable.end(), fcn, init); + } + template<class T, class InputIterator> bool has(InputIterator first, InputIterator last, const T &elem){ return last != std::find(first, last, elem); |