1 #include "visiontransfer/parameterinfo.h"
2 #include "visiontransfer/exceptions.h"
4 namespace visiontransfer {
6 class ParameterInfo::Pimpl {
8 Pimpl(): type(ParameterInfo::TYPE_INT), value({0}), min({0}), max({0}), inc({0}) { }
9 template<
typename T>
void set(
const std::string& name,
bool writeable,
10 T value, T min, T max, T inc);
11 inline std::string
getName()
const {
return name; }
12 inline ParameterType
getType()
const {
return type; }
13 inline bool isWriteable()
const {
return writeable; }
14 template<
typename T> T getTypedValue(
const ParameterValue& val)
const;
15 template<
typename T> T
getValue()
const {
return getTypedValue<T>(value); }
16 template<
typename T> T
getMin()
const {
return getTypedValue<T>(min); }
17 template<
typename T> T
getMax()
const {
return getTypedValue<T>(max); }
18 template<
typename T> T
getInc()
const {
return getTypedValue<T>(inc); }
31 ParameterInfo::ParameterInfo()
33 pimpl =
new ParameterInfo::Pimpl();
36 template<>
void ParameterInfo::Pimpl::set(
const std::string& name,
bool writeable,
int value,
int min,
int max,
int inc)
39 this->type = ParameterInfo::TYPE_INT;
40 this->writeable = writeable;
41 this->value.intVal = value;
42 this->min.intVal = min;
43 this->max.intVal = max;
44 this->inc.intVal = inc;
46 template<>
void ParameterInfo::Pimpl::set(
const std::string& name,
bool writeable,
double value,
double min,
double max,
double inc)
49 this->type = ParameterInfo::TYPE_DOUBLE;
50 this->writeable = writeable;
51 this->value.doubleVal = value;
52 this->min.doubleVal = min;
53 this->max.doubleVal = max;
54 this->inc.doubleVal = inc;
56 template<>
void ParameterInfo::Pimpl::set(
const std::string& name,
bool writeable,
bool value,
bool min,
bool max,
bool inc)
59 this->type = ParameterInfo::TYPE_BOOL;
60 this->writeable = writeable;
61 this->value.boolVal = value;
62 this->min.boolVal = min;
63 this->max.boolVal = max;
64 this->inc.boolVal = inc;
67 ParameterInfo ParameterInfo::fromInt(
const std::string& name,
bool writeable,
68 int value,
int min,
int max,
int inc) {
70 pi.pimpl->set<
int>(name, writeable, value, min, max, inc);
74 ParameterInfo ParameterInfo::fromDouble(
const std::string& name,
bool writeable,
75 double value,
double min,
double max,
double inc) {
77 pi.pimpl->set<
double>(name, writeable, value, min, max, inc);
81 ParameterInfo ParameterInfo::fromBool(
const std::string& name,
bool writeable,
bool value) {
83 pi.pimpl->set<
bool>(name, writeable, value, 0, 1, 1);
87 #ifndef DOXYGEN_SHOULD_SKIP_THIS
88 template<>
int ParameterInfo::Pimpl::getTypedValue(
const ParameterInfo::ParameterValue& val)
const {
90 case ParameterInfo::TYPE_INT: {
93 case ParameterInfo::TYPE_BOOL: {
94 return (
int) val.boolVal;
96 case ParameterInfo::TYPE_DOUBLE: {
97 return (
int) val.doubleVal;
100 throw ParameterException(
"Unexpected parameter type");
103 template<>
double ParameterInfo::Pimpl::getTypedValue(
const ParameterInfo::ParameterValue& val)
const {
105 case ParameterInfo::TYPE_DOUBLE: {
106 return val.doubleVal;
108 case ParameterInfo::TYPE_INT: {
109 return (
double) val.intVal;
111 case ParameterInfo::TYPE_BOOL: {
112 return val.boolVal?1.0:0.0;
115 throw ParameterException(
"Unexpected parameter type");
118 template<>
bool ParameterInfo::Pimpl::getTypedValue(
const ParameterInfo::ParameterValue& val)
const {
120 case ParameterInfo::TYPE_BOOL: {
123 case ParameterInfo::TYPE_DOUBLE: {
124 return val.doubleVal != 0.0;
126 case ParameterInfo::TYPE_INT: {
127 return val.intVal != 0;
130 throw ParameterException(
"Unexpected parameter type");
132 #endif // DOXYGEN_SHOULD_SKIP_THIS
138 #ifndef DOXYGEN_SHOULD_SKIP_THIS
151 #endif // DOXYGEN_SHOULD_SKIP_THIS