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