1 #ifndef _BLOCK_PARAM__valueHEADER_
2 #define _BLOCK_PARAM__valueHEADER_
6 #pragma warning(disable:4996 4251 4275 4800 4503 4190)
8 #include <boost/variant.hpp>
9 #include <opencv2/core/core.hpp>
10 #include <boost/thread/recursive_mutex.hpp>
11 #include <boost/thread/condition_variable.hpp>
26 struct ParamDefinition;
30 Boolean = 0, Int, Float, Color, Matrix, String, FilePath, ListBox, AnyType, typeError
42 typedef boost::variant <
56 mutable boost::recursive_mutex _mtx;
57 boost::condition_variable _cond_sync;
58 mutable bool _newValue;
59 std::vector<ParamValidator*> _validators;
60 std::set<ParamValue*> _distantListeners;
67 VariantClasses _value;
69 void notifyUpdate(
bool isNew);
73 _block(algo), _name(name), _isOutput(isOutput), _value(
Not_A_Value()){
74 _newValue =
false; _paramNeeded =
true; _definition = NULL;
77 _block(NULL), _name(
""), _isOutput(
false), _value(
Not_A_Value()){
78 _newValue =
false; _paramNeeded =
true; _definition = NULL;
105 if (v != NULL) v->_distantListeners.insert(
this);
108 _block(va._block), _name(va._name), _isOutput(va._isOutput), _value(va._value),
109 _validators(va._validators), _distantListeners(va._distantListeners){
110 _newValue =
false; _paramNeeded =
true; _definition = va._definition;
115 const std::set<ParamValue*>& getListeners()
const {
return _distantListeners; };
116 std::set<ParamValue*>& getListeners() {
return _distantListeners; };
118 static ParamValue fromString(ParamType,std::string);
124 ParamValue& operator=(std::string
const &rhs);
135 return this->operator==(b) || this->operator<(b);
139 return this->operator==(b) || this->operator>(b);
143 return !(this->operator==(b));
149 bool isNeeded(){
return _paramNeeded; };
150 void isNeeded(
bool paramNeeded){ _paramNeeded = paramNeeded; };
152 std::string toString()
const;
156 void addValidator(std::initializer_list<ParamValidator*> list);
158 bool containValidator()
const
160 for (
auto& val : _validators)
162 if (dynamic_cast<T*>(val) != NULL)
168 std::string getName()
const {
return _name; };
170 void setName(std::string val) { _name = val; }
176 void setNew(
bool isNew){ _newValue = isNew; };
177 bool isDefaultValue()
const;
178 void setDefaultValue();
179 bool isLinked()
const {
180 boost::unique_lock<boost::recursive_mutex> lock(_mtx);
181 return (_value.type() ==
typeid(
ParamValue*)) &&
182 boost::get<ParamValue*>(_value) != NULL;
185 ParamType getType(
bool allow_AnyType =
true)
const;
186 Block * getBlock()
const {
return _block; };
187 void setBlock(
Block *b) { _block=b; };
189 std::string getValFromList();
194 boost::unique_lock<boost::recursive_mutex> lock(_mtx);
198 return boost::get<T>(_value);
199 return boost::get<ParamValue*>(_value)->get<T>();
207 return boost::get<T>(_value);
209 catch (boost::bad_get&)
218 boost::unique_lock<boost::recursive_mutex> lock(_mtx);
220 return boost::get<ParamValue*>(_value)->get<int>();
228 return boost::get<int>(_value);
230 catch (boost::bad_get&)
234 return static_cast<int>(boost::get<double>(_value));
236 catch (boost::bad_get&)
244 double get<double>()
const
246 boost::unique_lock<boost::recursive_mutex> lock(_mtx);
248 return boost::get<ParamValue*>(_value)->get<double>();
256 return boost::get<double>(_value);
258 catch (boost::bad_get&)
262 return static_cast<double>(boost::get<int>(_value));
264 catch (boost::bad_get&)
272 float get<float>()
const
274 return static_cast<float>(get<double>());
279 boost::unique_lock<boost::recursive_mutex> lock(_mtx);
282 if (value->isLinked())
284 switch (value->getType())
287 _value = value->get<
bool>();
290 _value = value->get<
int>();
293 _value = value->get<
double>();
297 _value = value->get<std::string>();
300 _value = value->get<cv::Scalar>();
303 _value = value->get<cv::Mat>();
306 notifyUpdate(_newValue);
311 Q_SIGNAL
void paramUpdated();
void update()
Update the value. This will render the corresponding block and every ancestors.
Definition: ParamValue.cpp:178
Definition: ParamValue.h:33
Definition: ParamValue.h:52