aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorPaul David <paul.david@ettus.com>2017-05-09 21:36:02 -0400
committerMartin Braun <martin.braun@ettus.com>2017-05-23 17:14:32 -0700
commit2c0f1098351d6c0763d985c2085ec676a7992e2d (patch)
tree66b8c4cba5742f9e9a7f59d46c586957b35c4c28 /host
parent056dabcaf37469d0e614d269ded3e6e4c41d4cc8 (diff)
downloaduhd-2c0f1098351d6c0763d985c2085ec676a7992e2d.tar.gz
uhd-2c0f1098351d6c0763d985c2085ec676a7992e2d.tar.bz2
uhd-2c0f1098351d6c0763d985c2085ec676a7992e2d.zip
Types: Added equality/inquality operators to support Boost.Python additions
- Added to subdev_spec_pair_t - Added to range_t - Added tests for the inequalities
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/types/ranges.hpp6
-rw-r--r--host/include/uhd/usrp/subdev_spec.hpp6
-rw-r--r--host/lib/types/ranges.cpp12
-rw-r--r--host/lib/usrp/subdev_spec.cpp8
-rw-r--r--host/tests/ranges_test.cpp9
-rw-r--r--host/tests/subdev_spec_test.cpp8
6 files changed, 49 insertions, 0 deletions
diff --git a/host/include/uhd/types/ranges.hpp b/host/include/uhd/types/ranges.hpp
index ac632df93..b26b5d753 100644
--- a/host/include/uhd/types/ranges.hpp
+++ b/host/include/uhd/types/ranges.hpp
@@ -59,6 +59,12 @@ namespace uhd{
//! Convert this range to a printable string
const std::string to_pp_string(void) const;
+ //! Equality operator
+ bool operator==(const range_t &other) const;
+
+ //! Inequality operator
+ bool operator!=(const range_t &other) const;
+
private: double _start, _stop, _step;
};
diff --git a/host/include/uhd/usrp/subdev_spec.hpp b/host/include/uhd/usrp/subdev_spec.hpp
index 62c1fc177..4165a45f7 100644
--- a/host/include/uhd/usrp/subdev_spec.hpp
+++ b/host/include/uhd/usrp/subdev_spec.hpp
@@ -44,6 +44,12 @@ namespace uhd{ namespace usrp{
const std::string &db_name = "",
const std::string &sd_name = ""
);
+
+ //! overloaded equality operator
+ bool operator==(const subdev_spec_pair_t &other);
+
+ //! overloaded inquality operator
+ bool operator!=(const subdev_spec_pair_t &other);
};
//! overloaded comparison operator for subdev_spec_pair_t
diff --git a/host/lib/types/ranges.cpp b/host/lib/types/ranges.cpp
index ee4546cb8..d22e2fb6a 100644
--- a/host/lib/types/ranges.cpp
+++ b/host/lib/types/ranges.cpp
@@ -63,6 +63,18 @@ const std::string range_t::to_pp_string(void) const{
return ss.str();
}
+bool range_t::operator==(const range_t &other) const{
+ return (other._start == _start and
+ other._step == _step and
+ other._stop == _stop);
+}
+
+bool range_t::operator!=(const range_t &other) const{
+ return (other._start != _start or
+ other._step != _step or
+ other._stop != _stop);
+}
+
/***********************************************************************
* meta_range_t implementation code
**********************************************************************/
diff --git a/host/lib/usrp/subdev_spec.cpp b/host/lib/usrp/subdev_spec.cpp
index e59160a71..b7eb64f87 100644
--- a/host/lib/usrp/subdev_spec.cpp
+++ b/host/lib/usrp/subdev_spec.cpp
@@ -43,6 +43,14 @@ bool usrp::operator==(const subdev_spec_pair_t &lhs, const subdev_spec_pair_t &r
return (lhs.db_name == rhs.db_name) and (lhs.sd_name == rhs.sd_name);
}
+bool subdev_spec_pair_t::operator==(const subdev_spec_pair_t &other){
+ return (other.db_name == db_name) and (other.sd_name == sd_name);
+}
+
+bool subdev_spec_pair_t::operator!=(const subdev_spec_pair_t &other){
+ return (other.db_name != db_name) or (other.sd_name != sd_name);
+}
+
subdev_spec_t::subdev_spec_t(const std::string &markup){
for(const std::string &pair: pair_tokenizer(markup)){
if (pair.empty()) continue;
diff --git a/host/tests/ranges_test.cpp b/host/tests/ranges_test.cpp
index 85bb4c3c4..49607b9a3 100644
--- a/host/tests/ranges_test.cpp
+++ b/host/tests/ranges_test.cpp
@@ -68,3 +68,12 @@ BOOST_AUTO_TEST_CASE(test_ranges_clip2){
BOOST_CHECK_CLOSE(mr.clip(3.1, true), 3., tolerance);
BOOST_CHECK_CLOSE(mr.clip(4., true), 3., tolerance);
}
+
+BOOST_AUTO_TEST_CASE(test_ranges_compare){
+ range_t range(1);
+ range_t n_range(1);
+ range_t d_range(2);
+
+ BOOST_CHECK(range == n_range);
+ BOOST_CHECK(range != d_range);
+}
diff --git a/host/tests/subdev_spec_test.cpp b/host/tests/subdev_spec_test.cpp
index 2c4747fa9..81f86380b 100644
--- a/host/tests/subdev_spec_test.cpp
+++ b/host/tests/subdev_spec_test.cpp
@@ -27,6 +27,11 @@ BOOST_AUTO_TEST_CASE(test_subdevice_spec){
sd_spec.push_back(uhd::usrp::subdev_spec_pair_t("A", "AB"));
sd_spec.push_back(uhd::usrp::subdev_spec_pair_t("B", "AB"));
+ //create a subdev_spec with something different
+ uhd::usrp::subdev_spec_t diff_sd_spec;
+ diff_sd_spec.push_back(uhd::usrp::subdev_spec_pair_t("B", "BA"));
+ diff_sd_spec.push_back(uhd::usrp::subdev_spec_pair_t("B", "BA"));
+
//convert to and from args string
std::cout << "Pretty Print: " << std::endl << sd_spec.to_pp_string();
std::string markup_str = sd_spec.to_string();
@@ -40,5 +45,8 @@ BOOST_AUTO_TEST_CASE(test_subdevice_spec){
for (size_t i = 0; i < sd_spec.size(); i++){
BOOST_CHECK_EQUAL(sd_spec.at(i).db_name, new_sd_spec.at(i).db_name);
BOOST_CHECK_EQUAL(sd_spec.at(i).sd_name, new_sd_spec.at(i).sd_name);
+
+ BOOST_CHECK(sd_spec.at(i) == new_sd_spec.at(i));
+ BOOST_CHECK(sd_spec.at(i) != diff_sd_spec.at(i));
}
}