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> 37 #include <superptr.hpp> 59 static const Zone::Type FrontRight;
60 static const Zone::Type FrontLeft;
61 static const Zone::Type MiddleRight;
62 static const Zone::Type MiddleLeft;
63 static const Zone::Type RearRight;
64 static const Zone::Type RearLeft;
66 typedef std::vector<Zone::Type> ZoneList;
92 : name(property), timestamp(
amb::currentTime()), sequence(-1), zone(
Zone::None), priority(Normal)
99 for(
auto i : destroyed)
109 virtual std::string toString()
const = 0;
114 virtual void fromString(std::string)= 0;
120 virtual GVariant* toVariant() = 0;
126 virtual void fromVariant(GVariant*) = 0;
148 std::string one = toString();
151 && zone == other.
zone 153 && name == other.
name;
158 std::string one = toString();
208 timestamp = amb::currentTime();
214 template <
typename T>
217 return boost::any_cast<T>(mValue);
235 auto var = amb::make_super(toVariant());
238 const string s = g_variant_get_type_string(var.get());
240 DebugOut() <<
"returning signature: " << s <<
" for "<< name << endl;
248 std::vector<std::function<void(AbstractPropertyType*)>>
destroyed;
278 template <
typename T>
285 static const char* signature() {
return "i"; }
287 static int value(GVariant* v)
290 g_variant_get(v, signature(), &val);
294 static std::string stringize(std::string v)
304 static const char* signature() {
return "d"; }
306 static double value(GVariant* v)
308 return g_variant_get_double(v);
310 static std::string stringize(std::string v)
320 static const char* signature() {
return "q"; }
322 static uint16_t value(GVariant* v)
324 return g_variant_get_uint16(v);
326 static std::string stringize(std::string v)
336 static const char* signature() {
return "n"; }
338 static int16_t value(GVariant* v)
340 return g_variant_get_int16(v);
342 static std::string stringize(std::string v)
352 static const char* signature() {
return "y"; }
354 static char value(GVariant* v)
356 return g_variant_get_byte(v);
358 static std::string stringize(std::string v)
368 static const char* signature() {
return "u"; }
370 static uint32_t value(GVariant* v)
372 return g_variant_get_uint32(v);
374 static std::string stringize(std::string v)
384 static const char* signature() {
return "x"; }
386 static int64_t value(GVariant* v)
388 return g_variant_get_int64(v);
390 static std::string stringize(std::string v)
400 static const char* signature() {
return "t"; }
402 static uint64_t value(GVariant* v)
404 return g_variant_get_uint64(v);
406 static std::string stringize(std::string v)
416 static const char* signature() {
return "b"; }
418 static bool value(GVariant *v)
420 return g_variant_get_boolean(v);
422 static std::string stringize(std::string v)
424 if(v ==
"0" || v ==
"1")
427 boost::algorithm::to_lower(v);
428 return v ==
"true" ?
"1":
"0";
439 template <
typename T>
451 setValue(other.
value<T>());
462 setValue(other.
value<T>());
480 setValue(basicValue() + 1);
485 setValue(basicValue() - 1);
488 bool operator < (const BasicPropertyType<T>& other)
const 490 return value<T>() < other.value<T>();
495 return value<T>() > other.
value<T>();
513 if(!val.empty() && val !=
"")
533 if(!val.empty() && val !=
"")
541 std::stringstream stream;
542 stream.precision(10);
550 return serializeVariant<T>(value<T>());
555 setValue(deserializeVariant<T>(v));
583 void serialize(std::string val,
typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
587 std::stringstream stream(val);
590 setValue((N)someTemp);
594 void serialize(std::string val,
typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
603 GVariant* serializeVariant(T val,
typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
607 return (g_variant_new(
"i",(
int)val));
611 GVariant* serializeVariant(T val,
typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
619 T deserializeVariant(GVariant* v,
typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
627 T deserializeVariant(GVariant* v,
typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
642 setValue(std::string());
648 setValue(std::string());
660 setValue(other.
value<std::string>());
670 setValue(other.
value<std::string>());
682 setValue(std::string(other));
688 return value<std::string>() < other.
value<std::string>();
704 return value<std::string>();
711 return g_variant_new_string(toString().c_str());
717 setValue(std::string(g_variant_get_string(v,NULL)));
724 template <
class T = AbstractPropertyType>
744 std::vector<T> l = other.list();
773 appendPriv(property);
800 std::string str =
"[";
802 for(
auto itr = mList.begin(); itr != mList.end(); itr++)
825 if(str[0] ==
'[' && str[str.length()-1] ==
']')
827 str = str.substr(1,str.length() - 2);
830 std::vector<std::string> elements;
832 std::istringstream f(str);
835 while(std::getline(f,element,
','))
840 timestamp = amb::currentTime();
847 GVariantBuilder params;
848 g_variant_builder_init(¶ms, ((
const GVariantType *)
"av"));
850 for(
auto itr = mList.begin(); itr != mList.end(); itr++)
853 auto var = t.toVariant();
854 GVariant *newvar = g_variant_new(
"v", var);
855 g_variant_builder_add_value(¶ms, newvar);
858 GVariant* var = g_variant_builder_end(¶ms);
869 gsize dictsize = g_variant_n_children(v);
870 for (
int i=0;i<dictsize;i++)
872 GVariant *childvariant = g_variant_get_child_value(v,i);
873 GVariant *innervariant = g_variant_get_variant(childvariant);
875 t.fromVariant(innervariant);
880 std::vector<T> list() {
return mList; }
896 std::vector<T> mList;
int32_t sequence
sequence internal counter. Useful as a unique indentifier. values is -1 if not used (default)...
Definition: abstractpropertytype.h:179
void fromVariant(GVariant *v)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:715
void setValue(boost::any val)
setValue
Definition: abstractpropertytype.h:573
Definition: abstractpropertytype.h:70
void fromString(std::string val)
fromString converts from string value
Definition: abstractpropertytype.h:531
virtual const string signature()
signature
Definition: abstractpropertytype.h:233
AbstractPropertyType * copy()
copy
Definition: abstractpropertytype.h:526
T basicValue()
basicValue
Definition: abstractpropertytype.h:563
ListPropertyType is a AbstractPropertyType for arrays of AbstractPropertyTypes.
Definition: abstractpropertytype.h:725
Definition: abstractpropertytype.h:259
static const int Error
Error use when essential functionality is blocked.
Definition: debugout.h:80
std::string toString() const
toString
Definition: abstractpropertytype.h:702
std::string toString() const
toString
Definition: abstractpropertytype.h:798
Priority priority
priority is used to tell the routing engine how to prioritize routing the value to plugins...
Definition: abstractpropertytype.h:198
void fromString(std::string str)
fromString converts from string value
Definition: abstractpropertytype.h:818
GVariant * toVariant()
toVariant
Definition: abstractpropertytype.h:844
Definition: abstractpropertytype.h:39
double timestamp
timestamp. Timestamp when the value was last updated by the system. This is updated automatically any...
Definition: abstractpropertytype.h:174
virtual std::string toString() const =0
toString
std::string toString() const
toString
Definition: abstractpropertytype.h:539
Definition: abstractpropertytype.h:256
Zone::Type zone
zone that the property is situated in.
Definition: abstractpropertytype.h:190
The DebugOut class represents a class used for outputing debug information The specified debug level ...
Priority
The Priority enum describes prority of the property type.
Definition: abstractpropertytype.h:77
std::string name
name Property name.
Definition: abstractpropertytype.h:166
GVariant * toVariant()
toVariant
Definition: abstractpropertytype.h:707
void append(T property)
append - appends a property to the list
Definition: abstractpropertytype.h:765
void fromString(std::string val)
fromString converts from string value
Definition: abstractpropertytype.h:692
std::string sourceUuid
sourceUuid uuid of the source that produced this property. This is set by the routingengine if left u...
Definition: abstractpropertytype.h:185
AbstractPropertyType * copy()
copy
Definition: abstractpropertytype.h:697
Definition: abstractpropertytype.h:440
Definition: abstractpropertytype.h:279
GVariant * toVariant()
toVariant
Definition: abstractpropertytype.h:548
Definition: abstractpropertytype.h:634
std::vector< std::function< void(AbstractPropertyType *)> > destroyed
destroyed is called if this property is destroyed.
Definition: abstractpropertytype.h:248
virtual void setValue(boost::any val)
setValue
Definition: abstractpropertytype.h:205
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:139
Definition: debugout.h:73
T value() const
value() native value. Does not use type coercion. Will throw if types do not match.
Definition: abstractpropertytype.h:215
void fromVariant(GVariant *v)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:864
boost::any anyValue()
anyValue
Definition: abstractpropertytype.h:224
void fromVariant(GVariant *v)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:553
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:786
AbstractPropertyType * copy()
copy
Definition: abstractpropertytype.h:781