Statistics
| Branch: | Tag: | Revision:

root / host / include / uhd / types / ranges.hpp @ daa537d3

History | View | Annotate | Download (4.08 KB)

1
//
2
// Copyright 2010 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_UHD_TYPES_RANGES_HPP
19
#define INCLUDED_UHD_TYPES_RANGES_HPP
20

    
21
#include <uhd/config.hpp>
22
#include <uhd/utils/pimpl.hpp>
23
#include <vector>
24
#include <string>
25

    
26
namespace uhd{
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
     */
32
    template <typename T> class range_t{
33
    public:
34
        /*!
35
         * Create a range from a single value.
36
         * The step size will be taken as zero.
37
         * \param value the only possible value in this range
38
         */
39
        range_t(const T &value = T(0));
40

    
41
        /*!
42
         * Create a range from a full set of values.
43
         * A step size of zero implies infinite precision.
44
         * \param start the minimum value for this range
45
         * \param stop the maximum value for this range
46
         * \param step the step size for this range
47
         */
48
        range_t(const T &start, const T &stop, const T &step = T(0));
49

    
50
        //! Get the start value for this range.
51
        const T start(void) const;
52

    
53
        //! Get the stop value for this range.
54
        const T stop(void) const;
55

    
56
        //! Get the step value for this range.
57
        const T step(void) const;
58

    
59
        //! Convert this range to a printable string
60
        const std::string to_pp_string(void) const;
61

    
62
    private: 
63
        UHD_PIMPL_DECL(impl) _impl;
64
    };
65

    
66
    /*!
67
     * A meta-range object holds a list of individual ranges.
68
     */
69
    template <typename T> struct meta_range_t : std::vector<range_t<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

    
83
        /*!
84
         * A convenience constructor for a single range.
85
         * A step size of zero implies infinite precision.
86
         * \param start the minimum value for this range
87
         * \param stop the maximum value for this range
88
         * \param step the step size for this range
89
         */
90
        meta_range_t(const T &start, const T &stop, const T &step = T(0));
91

    
92
        //! Get the overall start value for this meta-range.
93
        const T start(void) const;
94

    
95
        //! Get the overall stop value for this meta-range.
96
        const T stop(void) const;
97

    
98
        //! Get the overall step value for this meta-range.
99
        const T step(void) const;
100

    
101
        /*!
102
         * Clip the target value to a possible range value.
103
         * \param value the value to clip to this range
104
         * \param clip_step if true, clip to steps as well
105
         * \return a value that is in one of the ranges
106
         */
107
         const T clip(const T &value, bool clip_step = false) const;
108

    
109
        //! Convert this meta-range to a printable string
110
        const std::string to_pp_string(void) const;
111

    
112
    };
113

    
114
    //! export a symbol for the gain range type
115
    EXIMP_TEMPLATE template struct UHD_API meta_range_t<float>;
116
    typedef meta_range_t<float> gain_range_t;
117

    
118
    //! export a symbol for the freq range type
119
    EXIMP_TEMPLATE template struct UHD_API meta_range_t<double>;
120
    typedef meta_range_t<double> freq_range_t;
121

    
122

    
123
} //namespace uhd
124

    
125
#include <uhd/types/ranges.ipp>
126

    
127
#endif /* INCLUDED_UHD_TYPES_RANGES_HPP */