add meta_range_t::values() which returns all values of the range

This commit is contained in:
Dimitri Stolnikov 2013-02-16 12:19:47 +01:00
parent d11b7a2614
commit 878c80d8ca
2 changed files with 24 additions and 0 deletions

View File

@ -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;

View File

@ -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)){