USRP Hardware Driver and Device Manual  Version: 4.11.0.0-0-g0d7ed3b1
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 #pragma once
9 
10 #include <uhd/config.hpp>
11 #include <uhd/types/ref_vector.hpp>
12 #include <boost/operators.hpp>
13 #include <cstddef>
14 #include <functional>
15 #include <memory>
16 #include <string>
17 
18 namespace uhd { namespace convert {
19 
21 class converter
22 {
23 public:
24  typedef std::shared_ptr<converter> sptr;
27 
28  virtual ~converter(void) = 0;
29 
31  virtual void set_scalar(const double) = 0;
32 
34  UHD_INLINE void conv(const input_type& in, const output_type& out, const size_t num)
35  {
36  if (num != 0)
37  (*this)(in, out, num);
38  }
39 
40 private:
50  virtual void operator()(
51  const input_type& in, const output_type& out, const size_t num) = 0;
52 };
53 
55 typedef std::function<converter::sptr(void)> function_type;
56 
58 typedef int priority_type;
59 
61 struct UHD_API id_type : boost::equality_comparable<id_type>
62 {
63  std::string input_format;
64  size_t num_inputs;
65  std::string output_format;
66  size_t num_outputs;
67  std::string to_pp_string(void) const;
68  std::string to_string(void) const;
69 };
70 
72 UHD_API bool operator==(const id_type&, const id_type&);
73 
84  const id_type& id, const function_type& fcn, const priority_type prio);
85 
93 
99 UHD_API void register_bytes_per_item(const std::string& format, const size_t size);
100 
102 UHD_API size_t get_bytes_per_item(const std::string& format);
103 }} // namespace uhd::convert
A conversion class that implements a conversion from inputs -> outputs.
Definition: convert.hpp:22
uhd::ref_vector< void * > output_type
Definition: convert.hpp:25
uhd::ref_vector< const void * > input_type
Definition: convert.hpp:26
virtual void set_scalar(const double)=0
Set the scale factor (used in floating point conversions)
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:34
std::shared_ptr< converter > sptr
Definition: convert.hpp:24
virtual ~converter(void)=0
Definition: ref_vector.hpp:22
#define UHD_INLINE
Definition: config.h:65
#define UHD_API
Definition: config.h:87
std::function< converter::sptr(void)> function_type
Conversion factory function typedef.
Definition: convert.hpp:55
UHD_API void register_converter(const id_type &id, const function_type &fcn, const priority_type prio)
int priority_type
Priority of conversion routines.
Definition: convert.hpp:58
UHD_API void register_bytes_per_item(const std::string &format, const size_t size)
UHD_API function_type get_converter(const id_type &id, const priority_type prio=-1)
UHD_API bool operator==(const id_type &, const id_type &)
Implement equality_comparable interface.
UHD_API size_t get_bytes_per_item(const std::string &format)
Convert an item format to a size in bytes.
Definition: build_info.hpp:12
Identify a conversion routine in the registry.
Definition: convert.hpp:62
std::string input_format
Definition: convert.hpp:63
std::string output_format
Definition: convert.hpp:65
size_t num_inputs
Definition: convert.hpp:64
std::string to_pp_string(void) const
std::string to_string(void) const
size_t num_outputs
Definition: convert.hpp:66