summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/uhd/dict.hpp18
-rw-r--r--include/uhd/usrp/dboard/manager.hpp6
-rw-r--r--include/uhd/usrp/mboard/test.hpp4
-rw-r--r--include/uhd/usrp/mboard/usrp2.hpp4
-rw-r--r--include/uhd/usrp/usrp.hpp4
-rw-r--r--include/uhd/utils.hpp94
-rw-r--r--lib/usrp/dboard/id.cpp12
-rw-r--r--lib/usrp/dboard/manager.cpp15
-rw-r--r--lib/usrp/mboard/test.cpp9
-rw-r--r--lib/usrp/usrp.cpp5
-rw-r--r--test/gain_handler_test.cpp12
11 files changed, 84 insertions, 99 deletions
diff --git a/include/uhd/dict.hpp b/include/uhd/dict.hpp
index 3abc4273c..1ed28551a 100644
--- a/include/uhd/dict.hpp
+++ b/include/uhd/dict.hpp
@@ -20,8 +20,8 @@
#include <map>
#include <vector>
-#include <boost/foreach.hpp>
#include <stdexcept>
+#include <boost/foreach.hpp>
namespace uhd{
@@ -31,6 +31,9 @@ namespace uhd{
*/
template <class Key, class Val> class dict{
public:
+ typedef std::map<Key, Val> map_t;
+ typedef std::pair<Key, Val> pair_t;
+
/*!
* Create a new empty dictionary.
*/
@@ -42,7 +45,7 @@ namespace uhd{
* Create a dictionary from a map.
* \param map a map with key value pairs
*/
- dict(const std::map<Key, Val> &map){
+ dict(const map_t &map){
_map = map;
}
@@ -59,8 +62,7 @@ namespace uhd{
*/
std::vector<Key> get_keys(void) const{
std::vector<Key> keys;
- std::pair<Key, Val> p;
- BOOST_FOREACH(p, _map){
+ BOOST_FOREACH(pair_t p, _map){
keys.push_back(p.first);
}
return keys;
@@ -72,8 +74,7 @@ namespace uhd{
*/
std::vector<Val> get_vals(void) const{
std::vector<Val> vals;
- std::pair<Key, Val> p;
- BOOST_FOREACH(p, _map){
+ BOOST_FOREACH(pair_t p, _map){
vals.push_back(p.second);
}
return vals;
@@ -85,8 +86,7 @@ namespace uhd{
* \return true if found
*/
bool has_key(const Key &key) const{
- std::pair<Key, Val> p;
- BOOST_FOREACH(p, _map){
+ BOOST_FOREACH(pair_t p, _map){
if (p.first == key) return true;
}
return false;
@@ -132,7 +132,7 @@ namespace uhd{
}
private:
- std::map<Key, Val> _map; //private container
+ map_t _map; //private container
};
} //namespace uhd
diff --git a/include/uhd/usrp/dboard/manager.hpp b/include/uhd/usrp/dboard/manager.hpp
index 5934efedc..e53ba8e52 100644
--- a/include/uhd/usrp/dboard/manager.hpp
+++ b/include/uhd/usrp/dboard/manager.hpp
@@ -18,7 +18,7 @@
#ifndef INCLUDED_UHD_USRP_DBOARD_MANAGER_HPP
#define INCLUDED_UHD_USRP_DBOARD_MANAGER_HPP
-#include <map>
+#include <uhd/dict.hpp>
#include <uhd/wax.hpp>
#include <uhd/props.hpp>
#include <boost/utility.hpp>
@@ -73,8 +73,8 @@ private:
//list of rx and tx dboards in this manager
//each dboard here is actually a subdevice proxy
//the subdevice proxy is internal to the cpp file
- std::map<std::string, wax::obj> _rx_dboards;
- std::map<std::string, wax::obj> _tx_dboards;
+ uhd::dict<std::string, wax::obj> _rx_dboards;
+ uhd::dict<std::string, wax::obj> _tx_dboards;
};
}}} //namespace
diff --git a/include/uhd/usrp/mboard/test.hpp b/include/uhd/usrp/mboard/test.hpp
index be435930b..04d0ff4c4 100644
--- a/include/uhd/usrp/mboard/test.hpp
+++ b/include/uhd/usrp/mboard/test.hpp
@@ -21,7 +21,7 @@
#include <uhd/usrp/mboard/base.hpp>
#include <uhd/device_addr.hpp>
#include <uhd/usrp/dboard/manager.hpp>
-#include <map>
+#include <uhd/dict.hpp>
namespace uhd{ namespace usrp{ namespace mboard{
@@ -38,7 +38,7 @@ private:
void get(const wax::obj &, wax::obj &);
void set(const wax::obj &, const wax::obj &);
- std::map<std::string, dboard::manager::sptr> _dboard_managers;
+ uhd::dict<std::string, dboard::manager::sptr> _dboard_managers;
};
}}} //namespace
diff --git a/include/uhd/usrp/mboard/usrp2.hpp b/include/uhd/usrp/mboard/usrp2.hpp
index 4950f4cd1..91f729f6f 100644
--- a/include/uhd/usrp/mboard/usrp2.hpp
+++ b/include/uhd/usrp/mboard/usrp2.hpp
@@ -22,7 +22,7 @@
#include <uhd/device_addr.hpp>
#include <uhd/usrp/dboard/manager.hpp>
#include <uhd/transport/udp.hpp>
-#include <map>
+#include <uhd/dict.hpp>
namespace uhd{ namespace usrp{ namespace mboard{
@@ -46,7 +46,7 @@ private:
void get(const wax::obj &, wax::obj &);
void set(const wax::obj &, const wax::obj &);
- std::map<std::string, dboard::manager::sptr> _dboard_managers;
+ uhd::dict<std::string, dboard::manager::sptr> _dboard_managers;
uhd::transport::udp::sptr _udp_ctrl_transport;
uhd::transport::udp::sptr _udp_data_transport;
};
diff --git a/include/uhd/usrp/usrp.hpp b/include/uhd/usrp/usrp.hpp
index 0dca36f62..98c357b77 100644
--- a/include/uhd/usrp/usrp.hpp
+++ b/include/uhd/usrp/usrp.hpp
@@ -17,7 +17,7 @@
#include <uhd/device.hpp>
#include <uhd/usrp/mboard/base.hpp>
-#include <map>
+#include <uhd/dict.hpp>
#ifndef INCLUDED_UHD_USRP_USRP_HPP
#define INCLUDED_UHD_USRP_USRP_HPP
@@ -43,7 +43,7 @@ private:
void get(const wax::obj &, wax::obj &);
void set(const wax::obj &, const wax::obj &);
- std::map<std::string, mboard::base::sptr> _mboards;
+ uhd::dict<std::string, mboard::base::sptr> _mboards;
boost::function<void(const std::vector<boost::asio::const_buffer> &)> _send_raw_cb;
boost::function<uhd::shared_iovec(void)> _recv_raw_cb;
};
diff --git a/include/uhd/utils.hpp b/include/uhd/utils.hpp
index b080516a5..13367990e 100644
--- a/include/uhd/utils.hpp
+++ b/include/uhd/utils.hpp
@@ -27,23 +27,50 @@
#ifndef INCLUDED_UHD_UTILS_HPP
#define INCLUDED_UHD_UTILS_HPP
-namespace uhd{
+/*!
+ * Useful templated functions and classes that I like to pretend are part of stl
+ */
+namespace std{
+
+ class assert_error : public std::logic_error{
+ public:
+ explicit assert_error(const string& what_arg) : logic_error(what_arg){
+ /* NOP */
+ }
+ };
-template <class Key, class T> //TODO template this better
-std::vector<Key> get_map_keys(const std::map<Key, T> &m){
- std::vector<Key> v;
- std::pair<Key, T> p;
- BOOST_FOREACH(p, m){
- v.push_back(p.first);
+ #define ASSERT_THROW(_x) if (not (_x)) { \
+ throw std::assert_error("Assertion Failed: " + std::string(#_x)); \
}
- return v;
-}
-template<typename T> T signum(T n){
- if (n < 0) return -1;
- if (n > 0) return 1;
- return 0;
-}
+ template<class T, class InputIterator, class Function>
+ T reduce(InputIterator first, InputIterator last, Function fcn, T init = 0){
+ T tmp = init;
+ for ( ; first != last; ++first ){
+ tmp = fcn(tmp, *first);
+ }
+ return tmp;
+ }
+
+ template<class T, class InputIterator>
+ bool has(InputIterator first, InputIterator last, const T &elem){
+ return last != std::find(first, last, elem);
+ }
+
+ template<class T>
+ T sum(const T &a, const T &b){
+ return a + b;
+ }
+
+ template<typename T> T signum(T n){
+ if (n < 0) return -1;
+ if (n > 0) return 1;
+ return 0;
+ }
+
+}//namespace std
+
+namespace uhd{
inline void tune(
freq_t target_freq,
@@ -62,7 +89,7 @@ inline void tune(
// Calculate the DDC setting that will downconvert the baseband from the
// daughterboard to our target frequency.
freq_t delta_freq = target_freq - inter_freq;
- int delta_sign = signum(delta_freq);
+ int delta_sign = std::signum(delta_freq);
delta_freq *= delta_sign;
delta_freq = fmod(delta_freq, dsp_sample_rate);
bool inverted = delta_freq > dsp_sample_rate/2.0;
@@ -91,41 +118,4 @@ inline void tune(
} //namespace uhd
-/*!
- * Useful templated functions and classes that I like to pretend are part of stl
- */
-namespace std{
-
- class assert_error : public std::logic_error{
- public:
- explicit assert_error(const string& what_arg) : logic_error(what_arg){
- /* NOP */
- }
- };
-
- #define ASSERT_THROW(_x) if (not (_x)) { \
- throw std::assert_error("Assertion Failed: " + std::string(#_x)); \
- }
-
- template<class T, class InputIterator, class Function>
- T reduce(InputIterator first, InputIterator last, Function fcn, T init = 0){
- T tmp = init;
- for ( ; first != last; ++first ){
- tmp = fcn(tmp, *first);
- }
- return tmp;
- }
-
- template<class T, class InputIterator>
- bool has(InputIterator first, InputIterator last, const T &elem){
- return last != std::find(first, last, elem);
- }
-
- template<class T>
- T sum(const T &a, const T &b){
- return a + b;
- }
-
-}//namespace std
-
#endif /* INCLUDED_UHD_UTILS_HPP */
diff --git a/lib/usrp/dboard/id.cpp b/lib/usrp/dboard/id.cpp
index b55028a11..0f173ef14 100644
--- a/lib/usrp/dboard/id.cpp
+++ b/lib/usrp/dboard/id.cpp
@@ -16,21 +16,19 @@
//
#include <uhd/usrp/dboard/id.hpp>
-#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
-#include <map>
+#include <uhd/dict.hpp>
using namespace uhd::usrp::dboard;
std::ostream& operator<<(std::ostream &os, const dboard_id_t &id){
//map the dboard ids to string representations
- std::map<dboard_id_t, std::string> id_to_str = boost::assign::map_list_of
- (ID_BASIC_TX, "basic tx")
- (ID_BASIC_RX, "basic rx")
- ;
+ uhd::dict<dboard_id_t, std::string> id_to_str;
+ id_to_str[ID_BASIC_TX] = "basic tx";
+ id_to_str[ID_BASIC_RX] = "basic rx";
//get the string representation
- if (id_to_str.count(id) != 0){
+ if (id_to_str.has_key(id)){
os << id_to_str[id];
}
else{
diff --git a/lib/usrp/dboard/manager.cpp b/lib/usrp/dboard/manager.cpp
index 5005301ba..f6d9a718e 100644
--- a/lib/usrp/dboard/manager.cpp
+++ b/lib/usrp/dboard/manager.cpp
@@ -16,7 +16,6 @@
//
#include <uhd/usrp/dboard/manager.hpp>
-#include <uhd/utils.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
@@ -51,10 +50,10 @@ static void register_internal_dboards(void){
* storage and registering for dboards
**********************************************************************/
//map a dboard id to a dboard constructor
-static std::map<dboard_id_t, manager::dboard_ctor_t> id_to_ctor_map;
+static uhd::dict<dboard_id_t, manager::dboard_ctor_t> id_to_ctor_map;
//map a dboard constructor to subdevice names
-static std::map<manager::dboard_ctor_t, prop_names_t> ctor_to_names_map;
+static uhd::dict<manager::dboard_ctor_t, prop_names_t> ctor_to_names_map;
void manager::register_subdevs(
dboard_id_t dboard_id,
@@ -117,7 +116,7 @@ static manager::dboard_ctor_t const& get_dboard_ctor(
std::string const& xx_type
){
//verify that there is a registered constructor for this id
- if (id_to_ctor_map.count(dboard_id) == 0){
+ if (not id_to_ctor_map.has_key(dboard_id)){
throw std::runtime_error(str(
boost::format("Unknown %s dboard id: 0x%04x") % xx_type % dboard_id
));
@@ -180,15 +179,15 @@ manager::~manager(void){
}
prop_names_t manager::get_rx_subdev_names(void){
- return get_map_keys(_rx_dboards);
+ return _rx_dboards.get_keys();
}
prop_names_t manager::get_tx_subdev_names(void){
- return get_map_keys(_tx_dboards);
+ return _tx_dboards.get_keys();
}
wax::obj manager::get_rx_subdev(const std::string &subdev_name){
- if (_rx_dboards.count(subdev_name) == 0) throw std::invalid_argument(
+ if (not _rx_dboards.has_key(subdev_name)) throw std::invalid_argument(
str(boost::format("Unknown rx subdev name %s") % subdev_name)
);
//get a link to the rx subdev proxy
@@ -196,7 +195,7 @@ wax::obj manager::get_rx_subdev(const std::string &subdev_name){
}
wax::obj manager::get_tx_subdev(const std::string &subdev_name){
- if (_tx_dboards.count(subdev_name) == 0) throw std::invalid_argument(
+ if (not _tx_dboards.has_key(subdev_name)) throw std::invalid_argument(
str(boost::format("Unknown tx subdev name %s") % subdev_name)
);
//get a link to the tx subdev proxy
diff --git a/lib/usrp/mboard/test.cpp b/lib/usrp/mboard/test.cpp
index b4ac66eb7..c533c97b4 100644
--- a/lib/usrp/mboard/test.cpp
+++ b/lib/usrp/mboard/test.cpp
@@ -16,7 +16,6 @@
//
#include <uhd/usrp/mboard/test.hpp>
-#include <uhd/utils.hpp>
#include <uhd/props.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
@@ -139,7 +138,7 @@ void test::get(const wax::obj &key_, wax::obj &val){
return;
case MBOARD_PROP_RX_DBOARD:
- if (_dboard_managers.count(name) == 0) throw std::invalid_argument(
+ if (not _dboard_managers.has_key(name)) throw std::invalid_argument(
str(boost::format("Unknown rx dboard name %s") % name)
);
//FIXME store the shell dboard within the class
@@ -150,11 +149,11 @@ void test::get(const wax::obj &key_, wax::obj &val){
return;
case MBOARD_PROP_RX_DBOARD_NAMES:
- val = prop_names_t(get_map_keys(_dboard_managers));
+ val = prop_names_t(_dboard_managers.get_keys());
return;
case MBOARD_PROP_TX_DBOARD:
- if (_dboard_managers.count(name) == 0) throw std::invalid_argument(
+ if (not _dboard_managers.has_key(name)) throw std::invalid_argument(
str(boost::format("Unknown tx dboard name %s") % name)
);
//FIXME store the shell dboard within the class
@@ -165,7 +164,7 @@ void test::get(const wax::obj &key_, wax::obj &val){
return;
case MBOARD_PROP_TX_DBOARD_NAMES:
- val = prop_names_t(get_map_keys(_dboard_managers));
+ val = prop_names_t(_dboard_managers.get_keys());
return;
case MBOARD_PROP_MTU:
diff --git a/lib/usrp/usrp.cpp b/lib/usrp/usrp.cpp
index 68b423538..86a40ebd8 100644
--- a/lib/usrp/usrp.cpp
+++ b/lib/usrp/usrp.cpp
@@ -18,7 +18,6 @@
#include <uhd/usrp/usrp.hpp>
#include <uhd/usrp/mboard/usrp2.hpp>
#include <uhd/usrp/mboard/test.hpp>
-#include <uhd/utils.hpp>
#include <boost/format.hpp>
#include <boost/bind.hpp>
#include <stdexcept>
@@ -72,7 +71,7 @@ void usrp::get(const wax::obj &key_, wax::obj &val){
return;
case DEVICE_PROP_MBOARD:
- if (_mboards.count(name) == 0) throw std::invalid_argument(
+ if (not _mboards.has_key(name)) throw std::invalid_argument(
str(boost::format("Unknown mboard name %s") % name)
);
//turn the mboard sptr object into a wax::obj::sptr
@@ -81,7 +80,7 @@ void usrp::get(const wax::obj &key_, wax::obj &val){
return;
case DEVICE_PROP_MBOARD_NAMES:
- val = prop_names_t(get_map_keys(_mboards));
+ val = prop_names_t(_mboards.get_keys());
return;
}
}
diff --git a/test/gain_handler_test.cpp b/test/gain_handler_test.cpp
index 30e88c445..c81221aac 100644
--- a/test/gain_handler_test.cpp
+++ b/test/gain_handler_test.cpp
@@ -17,7 +17,7 @@
#include <boost/test/unit_test.hpp>
#include <uhd/gain_handler.hpp>
-#include <uhd/utils.hpp>
+#include <uhd/dict.hpp>
#include <iostream>
using namespace uhd;
@@ -74,7 +74,7 @@ private:
return;
case PROP_GAIN_NAMES:
- val = prop_names_t(get_map_keys(_gains));
+ val = prop_names_t(_gains.get_keys());
return;
}
}
@@ -100,10 +100,10 @@ private:
}
gain_handler::sptr _gain_handler;
- std::map<std::string, gain_t> _gains;
- std::map<std::string, gain_t> _gains_min;
- std::map<std::string, gain_t> _gains_max;
- std::map<std::string, gain_t> _gains_step;
+ uhd::dict<std::string, gain_t> _gains;
+ uhd::dict<std::string, gain_t> _gains_min;
+ uhd::dict<std::string, gain_t> _gains_max;
+ uhd::dict<std::string, gain_t> _gains_step;
};