Loading...
Searching...
No Matches
Types.hpp
Go to the documentation of this file.
#pragma once
#include <SoapySDR/Config.hpp>
#include <SoapySDR/Types.h>
#include <type_traits>
#include <vector>
#include <stdexcept>
#include <string>
#include <map>
namespace SoapySDR
{
typedef std::map<std::string, std::string> Kwargs;
SOAPY_SDR_API Kwargs KwargsFromString(const std::string &markup);
SOAPY_SDR_API std::string KwargsToString(const Kwargs &args);
typedef std::vector<Kwargs> KwargsList;
template <typename Type>
Type StringToSetting(const std::string &s);
template <typename Type>
std::string SettingToString(const Type &s);
class SOAPY_SDR_API Range
{
public:
Range(void);
Range(const double minimum, const double maximum, const double step=0.0);
double minimum(void) const;
double maximum(void) const;
double step(void) const;
private:
double _min, _max, _step;
};
typedef std::vector<Range> RangeList;
class SOAPY_SDR_API ArgInfo
{
public:
ArgInfo(void);
std::string key;
std::string value;
std::string name;
std::string description;
std::string units;
enum Type {BOOL, INT, FLOAT, STRING} type;
Range range;
std::vector<std::string> options;
std::vector<std::string> optionNames;
};
typedef std::vector<ArgInfo> ArgInfoList;
}
inline double SoapySDR::Range::minimum(void) const
{
return _min;
}
inline double SoapySDR::Range::maximum(void) const
{
return _max;
}
inline double SoapySDR::Range::step(void) const
{
return _step;
}
namespace SoapySDR {
namespace Detail {
//private implementation details for settings converters
template <typename Type>
typename std::enable_if<std::is_same<Type, bool>::value, Type>::type StringToSetting(const std::string &s)
{
if (s.empty() or s == SOAPY_SDR_FALSE) {
return false;
}
if (s == SOAPY_SDR_TRUE) {
return true;
}
try {
// C++: Float conversion to bool is unambiguous
return std::stod(s);
} catch (std::invalid_argument&) {
}
// other values are true
return true;
}
template <typename Type>
typename std::enable_if<not std::is_same<Type, bool>::value and std::is_integral<Type>::value and std::is_signed<Type>::value, Type>::type StringToSetting(const std::string &s)
{
return Type(std::stoll(s));
}
template <typename Type>
typename std::enable_if<not std::is_same<Type, bool>::value and std::is_integral<Type>::value and std::is_unsigned<Type>::value, Type>::type StringToSetting(const std::string &s)
{
return Type(std::stoull(s));
}
template <typename Type>
typename std::enable_if<std::is_floating_point<Type>::value, Type>::type StringToSetting(const std::string &s)
{
return Type(std::stod(s));
}
template <typename Type>
typename std::enable_if<std::is_same<typename std::decay<Type>::type, std::string>::value, Type>::type StringToSetting(const std::string &s)
{
return s;
}
inline std::string SettingToString(const bool &s)
{
return s?SOAPY_SDR_TRUE:SOAPY_SDR_FALSE;
}
inline std::string SettingToString(const char *s)
{
return s;
}
inline std::string SettingToString(const std::string &s)
{
return s;
}
template <typename Type>
std::string SettingToString(const Type &s)
{
return std::to_string(s);
}
}}
template <typename Type>
Type SoapySDR::StringToSetting(const std::string &s)
{
return SoapySDR::Detail::StringToSetting<Type>(s);
}
template <typename Type>
std::string SoapySDR::SettingToString(const Type &s)
{
return SoapySDR::Detail::SettingToString(s);
}
SOAPY_SDR_API
#define SOAPY_SDR_API
Definition Config.h:41
Config.hpp
Types.h
SOAPY_SDR_FALSE
#define SOAPY_SDR_FALSE
String definition for boolean false used in settings.
Definition Types.h:23
SOAPY_SDR_TRUE
#define SOAPY_SDR_TRUE
String definition for boolean true used in settings.
Definition Types.h:20
SoapySDR::ArgInfo::ArgInfo
ArgInfo(void)
Default constructor.
SoapySDR::ArgInfo::units
std::string units
The units of the argument: dB, Hz, etc (optional).
Definition Types.hpp:121
SoapySDR::ArgInfo::range
Range range
Definition Types.hpp:131
SoapySDR::ArgInfo::options
std::vector< std::string > options
Definition Types.hpp:137
SoapySDR::ArgInfo::description
std::string description
A brief description about the argument (optional).
Definition Types.hpp:118
SoapySDR::ArgInfo::optionNames
std::vector< std::string > optionNames
Definition Types.hpp:143
SoapySDR::ArgInfo::value
std::string value
Definition Types.hpp:112
SoapySDR::ArgInfo::name
std::string name
The displayable name of the argument (optional, use key if empty).
Definition Types.hpp:115
SoapySDR::ArgInfo::key
std::string key
The key used to identify the argument (required).
Definition Types.hpp:105
SoapySDR::ArgInfo::Type
Type
The data type of the argument (required).
Definition Types.hpp:124
SoapySDR::ArgInfo::INT
@ INT
Definition Types.hpp:124
SoapySDR::ArgInfo::BOOL
@ BOOL
Definition Types.hpp:124
SoapySDR::ArgInfo::FLOAT
@ FLOAT
Definition Types.hpp:124
SoapySDR::ArgInfo::STRING
@ STRING
Definition Types.hpp:124
SoapySDR::Range
Definition Types.hpp:65
SoapySDR::Range::maximum
double maximum(void) const
Get the range maximum.
Definition Types.hpp:158
SoapySDR::Range::Range
Range(const double minimum, const double maximum, const double step=0.0)
Create a min/max range.
SoapySDR::Range::minimum
double minimum(void) const
Get the range minimum.
Definition Types.hpp:153
SoapySDR::Range::step
double step(void) const
Get the range step size.
Definition Types.hpp:163
SoapySDR::Range::Range
Range(void)
Create an empty range (0.0, 0.0).
SoapySDR::Detail
Definition Types.hpp:169
SoapySDR::Detail::StringToSetting
std::enable_if< std::is_same< Type, bool >::value, Type >::type StringToSetting(const std::string &s)
Definition Types.hpp:175
SoapySDR::Detail::SettingToString
std::string SettingToString(const bool &s)
Definition Types.hpp:216
SoapySDR
Definition ConverterPrimitives.hpp:15
SoapySDR::KwargsFromString
SOAPY_SDR_API Kwargs KwargsFromString(const std::string &markup)
SoapySDR::RangeList
std::vector< Range > RangeList
Definition Types.hpp:92
SoapySDR::ArgInfoList
std::vector< ArgInfo > ArgInfoList
Definition Types.hpp:149
SoapySDR::StringToSetting
Type StringToSetting(const std::string &s)
Definition Types.hpp:240
SoapySDR::KwargsToString
SOAPY_SDR_API std::string KwargsToString(const Kwargs &args)
SoapySDR::Kwargs
std::map< std::string, std::string > Kwargs
Typedef for a dictionary of key-value string arguments.
Definition Types.hpp:24
SoapySDR::KwargsList
std::vector< Kwargs > KwargsList
Typedef for a list of key-word dictionaries.
Definition Types.hpp:39
SoapySDR::SettingToString
std::string SettingToString(const Type &s)
Definition Types.hpp:246