ranges.h
Go to the documentation of this file.
//
// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef INCLUDED_OSMOSDR_RANGES_H
#define INCLUDED_OSMOSDR_RANGES_H
#include <osmosdr/api.h>
#include <osmosdr/pimpl.h>
#include <string>
#include <vector>
namespace osmosdr{
//! A wildcard motherboard index
static const size_t ALL_MBOARDS = size_t(~0);
//! A wildcard channel index
static const size_t ALL_CHANS = size_t(~0);
/*!
* A range object describes a set of discrete values of the form:
* y = start + step*n, where n is an integer between 0 and (stop - start)/step
*/
class OSMOSDR_API range_t{
public:
/*!
* Create a range from a single value.
* The step size will be taken as zero.
* \param value the only possible value in this range
*/
range_t(double value = 0);
/*!
* Create a range from a full set of values.
* A step size of zero implies infinite precision.
* \param start the minimum value for this range
* \param stop the maximum value for this range
* \param step the step size for this range
*/
range_t(double start, double stop, double step = 0);
//! Get the start value for this range.
double start(void) const;
//! Get the stop value for this range.
double stop(void) const;
//! Get the step value for this range.
double step(void) const;
//! Convert this range to a printable string
const std::string to_pp_string(void) const;
private: OSMOSDR_PIMPL_DECL(impl) _impl;
};
/*!
* A meta-range object holds a list of individual ranges.
*/
struct OSMOSDR_API meta_range_t : std::vector<range_t>{
//! A default constructor for an empty meta-range
meta_range_t(void);
/*!
* Input iterator constructor:
* Makes boost::assign::list_of work.
* \param first the begin iterator
* \param last the end iterator
*/
template <typename InputIterator>
meta_range_t(InputIterator first, InputIterator last):
std::vector<range_t>(first, last){ /* NOP */ }
/*!
* A convenience constructor for a single range.
* A step size of zero implies infinite precision.
* \param start the minimum value for this range
* \param stop the maximum value for this range
* \param step the step size for this range
*/
meta_range_t(double start, double stop, double step = 0);
//! Get the overall start value for this meta-range.
double start(void) const;
//! Get the overall stop value for this meta-range.
double stop(void) const;
//! Get the overall step value for this meta-range.
double step(void) const;
/*!
* Clip the target value to a possible range value.
* \param value the value to clip to this range
* \param clip_step if true, clip to steps as well
* \return a value that is in one of the ranges
*/
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;
};
typedef meta_range_t gain_range_t;
typedef meta_range_t freq_range_t;
} //namespace osmosdr
#endif /* INCLUDED_OSMOSDR_RANGES_H */
api.h
OSMOSDR_API
#define OSMOSDR_API
Definition api.h:30
osmosdr::range_t
Definition ranges.h:38
osmosdr::range_t::step
double step(void) const
Get the step value for this range.
osmosdr::range_t::start
double start(void) const
Get the start value for this range.
osmosdr::range_t::range_t
range_t(double value=0)
osmosdr::range_t::range_t
range_t(double start, double stop, double step=0)
osmosdr::range_t::stop
double stop(void) const
Get the stop value for this range.
osmosdr::range_t::to_pp_string
const std::string to_pp_string(void) const
Convert this range to a printable string.
osmosdr
Definition device.h:35
osmosdr::freq_range_t
meta_range_t freq_range_t
Definition ranges.h:125
osmosdr::ALL_CHANS
static const size_t ALL_CHANS
A wildcard channel index.
Definition ranges.h:32
osmosdr::ALL_MBOARDS
static const size_t ALL_MBOARDS
A wildcard motherboard index.
Definition ranges.h:29
osmosdr::gain_range_t
meta_range_t gain_range_t
Definition ranges.h:124
pimpl.h
OSMOSDR_PIMPL_DECL
#define OSMOSDR_PIMPL_DECL(_name)
Definition pimpl.h:41
osmosdr::meta_range_t
Definition ranges.h:75
osmosdr::meta_range_t::values
std::vector< double > values() const
osmosdr::meta_range_t::clip
double clip(double value, bool clip_step=false) const
osmosdr::meta_range_t::step
double step(void) const
Get the overall step value for this meta-range.
osmosdr::meta_range_t::stop
double stop(void) const
Get the overall stop value for this meta-range.
osmosdr::meta_range_t::meta_range_t
meta_range_t(double start, double stop, double step=0)
osmosdr::meta_range_t::start
double start(void) const
Get the overall start value for this meta-range.
osmosdr::meta_range_t::meta_range_t
meta_range_t(InputIterator first, InputIterator last)
Definition ranges.h:87
osmosdr::meta_range_t::meta_range_t
meta_range_t(void)
A default constructor for an empty meta-range.
osmosdr::meta_range_t::to_pp_string
const std::string to_pp_string(void) const
Convert this meta-range to a printable string.