USRP Hardware Driver and USRP Manual  Version: 003.009.004-0-g2b5a88bb
UHD and USRP Manual
convert.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2011-2012,2014 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_CONVERT_HPP
19 #define INCLUDED_UHD_CONVERT_HPP
20 
21 #include <uhd/config.hpp>
22 #include <uhd/types/ref_vector.hpp>
23 #include <boost/shared_ptr.hpp>
24 #include <boost/function.hpp>
25 #include <boost/operators.hpp>
26 #include <string>
27 
28 namespace uhd{ namespace convert{
29 
31  class converter{
32  public:
33  typedef boost::shared_ptr<converter> sptr;
36 
37  virtual ~converter(void) = 0;
38 
40  virtual void set_scalar(const double) = 0;
41 
43  UHD_INLINE void conv(const input_type &in, const output_type &out, const size_t num){
44  if (num != 0) (*this)(in, out, num);
45  }
46 
47  private:
49  //
50  // This is the guts of the converter. When deriving new converter types,
51  // this is where the actual conversion routines go.
52  //
53  // \param in Pointers to the input buffers
54  // \param out Pointers to the output buffers
55  // \param num Number of items in the input buffers to convert
56  virtual void operator()(const input_type& in, const output_type& out, const size_t num) = 0;
57  };
58 
60  typedef boost::function<converter::sptr(void)> function_type;
61 
63  typedef int priority_type;
64 
66  struct UHD_API id_type : boost::equality_comparable<id_type>{
67  std::string input_format;
68  size_t num_inputs;
69  std::string output_format;
70  size_t num_outputs;
71  std::string to_pp_string(void) const;
72  std::string to_string(void) const;
73  };
74 
76  UHD_API bool operator==(const id_type &, const id_type &);
77 
88  const id_type &id,
89  const function_type &fcn,
90  const priority_type prio
91  );
92 
99  UHD_API function_type get_converter(
100  const id_type &id,
101  const priority_type prio = -1
102  );
103 
110  const std::string &format, const size_t size
111  );
112 
114  UHD_API size_t get_bytes_per_item(const std::string &format);
115 
116 }} //namespace
117 
118 #endif /* INCLUDED_UHD_CONVERT_HPP */
UHD_API function_type get_converter(const id_type &id, const priority_type prio=-1)
Identify a conversion routine in the registry.
Definition: convert.hpp:66
UHD_API void register_bytes_per_item(const std::string &format, const size_t size)
boost::function< converter::sptr(void)> function_type
Conversion factory function typedef.
Definition: convert.hpp:60
virtual void set_scalar(const double)=0
Set the scale factor (used in floating point conversions)
UHD_API size_t get_bytes_per_item(const std::string &format)
Convert an item format to a size in bytes.
uhd::ref_vector< const void * > input_type
Definition: convert.hpp:35
UHD_API bool operator==(const id_type &, const id_type &)
Implement equality_comparable interface.
A conversion class that implements a conversion from inputs -> outputs.
Definition: convert.hpp:31
std::string output_format
Definition: convert.hpp:69
Definition: convert.hpp:28
UHD_INLINE void conv(const input_type &in, const output_type &out, const size_t num)
The public conversion method to convert inputs -> outputs.
Definition: convert.hpp:43
Definition: ref_vector.hpp:31
#define UHD_INLINE
Definition: config.h:56
int priority_type
Priority of conversion routines.
Definition: convert.hpp:63
virtual ~converter(void)=0
#define UHD_API
Definition: config.h:66
size_t num_inputs
Definition: convert.hpp:68
UHD_API void register_converter(const id_type &id, const function_type &fcn, const priority_type prio)
uhd::ref_vector< void * > output_type
Definition: convert.hpp:34
size_t num_outputs
Definition: convert.hpp:70
boost::shared_ptr< converter > sptr
Definition: convert.hpp:33
std::string input_format
Definition: convert.hpp:67