USRP Hardware Driver and USRP Manual  Version: 3.11.0.HEAD-0-gdca39145
UHD and USRP Manual
convert.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2011-2012,2014 Ettus Research LLC
3 //
4 // SPDX-License-Identifier: GPL-3.0
5 //
6 
7 #ifndef INCLUDED_UHD_CONVERT_HPP
8 #define INCLUDED_UHD_CONVERT_HPP
9 
10 #include <uhd/config.hpp>
11 #include <uhd/types/ref_vector.hpp>
12 #include <boost/shared_ptr.hpp>
13 #include <boost/function.hpp>
14 #include <boost/operators.hpp>
15 #include <string>
16 
17 namespace uhd{ namespace convert{
18 
20  class converter{
21  public:
22  typedef boost::shared_ptr<converter> sptr;
25 
26  virtual ~converter(void) = 0;
27 
29  virtual void set_scalar(const double) = 0;
30 
32  UHD_INLINE void conv(const input_type &in, const output_type &out, const size_t num){
33  if (num != 0) (*this)(in, out, num);
34  }
35 
36  private:
38  //
39  // This is the guts of the converter. When deriving new converter types,
40  // this is where the actual conversion routines go.
41  //
42  // \param in Pointers to the input buffers
43  // \param out Pointers to the output buffers
44  // \param num Number of items in the input buffers to convert
45  virtual void operator()(const input_type& in, const output_type& out, const size_t num) = 0;
46  };
47 
49  typedef boost::function<converter::sptr(void)> function_type;
50 
52  typedef int priority_type;
53 
55  struct UHD_API id_type : boost::equality_comparable<id_type>{
56  std::string input_format;
57  size_t num_inputs;
58  std::string output_format;
59  size_t num_outputs;
60  std::string to_pp_string(void) const;
61  std::string to_string(void) const;
62  };
63 
65  UHD_API bool operator==(const id_type &, const id_type &);
66 
77  const id_type &id,
78  const function_type &fcn,
79  const priority_type prio
80  );
81 
88  UHD_API function_type get_converter(
89  const id_type &id,
90  const priority_type prio = -1
91  );
92 
99  const std::string &format, const size_t size
100  );
101 
103  UHD_API size_t get_bytes_per_item(const std::string &format);
104 
105 }} //namespace
106 
107 #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:55
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:49
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:24
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:20
std::string output_format
Definition: convert.hpp:58
Definition: build_info.hpp:14
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:32
Definition: ref_vector.hpp:20
#define UHD_INLINE
Definition: config.h:52
int priority_type
Priority of conversion routines.
Definition: convert.hpp:52
virtual ~converter(void)=0
#define UHD_API
Definition: config.h:62
size_t num_inputs
Definition: convert.hpp:57
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:23
size_t num_outputs
Definition: convert.hpp:59
boost::shared_ptr< converter > sptr
Definition: convert.hpp:22
std::string input_format
Definition: convert.hpp:56