GNU Radio's OsmoSDR Package
ranges.h
Go to the documentation of this file.
1 //
2 // Copyright 2010-2011 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_OSMOSDR_RANGES_H
19 #define INCLUDED_OSMOSDR_RANGES_H
20 
21 #include <osmosdr/api.h>
22 #include <osmosdr/pimpl.h>
23 #include <string>
24 #include <vector>
25 
26 namespace osmosdr{
27 
28  /*!
29  * A range object describes a set of discrete values of the form:
30  * y = start + step*n, where n is an integer between 0 and (stop - start)/step
31  */
33  public:
34 
35  /*!
36  * Create a range from a single value.
37  * The step size will be taken as zero.
38  * \param value the only possible value in this range
39  */
40  range_t(double value = 0);
41 
42  /*!
43  * Create a range from a full set of values.
44  * A step size of zero implies infinite precision.
45  * \param start the minimum value for this range
46  * \param stop the maximum value for this range
47  * \param step the step size for this range
48  */
49  range_t(double start, double stop, double step = 0);
50 
51  //! Get the start value for this range.
52  double start(void) const;
53 
54  //! Get the stop value for this range.
55  double stop(void) const;
56 
57  //! Get the step value for this range.
58  double step(void) const;
59 
60  //! Convert this range to a printable string
61  const std::string to_pp_string(void) const;
62 
63  private: OSMOSDR_PIMPL_DECL(impl) _impl;
64  };
65 
66  /*!
67  * A meta-range object holds a list of individual ranges.
68  */
69  struct OSMOSDR_API meta_range_t : std::vector<range_t>{
70 
71  //! A default constructor for an empty meta-range
72  meta_range_t(void);
73 
74  /*!
75  * Input iterator constructor:
76  * Makes boost::assign::list_of work.
77  * \param first the begin iterator
78  * \param last the end iterator
79  */
80  template <typename InputIterator>
81  meta_range_t(InputIterator first, InputIterator last):
82  std::vector<range_t>(first, last){ /* NOP */ }
83 
84  /*!
85  * A convenience constructor for a single range.
86  * A step size of zero implies infinite precision.
87  * \param start the minimum value for this range
88  * \param stop the maximum value for this range
89  * \param step the step size for this range
90  */
91  meta_range_t(double start, double stop, double step = 0);
92 
93  //! Get the overall start value for this meta-range.
94  double start(void) const;
95 
96  //! Get the overall stop value for this meta-range.
97  double stop(void) const;
98 
99  //! Get the overall step value for this meta-range.
100  double step(void) const;
101 
102  /*!
103  * Clip the target value to a possible range value.
104  * \param value the value to clip to this range
105  * \param clip_step if true, clip to steps as well
106  * \return a value that is in one of the ranges
107  */
108  double clip(double value, bool clip_step = false) const;
109 
110  /*! return a vector containing all values of the range */
111  std::vector<double> values() const;
112 
113  //! Convert this meta-range to a printable string
114  const std::string to_pp_string(void) const;
115 
116  };
117 
120 
121 } //namespace osmosdr
122 
123 #endif /* INCLUDED_OSMOSDR_RANGES_H */
meta_range_t freq_range_t
Definition: ranges.h:119
Definition: ranges.h:32
STL namespace.
Definition: ranges.h:69
meta_range_t(InputIterator first, InputIterator last)
Definition: ranges.h:81
meta_range_t gain_range_t
Definition: ranges.h:118
#define OSMOSDR_PIMPL_DECL(_name)
Definition: pimpl.h:41
#define OSMOSDR_API
Definition: api.h:30
Definition: device.h:35