19 #ifndef _ABSTRACTPROPERTYTYPE_H_
20 #define _ABSTRACTPROPERTYTYPE_H_
28 #include <boost/any.hpp>
29 #include <boost/lexical_cast.hpp>
30 #include <boost/utility.hpp>
31 #include <type_traits>
34 #include "timestamp.h"
36 #include <boost/algorithm/string.hpp>
58 static const Zone::Type FrontRight;
59 static const Zone::Type FrontLeft;
60 static const Zone::Type MiddleRight;
61 static const Zone::Type MiddleLeft;
62 static const Zone::Type RearRight;
63 static const Zone::Type RearLeft;
65 typedef std::list<Zone::Type> ZoneList;
104 virtual std::string
toString()
const = 0;
209 template <
typename T>
212 return boost::any_cast<T>(mValue);
227 std::vector<std::function<void(AbstractPropertyType*)>>
destroyed;
235 template <
typename T>
242 static const char* signature() {
return "i"; }
244 static int value(GVariant* v)
246 return g_variant_get_int32(v);
249 static std::string stringize(std::string v)
259 static const char* signature() {
return "d"; }
261 static double value(GVariant* v)
263 return g_variant_get_double(v);
265 static std::string stringize(std::string v)
275 static const char* signature() {
return "q"; }
277 static uint16_t value(GVariant* v)
279 return g_variant_get_uint16(v);
281 static std::string stringize(std::string v)
291 static const char* signature() {
return "n"; }
293 static int16_t value(GVariant* v)
295 return g_variant_get_int16(v);
297 static std::string stringize(std::string v)
307 static const char* signature() {
return "y"; }
309 static char value(GVariant* v)
311 return g_variant_get_byte(v);
313 static std::string stringize(std::string v)
323 static const char* signature() {
return "u"; }
325 static uint32_t value(GVariant* v)
327 return g_variant_get_uint32(v);
329 static std::string stringize(std::string v)
339 static const char* signature() {
return "x"; }
341 static int64_t value(GVariant* v)
343 return g_variant_get_int64(v);
345 static std::string stringize(std::string v)
355 static const char* signature() {
return "t"; }
357 static uint64_t value(GVariant* v)
359 return g_variant_get_uint64(v);
361 static std::string stringize(std::string v)
371 static const char* signature() {
return "b"; }
373 static bool value(GVariant *v)
375 return g_variant_get_boolean(v);
377 static std::string stringize(std::string v)
379 if(v ==
"0" || v ==
"1")
382 boost::algorithm::to_lower(v);
383 return v ==
"true" ?
"1":
"0";
394 template <
typename T>
405 setValue(other.
value<T>());
416 setValue(other.
value<T>());
442 bool operator < (const BasicPropertyType<T>& other)
const
444 return value<T>() < other.value<T>();
449 return value<T>() > other.
value<T>();
467 if(!val.empty() && val !=
"")
487 if(!val.empty() && val !=
"")
495 std::stringstream stream;
496 stream.precision(10);
504 return serializeVariant<T>(value<T>());
509 setValue(deserializeVariant<T>(v));
537 void serialize(std::string val,
typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
541 std::stringstream stream(val);
544 setValue((N)someTemp);
548 void serialize(std::string val,
typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
557 GVariant* serializeVariant(T val,
typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
561 return (g_variant_new(
"i",(
int)val));
565 GVariant* serializeVariant(T val,
typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
573 T deserializeVariant(GVariant* v,
typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
581 T deserializeVariant(GVariant* v,
typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
644 return value<std::string>();
651 return g_variant_new_string(
toString().c_str());
657 setValue(std::string(g_variant_get_string(v,NULL)));
675 appendPriv(value->
copy());
681 std::list<AbstractPropertyType*> l = other.list();
682 for(
auto itr = l.begin(); itr != l.end(); itr++)
707 for(
auto itr = mList.begin(); itr != mList.end(); itr++)
716 appendPriv(property->
copy());
731 std::string str =
"[";
733 for(
auto itr = mList.begin(); itr != mList.end(); itr++)
756 if(str[0] !=
'[' && str[str.length()-1] !=
']')
761 str = str.substr(1,str.length() - 2);
763 std::vector<std::string> elements;
765 std::istringstream f(str);
768 while(std::getline(f,element,
','))
779 GVariantBuilder params;
780 g_variant_builder_init(¶ms, ((
const GVariantType *)
"av"));
782 for(
auto itr = mList.begin(); itr != mList.end(); itr++)
786 GVariant *newvar = g_variant_new(
"v",var);
787 g_variant_builder_add_value(¶ms, newvar);
791 GVariant* var = g_variant_builder_end(¶ms);
802 gsize dictsize = g_variant_n_children(v);
803 for (
int i=0;i<dictsize;i++)
805 GVariant *childvariant = g_variant_get_child_value(v,i);
806 GVariant *innervariant = g_variant_get_variant(childvariant);
808 t->fromVariant(innervariant);
813 std::list<AbstractPropertyType*> list() {
return mList; }
819 for(
auto itr = mList.begin(); itr != mList.end(); itr++)
833 std::list<AbstractPropertyType*> mList;
virtual GVariant * toVariant()=0
toVariant
int32_t sequence
sequence internal counter. Useful as a unique indentifier. values is -1 if not used (default)...
Definition: abstractpropertytype.h:174
void fromVariant(GVariant *v)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:655
void setValue(boost::any val)
setValue
Definition: abstractpropertytype.h:527
Definition: abstractpropertytype.h:79
Definition: abstractpropertytype.h:69
void fromString(std::string val)
fromString converts from string value
Definition: abstractpropertytype.h:485
AbstractPropertyType * copy()
copy
Definition: abstractpropertytype.h:480
T basicValue()
basicValue
Definition: abstractpropertytype.h:517
Definition: abstractpropertytype.h:662
virtual AbstractPropertyType * copy()=0
copy
std::string toString() const
toString
Definition: abstractpropertytype.h:642
std::string toString() const
toString
Definition: abstractpropertytype.h:729
Priority priority
priority is used to tell the routing engine how to prioritize routing the value to plugins...
Definition: abstractpropertytype.h:193
void fromString(std::string str)
fromString converts from string value
Definition: abstractpropertytype.h:749
GVariant * toVariant()
toVariant
Definition: abstractpropertytype.h:776
Definition: abstractpropertytype.h:38
virtual void fromString(std::string)=0
fromString converts from string value
double timestamp
timestamp. Timestamp when the value was last updated by the system. This is updated automatically any...
Definition: abstractpropertytype.h:169
virtual std::string toString() const =0
toString
std::string toString() const
toString
Definition: abstractpropertytype.h:493
Zone::Type zone
zone that the property is situated in.
Definition: abstractpropertytype.h:185
Definition: abstractpropertytype.h:81
Priority
The Priority enum describes prority of the property type.
Definition: abstractpropertytype.h:76
std::string name
name Property name.
Definition: abstractpropertytype.h:161
GVariant * toVariant()
toVariant
Definition: abstractpropertytype.h:647
void fromString(std::string val)
fromString converts from string value
Definition: abstractpropertytype.h:632
std::string sourceUuid
sourceUuid uuid of the source that produced this property. This is set by the routingengine if left u...
Definition: abstractpropertytype.h:180
AbstractPropertyType * copy()
copy
Definition: abstractpropertytype.h:637
Definition: abstractpropertytype.h:395
Definition: abstractpropertytype.h:236
virtual void fromVariant(GVariant *)=0
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:80
GVariant * toVariant()
toVariant
Definition: abstractpropertytype.h:502
Definition: abstractpropertytype.h:588
std::vector< std::function< void(AbstractPropertyType *)> > destroyed
destroyed is called if this property is destroyed.
Definition: abstractpropertytype.h:227
Definition: abstractpropertytype.h:78
virtual void setValue(boost::any val)
setValue
Definition: abstractpropertytype.h:200
virtual void quickCopy(AbstractPropertyType *other)
quickCopy is intended as a way to quickly copy the often changing bits from one abstract property to ...
Definition: abstractpropertytype.h:134
T value() const
value() native value. Does not use type coercion. Will throw if types do not match.
Definition: abstractpropertytype.h:210
void fromVariant(GVariant *v)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:797
boost::any anyValue()
anyValue
Definition: abstractpropertytype.h:219
void fromVariant(GVariant *v)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:507
void append(AbstractPropertyType *property)
Definition: abstractpropertytype.h:703
AbstractPropertyType * copy()
copy
Definition: abstractpropertytype.h:724