20 #ifndef ESSENTIA_PARAMETER_H
21 #define ESSENTIA_PARAMETER_H
70 std::vector<Parameter*>
_vec;
71 std::map<std::string, Parameter*>
_map;
81 #define SPECIALIZE_CTOR(valueType, paramType, mName) \
82 Parameter (const valueType& x) : _type(paramType), _##mName(x), _configured(true) {}
92 Parameter(
const char* x) : _type(STRING), _str(x), _configured(true) {}
95 #define SPECIALIZE_VECTOR_CTOR(valueType, paramType) \
96 Parameter(const std::vector<valueType>& v) : _type(paramType), _configured(true) {\
97 _vec.resize(v.size()); \
98 for (int i=0; i<int(v.size()); ++i) { _vec[i] = new Parameter(v[i]); } \
112 #define SPECIALIZE_MAP_CTOR(valueType, paramType) \
113 Parameter(const std::map<std::string, valueType>& m) : _type(paramType), _configured(true) { \
114 for (std::map<std::string, valueType>::const_iterator i = m.begin(); \
116 ++i) { _map[(*i).first] = new Parameter((*i).second); } \
125 #define SPECIALIZE_MATRIX_CTOR(valueType, innerType) \
126 Parameter(const TNT::Array2D<valueType>& mat) : _type(MATRIX_##innerType), _configured(true) { \
127 _vec.resize(mat.dim1()); \
128 for (int i=0; i<mat.dim1(); ++i) { \
129 _vec[i] = new Parameter(VECTOR_##innerType); \
130 _vec[i]->_configured = true; \
131 _vec[i]->_vec.resize(mat.dim2()); \
132 for (int j=0; j<mat.dim2(); ++j) { \
133 _vec[i]->_vec[j] = new Parameter(mat[i][j]); \
161 #define TO(fname, valueType, paramType, mName) \
162 valueType to##fname() const { \
164 throw EssentiaException("Parameter: parameter has not been configured yet (ParamType=", _type, ")"); \
165 if (_type != paramType) \
166 throw EssentiaException("Parameter: parameter is not a " #valueType ", it is a ", _type); \
168 return (valueType)_##mName; \
171 TO(Bool,
bool, BOOL,
boolean)
172 TO(Double,
double, REAL, real)
173 TO(Float,
float, REAL, real)
178 throw EssentiaException(
"Parameter: parameter has not been configured yet (ParamType=", _type,
")");
179 if (_type != INT && _type != REAL)
180 throw EssentiaException(
"Parameter: parameter is not an int nor a Real, it is a ", _type);
188 throw EssentiaException(
"Parameter: parameter has not been configured yet (ParamType=", _type,
")");
189 if (_type != INT && _type != REAL)
190 throw EssentiaException(
"Parameter: parameter is not an int nor a Real, it is a ", _type);
195 #define TOVECTOR(fname, valueType, paramType) \
196 std::vector<valueType > toVector##fname() const { \
198 throw EssentiaException("Parameter: parameter has not been configured yet (ParamType=", _type, ")"); \
199 if (_type != paramType) \
200 throw EssentiaException("Parameter: parameter is not of type: ", paramType); \
202 std::vector<valueType > result(_vec.size()); \
203 for (int i=0; i<(int)_vec.size(); ++i) { \
204 result[i] = _vec[i]->to##fname(); \
215 TOVECTOR(VectorString, std::vector<std::
string>, VECTOR_VECTOR_STRING)
220 #define TOMAP(fname, valueType, paramType) \
221 std::map<std::string, valueType > toMap##fname() const { \
223 throw EssentiaException("Parameter: parameter has not been configured yet (ParamType=", _type, ")"); \
224 if (_type != paramType) \
225 throw EssentiaException("Parameter: parameter is not of type: ", paramType); \
227 std::map<std::string, valueType > result; \
229 for (std::map<std::string, Parameter*>::const_iterator i = _map.begin(); \
232 result[i->first] = i->second->to##fname(); \
238 TOMAP(VectorReal, std::vector<Real>, MAP_VECTOR_REAL)
239 TOMAP(VectorString, std::vector<std::
string>, MAP_VECTOR_STRING)
240 TOMAP(VectorInt, std::vector<
int>, MAP_VECTOR_INT)
247 #define TOMATRIX(fname, valueType, paramType) \
248 TNT::Array2D<valueType> toMatrix##fname() const { \
250 throw EssentiaException("Parameter: parameter has not been configured yet (ParamType=", _type, ")");\
251 if (_type != paramType) \
252 throw EssentiaException("Parameter: parameter is not of type: ", paramType);\
253 TNT::Array2D<valueType> result(_vec.size(), _vec[0]->_vec.size()); \
255 for (int i=0; i<result.dim1(); ++i) { \
256 for (int j=0; j<result.dim2(); ++j) { \
257 result[i][j] = _vec[i]->_vec[j]->to##fname(); \
Definition: parameter.h:276
const Parameter & operator[](const std::string &key) const
EssentiaMap< std::string, Parameter, string_cmp > ParameterMapBase
Definition: parameter.h:279
void add(const std::string &name, const Parameter &value)
Parameter & operator[](const std::string &key)
Definition: parameter.h:30
Parameter(ParamType tp)
Definition: parameter.h:78
bool _boolean
Definition: parameter.h:69
std::vector< Parameter * > _vec
Definition: parameter.h:70
ParamType _type
Definition: parameter.h:65
ParamType
Definition: parameter.h:34
@ REAL
Definition: parameter.h:37
@ MAP_VECTOR_REAL
Definition: parameter.h:55
@ STEREOSAMPLE
Definition: parameter.h:41
@ VECTOR_BOOL
Definition: parameter.h:45
@ VECTOR_VECTOR_STEREOSAMPLE
Definition: parameter.h:51
@ MAP_VECTOR_STRING
Definition: parameter.h:56
@ UNDEFINED
Definition: parameter.h:35
@ VECTOR_STEREOSAMPLE
Definition: parameter.h:47
@ VECTOR_VECTOR_REAL
Definition: parameter.h:49
@ VECTOR_VECTOR_STRING
Definition: parameter.h:50
@ MAP_VECTOR_INT
Definition: parameter.h:57
@ VECTOR_REAL
Definition: parameter.h:43
@ VECTOR_INT
Definition: parameter.h:46
@ MAP_REAL
Definition: parameter.h:58
@ VECTOR_MATRIX_REAL
Definition: parameter.h:53
@ BOOL
Definition: parameter.h:39
@ STRING
Definition: parameter.h:38
@ VECTOR_STRING
Definition: parameter.h:44
@ INT
Definition: parameter.h:40
std::string _str
Definition: parameter.h:67
std::map< std::string, Parameter * > _map
Definition: parameter.h:71
StereoSample _ssamp
Definition: parameter.h:72
std::string toLower() const
std::string toString(int precision=12) const
Parameter(const char *x)
Definition: parameter.h:92
Real toReal() const
Definition: parameter.h:186
bool isConfigured() const
Definition: parameter.h:154
Real _real
Definition: parameter.h:68
bool _configured
Definition: parameter.h:73
Definition: tnt_array1d.h:36
Definition: algorithm.h:28
std::ostream & operator<<(std::ostream &out, const Parameter &p)
float Real
Definition: types.h:69
#define TOVECTOR(fname, valueType, paramType)
Definition: parameter.h:195
#define SPECIALIZE_MATRIX_CTOR(valueType, innerType)
Definition: parameter.h:125
#define SPECIALIZE_CTOR(valueType, paramType, mName)
Definition: parameter.h:81
#define TOMAP(fname, valueType, paramType)
Definition: parameter.h:220
#define TO(fname, valueType, paramType, mName)
Definition: parameter.h:161
#define SPECIALIZE_MAP_CTOR(valueType, paramType)
Definition: parameter.h:112
#define TOMATRIX(fname, valueType, paramType)
Definition: parameter.h:247
#define SPECIALIZE_VECTOR_CTOR(valueType, paramType)
Definition: parameter.h:95
unsigned int uint
Definition: types.h:49