aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitri Stolnikov <horiz0n@gmx.net>2013-02-16 12:19:47 +0100
committerDimitri Stolnikov <horiz0n@gmx.net>2013-02-16 12:19:47 +0100
commit878c80d8ca6e159038ff8e6ee974f54233f7a3d9 (patch)
tree1d0c77e91e598ce9145ee9281d1e0cae5eb47007
parentd11b7a2614d8292168746050b9d197fba8981515 (diff)
add meta_range_t::values() which returns all values of the range
-rw-r--r--include/osmosdr/osmosdr_ranges.h3
-rw-r--r--lib/osmosdr_ranges.cc21
2 files changed, 24 insertions, 0 deletions
diff --git a/include/osmosdr/osmosdr_ranges.h b/include/osmosdr/osmosdr_ranges.h
index b7939df..c84eb95 100644
--- a/include/osmosdr/osmosdr_ranges.h
+++ b/include/osmosdr/osmosdr_ranges.h
@@ -107,6 +107,9 @@ namespace osmosdr{
*/
double clip(double value, bool clip_step = false) const;
+ /*! return a vector containing all values of the range */
+ std::vector<double> values() const;
+
//! Convert this meta-range to a printable string
const std::string to_pp_string(void) const;
diff --git a/lib/osmosdr_ranges.cc b/lib/osmosdr_ranges.cc
index 0b7ecbb..c018c29 100644
--- a/lib/osmosdr_ranges.cc
+++ b/lib/osmosdr_ranges.cc
@@ -154,6 +154,27 @@ double meta_range_t::clip(double value, bool clip_step) const{
return last_stop;
}
+std::vector<double> meta_range_t::values() const {
+ std::vector<double> values;
+
+ BOOST_FOREACH(const range_t &r, (*this)) {
+ if (r.start() != r.stop()) {
+ if ( r.step() == 0 ) {
+ values.push_back( r.start() );
+ values.push_back( r.stop() );
+ } else {
+ for ( double val = r.start(); val <= r.stop(); val += r.step() ) {
+ values.push_back( val );
+ }
+ }
+ } else {
+ values.push_back( r.start() );
+ }
+ }
+
+ return values;
+}
+
const std::string meta_range_t::to_pp_string(void) const{
std::stringstream ss;
BOOST_FOREACH(const range_t &r, (*this)){