aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-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
6 files changed, 60 insertions, 70 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 */