SoapySDR  0.8.0-gab626068
Vendor and platform neutral SDR interface library
Types.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 #include <SoapySDR/Config.hpp>
13 #include <SoapySDR/Types.h>
14 #include <type_traits>
15 #include <vector>
16 #include <string>
17 #include <map>
18 
19 namespace SoapySDR
20 {
21 
23 typedef std::map<std::string, std::string> Kwargs;
24 
29 SOAPY_SDR_API Kwargs KwargsFromString(const std::string &markup);
30 
35 SOAPY_SDR_API std::string KwargsToString(const Kwargs &args);
36 
38 typedef std::vector<Kwargs> KwargsList;
39 
47 template <typename Type>
48 Type StringToSetting(const std::string &s);
49 
57 template <typename Type>
58 std::string SettingToString(const Type &s);
59 
64 {
65 public:
66 
68  Range(void);
69 
71  Range(const double minimum, const double maximum, const double step=0.0);
72 
74  double minimum(void) const;
75 
77  double maximum(void) const;
78 
80  double step(void) const;
81 
82 private:
83  double _min, _max, _step;
84 };
85 
91 typedef std::vector<Range> RangeList;
92 
97 {
98 public:
99 
101  ArgInfo(void);
102 
104  std::string key;
105 
111  std::string value;
112 
114  std::string name;
115 
117  std::string description;
118 
120  std::string units;
121 
123  enum Type {BOOL, INT, FLOAT, STRING} type;
124 
131 
136  std::vector<std::string> options;
137 
142  std::vector<std::string> optionNames;
143 };
144 
148 typedef std::vector<ArgInfo> ArgInfoList;
149 
150 }
151 
152 inline double SoapySDR::Range::minimum(void) const
153 {
154  return _min;
155 }
156 
157 inline double SoapySDR::Range::maximum(void) const
158 {
159  return _max;
160 }
161 
162 inline double SoapySDR::Range::step(void) const
163 {
164  return _step;
165 }
166 
167 namespace SoapySDR {
168 namespace Detail {
169 
170 
171 //private implementation details for settings converters
172 
173 template <typename Type>
174 typename std::enable_if<std::is_same<Type, bool>::value, Type>::type StringToSetting(const std::string &s)
175 {
176  if (s == SOAPY_SDR_TRUE) return true;
177  if (s == SOAPY_SDR_FALSE) return false;
178 
179  //zeros and empty strings are false
180  if (s == "0") return false;
181  if (s == "0.0") return false;
182  if (s == "") return false;
183 
184  //other values are true
185  return "true";
186 }
187 
188 template <typename Type>
189 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)
190 {
191  return Type(std::stoll(s));
192 }
193 
194 template <typename Type>
195 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)
196 {
197  return Type(std::stoull(s));
198 }
199 
200 template <typename Type>
201 typename std::enable_if<std::is_floating_point<Type>::value, Type>::type StringToSetting(const std::string &s)
202 {
203  return Type(std::stod(s));
204 }
205 
206 template <typename Type>
207 typename std::enable_if<std::is_same<typename std::decay<Type>::type, std::string>::value, Type>::type StringToSetting(const std::string &s)
208 {
209  return s;
210 }
211 
212 inline std::string SettingToString(const bool &s)
213 {
215 }
216 
217 inline std::string SettingToString(const char *s)
218 {
219  return s;
220 }
221 
222 inline std::string SettingToString(const std::string &s)
223 {
224  return s;
225 }
226 
227 template <typename Type>
228 std::string SettingToString(const Type &s)
229 {
230  return std::to_string(s);
231 }
232 
233 }}
234 
235 template <typename Type>
236 Type SoapySDR::StringToSetting(const std::string &s)
237 {
238  return SoapySDR::Detail::StringToSetting<Type>(s);
239 }
240 
241 template <typename Type>
242 std::string SoapySDR::SettingToString(const Type &s)
243 {
245 }
SOAPY_SDR_API
#define SOAPY_SDR_API
Definition: Config.h:41
SoapySDR::ArgInfo::Type
Type
The data type of the argument (required)
Definition: Types.hpp:123
SOAPY_SDR_FALSE
#define SOAPY_SDR_FALSE
String definition for boolean false used in settings.
Definition: Types.h:23
SoapySDR::Range
Definition: Types.hpp:63
Types.h
SoapySDR::SettingToString
std::string SettingToString(const Type &s)
Definition: Types.hpp:242
SOAPY_SDR_TRUE
#define SOAPY_SDR_TRUE
String definition for boolean true used in settings.
Definition: Types.h:20
SoapySDR::Detail::StringToSetting
std::enable_if< std::is_same< Type, bool >::value, Type >::type StringToSetting(const std::string &s)
Definition: Types.hpp:174
SoapySDR::Range::step
double step(void) const
Get the range step size.
Definition: Types.hpp:162
SoapySDR::Range::maximum
double maximum(void) const
Get the range maximum.
Definition: Types.hpp:157
SoapySDR::Range::minimum
double minimum(void) const
Get the range minimum.
Definition: Types.hpp:152
SoapySDR::RangeList
std::vector< Range > RangeList
Definition: Types.hpp:91
SoapySDR::ArgInfo::key
std::string key
The key used to identify the argument (required)
Definition: Types.hpp:104
SoapySDR
Definition: ConverterPrimitives.hpp:14
SoapySDR::ArgInfoList
std::vector< ArgInfo > ArgInfoList
Definition: Types.hpp:148
SoapySDR::Detail::SettingToString
std::string SettingToString(const bool &s)
Definition: Types.hpp:212
Config.hpp
SoapySDR::KwargsFromString
SOAPY_SDR_API Kwargs KwargsFromString(const std::string &markup)
SoapySDR::StringToSetting
Type StringToSetting(const std::string &s)
Definition: Types.hpp:236
SoapySDR::Kwargs
std::map< std::string, std::string > Kwargs
Typedef for a dictionary of key-value string arguments.
Definition: Types.hpp:23
SoapySDR::ArgInfo::options
std::vector< std::string > options
Definition: Types.hpp:136
SoapySDR::ArgInfo::description
std::string description
A brief description about the argument (optional)
Definition: Types.hpp:117
SoapySDR::KwargsList
std::vector< Kwargs > KwargsList
Typedef for a list of key-word dictionaries.
Definition: Types.hpp:38
SoapySDR::ArgInfo
Definition: Types.hpp:96
SoapySDR::KwargsToString
SOAPY_SDR_API std::string KwargsToString(const Kwargs &args)
SoapySDR::ArgInfo::optionNames
std::vector< std::string > optionNames
Definition: Types.hpp:142
SoapySDR::ArgInfo::value
std::string value
Definition: Types.hpp:111
SoapySDR::ArgInfo::range
Range range
Definition: Types.hpp:130
SoapySDR::ArgInfo::units
std::string units
The units of the argument: dB, Hz, etc (optional)
Definition: Types.hpp:120
SoapySDR::ArgInfo::name
std::string name
The displayable name of the argument (optional, use key if empty)
Definition: Types.hpp:114