GNU Radio's TEST 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
26namespace osmosdr{
27
28 //! A wildcard motherboard index
29 static const size_t ALL_MBOARDS = size_t(~0);
30
31 //! A wildcard channel index
32 static const size_t ALL_CHANS = size_t(~0);
33
34 /*!
35 * A range object describes a set of discrete values of the form:
36 * y = start + step*n, where n is an integer between 0 and (stop - start)/step
37 */
39 public:
40
41 /*!
42 * Create a range from a single value.
43 * The step size will be taken as zero.
44 * \param value the only possible value in this range
45 */
46 range_t(double value = 0);
47
48 /*!
49 * Create a range from a full set of values.
50 * A step size of zero implies infinite precision.
51 * \param start the minimum value for this range
52 * \param stop the maximum value for this range
53 * \param step the step size for this range
54 */
55 range_t(double start, double stop, double step = 0);
56
57 //! Get the start value for this range.
58 double start(void) const;
59
60 //! Get the stop value for this range.
61 double stop(void) const;
62
63 //! Get the step value for this range.
64 double step(void) const;
65
66 //! Convert this range to a printable string
67 const std::string to_pp_string(void) const;
68
69 private: OSMOSDR_PIMPL_DECL(impl) _impl;
70 };
71
72 /*!
73 * A meta-range object holds a list of individual ranges.
74 */
75 struct OSMOSDR_API meta_range_t : std::vector<range_t>{
76
77 //! A default constructor for an empty meta-range
79
80 /*!
81 * Input iterator constructor:
82 * Makes boost::assign::list_of work.
83 * \param first the begin iterator
84 * \param last the end iterator
85 */
86 template <typename InputIterator>
87 meta_range_t(InputIterator first, InputIterator last):
88 std::vector<range_t>(first, last){ /* NOP */ }
89
90 /*!
91 * A convenience constructor for a single range.
92 * A step size of zero implies infinite precision.
93 * \param start the minimum value for this range
94 * \param stop the maximum value for this range
95 * \param step the step size for this range
96 */
97 meta_range_t(double start, double stop, double step = 0);
98
99 //! Get the overall start value for this meta-range.
100 double start(void) const;
101
102 //! Get the overall stop value for this meta-range.
103 double stop(void) const;
104
105 //! Get the overall step value for this meta-range.
106 double step(void) const;
107
108 /*!
109 * Clip the target value to a possible range value.
110 * \param value the value to clip to this range
111 * \param clip_step if true, clip to steps as well
112 * \return a value that is in one of the ranges
113 */
114 double clip(double value, bool clip_step = false) const;
115
116 /*! return a vector containing all values of the range */
117 std::vector<double> values() const;
118
119 //! Convert this meta-range to a printable string
120 const std::string to_pp_string(void) const;
121
122 };
123
126
127} //namespace osmosdr
128
129#endif /* INCLUDED_OSMOSDR_RANGES_H */
#define OSMOSDR_API
Definition api.h:30
Definition ranges.h:38
double step(void) const
Get the step value for this range.
double start(void) const
Get the start value for this range.
range_t(double value=0)
range_t(double start, double stop, double step=0)
double stop(void) const
Get the stop value for this range.
const std::string to_pp_string(void) const
Convert this range to a printable string.
Definition device.h:35
meta_range_t freq_range_t
Definition ranges.h:125
static const size_t ALL_CHANS
A wildcard channel index.
Definition ranges.h:32
static const size_t ALL_MBOARDS
A wildcard motherboard index.
Definition ranges.h:29
meta_range_t gain_range_t
Definition ranges.h:124
#define OSMOSDR_PIMPL_DECL(_name)
Definition pimpl.h:41
Definition ranges.h:75
std::vector< double > values() const
double clip(double value, bool clip_step=false) const
double step(void) const
Get the overall step value for this meta-range.
double stop(void) const
Get the overall stop value for this meta-range.
meta_range_t(double start, double stop, double step=0)
double start(void) const
Get the overall start value for this meta-range.
meta_range_t(InputIterator first, InputIterator last)
Definition ranges.h:87
meta_range_t(void)
A default constructor for an empty meta-range.
const std::string to_pp_string(void) const
Convert this meta-range to a printable string.