Loading...
Searching...
No Matches
convert.hpp
Go to the documentation of this file.
//
// Copyright 2011-2012,2014 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/config.hpp>
#include <uhd/types/ref_vector.hpp>
#include <boost/operators.hpp>
#include <cstddef>
#include <functional>
#include <memory>
#include <string>
namespace uhd { namespace convert {
class converter
{
public:
typedef std::shared_ptr<converter> sptr;
typedef uhd::ref_vector<void*> output_type;
typedef uhd::ref_vector<const void*> input_type;
virtual ~converter(void) = 0;
virtual void set_scalar(const double) = 0;
UHD_INLINE void conv(const input_type& in, const output_type& out, const size_t num)
{
if (num != 0)
(*this)(in, out, num);
}
private:
//
// This is the guts of the converter. When deriving new converter types,
// this is where the actual conversion routines go.
//
// \param in Pointers to the input buffers
// \param out Pointers to the output buffers
// \param num Number of items in the input buffers to convert
virtual void operator()(
const input_type& in, const output_type& out, const size_t num) = 0;
};
typedef std::function<converter::sptr(void)> function_type;
typedef int priority_type;
struct UHD_API id_type : boost::equality_comparable<id_type>
{
std::string input_format;
size_t num_inputs;
std::string output_format;
size_t num_outputs;
std::string to_pp_string(void) const;
std::string to_string(void) const;
};
UHD_API bool operator==(const id_type&, const id_type&);
UHD_API void register_converter(
const id_type& id, const function_type& fcn, const priority_type prio);
UHD_API function_type get_converter(const id_type& id, const priority_type prio = -1);
UHD_API void register_bytes_per_item(const std::string& format, const size_t size);
UHD_API size_t get_bytes_per_item(const std::string& format);
}} // namespace uhd::convert
uhd::convert::converter
A conversion class that implements a conversion from inputs -> outputs.
Definition convert.hpp:22
uhd::convert::converter::output_type
uhd::ref_vector< void * > output_type
Definition convert.hpp:25
uhd::convert::converter::input_type
uhd::ref_vector< const void * > input_type
Definition convert.hpp:26
uhd::convert::converter::set_scalar
virtual void set_scalar(const double)=0
Set the scale factor (used in floating point conversions).
uhd::convert::converter::conv
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
uhd::convert::converter::sptr
std::shared_ptr< converter > sptr
Definition convert.hpp:24
uhd::convert::converter::~converter
virtual ~converter(void)=0
uhd::ref_vector
Definition ref_vector.hpp:22
UHD_INLINE
#define UHD_INLINE
Definition config.h:65
UHD_API
#define UHD_API
Definition config.h:87
config.hpp
uhd::convert
Definition convert.hpp:18
uhd::convert::function_type
std::function< converter::sptr(void)> function_type
Conversion factory function typedef.
Definition convert.hpp:54
uhd::convert::register_converter
UHD_API void register_converter(const id_type &id, const function_type &fcn, const priority_type prio)
uhd::convert::priority_type
int priority_type
Priority of conversion routines.
Definition convert.hpp:57
uhd::convert::register_bytes_per_item
UHD_API void register_bytes_per_item(const std::string &format, const size_t size)
uhd::convert::get_converter
UHD_API function_type get_converter(const id_type &id, const priority_type prio=-1)
uhd::convert::operator==
UHD_API bool operator==(const id_type &, const id_type &)
Implement equality_comparable interface.
uhd::convert::get_bytes_per_item
UHD_API size_t get_bytes_per_item(const std::string &format)
Convert an item format to a size in bytes.
uhd
Definition build_info.hpp:12
ref_vector.hpp
uhd::convert::id_type
Identify a conversion routine in the registry.
Definition convert.hpp:61
uhd::convert::id_type::input_format
std::string input_format
Definition convert.hpp:62
uhd::convert::id_type::output_format
std::string output_format
Definition convert.hpp:64
uhd::convert::id_type::num_inputs
size_t num_inputs
Definition convert.hpp:63
uhd::convert::id_type::to_pp_string
std::string to_pp_string(void) const
uhd::convert::id_type::to_string
std::string to_string(void) const
uhd::convert::id_type::num_outputs
size_t num_outputs
Definition convert.hpp:65