summaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-05-02 04:28:50 +0000
committerJosh Blum <josh@joshknows.com>2010-05-02 04:28:50 +0000
commit6ec2883fcd3e0b2765c63f2e96e155d52248bf89 (patch)
tree123181b29494d3c26ad96f9df65a718def9a65d8 /host/include
parent3a8577aeb3c76dce0d0dcf0c9c7ce8d9aaf0a1d8 (diff)
parentbe97b68ba230e16b513e5a0310aded49f4b2dcb4 (diff)
downloaduhd-6ec2883fcd3e0b2765c63f2e96e155d52248bf89.tar.gz
uhd-6ec2883fcd3e0b2765c63f2e96e155d52248bf89.tar.bz2
uhd-6ec2883fcd3e0b2765c63f2e96e155d52248bf89.zip
Merge branch 'master' of git@ettus.sourcerepo.com:ettus/uhdpriv into usrp_e
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/config.hpp22
-rw-r--r--host/include/uhd/types/device_addr.hpp10
-rw-r--r--host/include/uhd/types/dict.hpp4
-rw-r--r--host/include/uhd/usrp/dboard_base.hpp24
-rw-r--r--host/include/uhd/usrp/dboard_id.hpp64
-rw-r--r--host/include/uhd/usrp/dboard_manager.hpp2
-rw-r--r--host/include/uhd/utils/algorithm.hpp30
-rw-r--r--host/include/uhd/utils/assert.hpp18
8 files changed, 103 insertions, 71 deletions
diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp
index 941219ac7..32eafc89b 100644
--- a/host/include/uhd/config.hpp
+++ b/host/include/uhd/config.hpp
@@ -39,27 +39,23 @@
//define logical operators
#ifdef BOOST_MSVC
- #define not !
- #define and &&
- #define or ||
+ #include <ciso646>
#endif
// http://gcc.gnu.org/wiki/Visibility
// Generic helper definitions for shared library support
-#if defined _WIN32 || defined __CYGWIN__
+#if defined(BOOST_HAS_DECLSPEC)
#define UHD_HELPER_DLL_IMPORT __declspec(dllimport)
#define UHD_HELPER_DLL_EXPORT __declspec(dllexport)
#define UHD_HELPER_DLL_LOCAL
+#elif defined(__GNUG__) && __GNUG__ >= 4
+ #define UHD_HELPER_DLL_IMPORT __attribute__ ((visibility("default")))
+ #define UHD_HELPER_DLL_EXPORT __attribute__ ((visibility("default")))
+ #define UHD_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden")))
#else
- #if __GNUC__ >= 4
- #define UHD_HELPER_DLL_IMPORT __attribute__ ((visibility("default")))
- #define UHD_HELPER_DLL_EXPORT __attribute__ ((visibility("default")))
- #define UHD_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden")))
- #else
- #define UHD_HELPER_DLL_IMPORT
- #define UHD_HELPER_DLL_EXPORT
- #define UHD_HELPER_DLL_LOCAL
- #endif
+ #define UHD_HELPER_DLL_IMPORT
+ #define UHD_HELPER_DLL_EXPORT
+ #define UHD_HELPER_DLL_LOCAL
#endif
// Now we use the generic helper definitions above to define UHD_API and UHD_LOCAL.
diff --git a/host/include/uhd/types/device_addr.hpp b/host/include/uhd/types/device_addr.hpp
index e8da2a1ab..e359d9467 100644
--- a/host/include/uhd/types/device_addr.hpp
+++ b/host/include/uhd/types/device_addr.hpp
@@ -40,7 +40,7 @@ namespace uhd{
* An arguments string, is a way to represent a device address
* using a single string with delimiter characters.
* - Ex: addr=192.168.10.2
- * - Ex: addr=192.168.10.2, rx_buff_size=1e6
+ * - Ex: addr=192.168.10.2, recv_buff_size=1e6
*/
class UHD_API device_addr_t : public dict<std::string, std::string>{
public:
@@ -51,17 +51,17 @@ namespace uhd{
device_addr_t(const std::string &args = "");
/*!
- * Convert a device address into a printable string.
- * \return string good for use with std::cout <<
+ * Convert a device address into a pretty print string.
+ * \return a printable string representing the device address
*/
- std::string to_string(void) const;
+ std::string to_pp_string(void) const;
/*!
* Convert the device address into an args string.
* The args string contains delimiter symbols.
* \return a string with delimiter markup
*/
- std::string to_args_str(void) const;
+ std::string to_string(void) const;
};
//handy typedef for a vector of device addresses
diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp
index c8fbc5a9f..b5fb11120 100644
--- a/host/include/uhd/types/dict.hpp
+++ b/host/include/uhd/types/dict.hpp
@@ -29,7 +29,7 @@ namespace uhd{
/*!
* A templated dictionary class with a python-like interface.
*/
- template <class Key, class Val> class dict{
+ template <typename Key, typename Val> class dict{
public:
typedef std::pair<Key, Val> pair_t;
@@ -130,7 +130,7 @@ namespace uhd{
BOOST_FOREACH(pair_t &p, _map){
if (p.first == key) return p.second;
}
- _map.push_back(pair_t(key, Val()));
+ _map.push_back(std::make_pair(key, Val()));
return _map.back().second;
}
diff --git a/host/include/uhd/usrp/dboard_base.hpp b/host/include/uhd/usrp/dboard_base.hpp
index 2025760ee..28bf2ae66 100644
--- a/host/include/uhd/usrp/dboard_base.hpp
+++ b/host/include/uhd/usrp/dboard_base.hpp
@@ -22,7 +22,6 @@
#include <uhd/wax.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
-#include <boost/tuple/tuple.hpp>
#include <uhd/usrp/dboard_id.hpp>
#include <uhd/usrp/dboard_iface.hpp>
@@ -35,13 +34,15 @@ namespace uhd{ namespace usrp{
class UHD_API dboard_base : boost::noncopyable{
public:
typedef boost::shared_ptr<dboard_base> sptr;
- //the constructor args consist of a subdev name, interface, and ids
- //derived classes should pass the args into the dboard_base class ctor
- //but should not have to deal with the internals of the args
- typedef boost::tuple<std::string, dboard_iface::sptr, dboard_id_t, dboard_id_t> ctor_args_t;
+ /*!
+ * An opaque type for the dboard constructor args.
+ * Derived classes should pass the args into the base class,
+ * but should not deal with the internals of the args.
+ */
+ struct ctor_args_impl; typedef ctor_args_impl* ctor_args_t;
//structors
- dboard_base(ctor_args_t const&);
+ dboard_base(ctor_args_t);
virtual ~dboard_base(void);
//interface
@@ -57,9 +58,8 @@ protected:
dboard_id_t get_tx_id(void);
private:
- std::string _subdev_name;
- dboard_iface::sptr _dboard_iface;
- dboard_id_t _rx_id, _tx_id;
+ struct dboard_base_impl;
+ dboard_base_impl *_impl;
};
/*!
@@ -71,7 +71,7 @@ public:
/*!
* Create a new xcvr dboard object, override in subclasses.
*/
- xcvr_dboard_base(ctor_args_t const&);
+ xcvr_dboard_base(ctor_args_t);
virtual ~xcvr_dboard_base(void);
};
@@ -85,7 +85,7 @@ public:
/*!
* Create a new rx dboard object, override in subclasses.
*/
- rx_dboard_base(ctor_args_t const&);
+ rx_dboard_base(ctor_args_t);
virtual ~rx_dboard_base(void);
@@ -103,7 +103,7 @@ public:
/*!
* Create a new rx dboard object, override in subclasses.
*/
- tx_dboard_base(ctor_args_t const&);
+ tx_dboard_base(ctor_args_t);
virtual ~tx_dboard_base(void);
diff --git a/host/include/uhd/usrp/dboard_id.hpp b/host/include/uhd/usrp/dboard_id.hpp
index afacaf8ff..8b6eaf6bd 100644
--- a/host/include/uhd/usrp/dboard_id.hpp
+++ b/host/include/uhd/usrp/dboard_id.hpp
@@ -20,16 +20,70 @@
#include <uhd/config.hpp>
#include <boost/cstdint.hpp>
+#include <boost/operators.hpp>
#include <string>
namespace uhd{ namespace usrp{
-typedef boost::uint16_t dboard_id_t;
+ class UHD_API dboard_id_t : boost::equality_comparable1<dboard_id_t>{
+ public:
+ /*!
+ * Create a dboard id from an integer.
+ * \param id the integer representation
+ */
+ dboard_id_t(boost::uint16_t id = 0xffff);
-namespace dboard_id{
- static const dboard_id_t NONE = 0xffff;
- UHD_API std::string to_string(const dboard_id_t &id);
-}
+ /*!
+ * Obtain a dboard id that represents no dboard.
+ * \return the dboard id with the 0xffff id.
+ */
+ static dboard_id_t none(void);
+
+ /*!
+ * Create a new dboard id from an integer representation.
+ * \param uint16 an unsigned 16 bit integer
+ * \return a new dboard id containing the integer
+ */
+ static dboard_id_t from_uint16(boost::uint16_t uint16);
+
+ /*!
+ * Get the dboard id represented as an integer.
+ * \return an unsigned 16 bit integer representation
+ */
+ boost::uint16_t to_uint16(void) const;
+
+ /*!
+ * Create a new dboard id from a string representation.
+ * If the string has a 0x prefix, it will be parsed as hex.
+ * \param string a numeric string, possibly hex
+ * \return a new dboard id containing the integer
+ */
+ static dboard_id_t from_string(const std::string &string);
+
+ /*!
+ * Get the dboard id represented as an integer.
+ * \return a hex string representation with 0x prefix
+ */
+ std::string to_string(void) const;
+
+ /*!
+ * Get the pretty print representation of this dboard id.
+ * \return a string with the dboard name and id number
+ */
+ std::string to_pp_string(void) const;
+
+ private:
+ boost::uint16_t _id; //internal representation
+ };
+
+ /*!
+ * Comparator operator overloaded for dboard ids.
+ * The boost::equality_comparable provides the !=.
+ * \param lhs the dboard id to the left of the operator
+ * \param rhs the dboard id to the right of the operator
+ * \return true when the dboard ids are equal
+ */
+ UHD_API bool operator==(const dboard_id_t &lhs, const dboard_id_t &rhs);
}} //namespace
diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp
index 007d85bb4..b84fee4e7 100644
--- a/host/include/uhd/usrp/dboard_manager.hpp
+++ b/host/include/uhd/usrp/dboard_manager.hpp
@@ -37,7 +37,7 @@ public:
typedef boost::shared_ptr<dboard_manager> sptr;
//dboard constructor (each dboard should have a ::make with this signature)
- typedef dboard_base::sptr(*dboard_ctor_t)(dboard_base::ctor_args_t const&);
+ typedef dboard_base::sptr(*dboard_ctor_t)(dboard_base::ctor_args_t);
/*!
* Register a dboard into the system.
diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp
index 8fe9cde82..72b655745 100644
--- a/host/include/uhd/utils/algorithm.hpp
+++ b/host/include/uhd/utils/algorithm.hpp
@@ -19,43 +19,25 @@
#define INCLUDED_UHD_UTILS_ALGORITHM_HPP
#include <algorithm>
+#include <boost/range/functions.hpp>
/*!
* Useful templated functions and classes that I like to pretend are part of stl
*/
namespace std{
- 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<typename Range, typename T> inline
+ bool has(const Range &range, const T &value){
+ return boost::end(range) != std::find(boost::begin(range), boost::end(range), value);
}
- 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);
- }
-
- template<class T, class Iterable>
- bool has(const Iterable &iterable, const T &elem){
- return has(iterable.begin(), iterable.end(), elem);
- }
-
- template<class T> T signum(T n){
+ template<typename T> inline T signum(T n){
if (n < 0) return -1;
if (n > 0) return 1;
return 0;
}
- template<class T> T clip(T val, T minVal, T maxVal){
+ template<typename T> inline T clip(T val, T minVal, T maxVal){
return std::min(std::max(val, minVal), maxVal);
}
diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp
index 0a278312e..6aca64f8c 100644
--- a/host/include/uhd/utils/assert.hpp
+++ b/host/include/uhd/utils/assert.hpp
@@ -50,28 +50,28 @@ namespace uhd{
* The "what" in the error will show what is
* being set and a list of known good values.
*
- * \param iterable a list of possible settings
- * \param elem an element that may be in the list
+ * \param range a list of possible settings
+ * \param value an element that may be in the list
* \param what a description of what is being set
* \throw assertion_error when elem not in list
*/
- template<class T, class Iterable> void assert_has(
- const Iterable &iterable,
- const T &elem,
+ template<typename T, typename Range> void assert_has(
+ const Range &range,
+ const T &value,
const std::string &what = "unknown"
){
- if (std::has(iterable, elem)) return;
+ if (std::has(range, value)) return;
std::string possible_values = "";
size_t i = 0;
- BOOST_FOREACH(const T &e, iterable){
+ BOOST_FOREACH(const T &v, range){
if (i++ > 0) possible_values += ", ";
- possible_values += boost::lexical_cast<std::string>(e);
+ possible_values += boost::lexical_cast<std::string>(v);
}
boost::throw_exception(uhd::assert_error() << assert_info(str(boost::format(
"Error: %s is not a valid %s. "
"Possible values are: [%s]."
)
- % boost::lexical_cast<std::string>(elem)
+ % boost::lexical_cast<std::string>(value)
% what % possible_values
)));
}