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;
105 virtual std::string
toString()
const = 0;
204 timestamp = amb::currentTime();
210 template <
typename T>
213 return boost::any_cast<T>(mValue);
234 const string s = g_variant_get_type_string(var.get());
236 DebugOut() <<
"returning signature: " << s <<
" for "<< name << endl;
244 std::vector<std::function<void(AbstractPropertyType*)>>
destroyed;
274 template <
typename T>
281 static const char* signature() {
return "i"; }
283 static int value(GVariant* v)
286 g_variant_get(v, signature(), &val);
290 static std::string stringize(std::string v)
300 static const char* signature() {
return "d"; }
302 static double value(GVariant* v)
304 return g_variant_get_double(v);
306 static std::string stringize(std::string v)
316 static const char* signature() {
return "q"; }
318 static uint16_t value(GVariant* v)
320 return g_variant_get_uint16(v);
322 static std::string stringize(std::string v)
332 static const char* signature() {
return "n"; }
334 static int16_t value(GVariant* v)
336 return g_variant_get_int16(v);
338 static std::string stringize(std::string v)
348 static const char* signature() {
return "y"; }
350 static char value(GVariant* v)
352 return g_variant_get_byte(v);
354 static std::string stringize(std::string v)
364 static const char* signature() {
return "u"; }
366 static uint32_t value(GVariant* v)
368 return g_variant_get_uint32(v);
370 static std::string stringize(std::string v)
380 static const char* signature() {
return "x"; }
382 static int64_t value(GVariant* v)
384 return g_variant_get_int64(v);
386 static std::string stringize(std::string v)
396 static const char* signature() {
return "t"; }
398 static uint64_t value(GVariant* v)
400 return g_variant_get_uint64(v);
402 static std::string stringize(std::string v)
412 static const char* signature() {
return "b"; }
414 static bool value(GVariant *v)
416 return g_variant_get_boolean(v);
418 static std::string stringize(std::string v)
420 if(v ==
"0" || v ==
"1")
423 boost::algorithm::to_lower(v);
424 return v ==
"true" ?
"1":
"0";
435 template <
typename T>
447 setValue(other.
value<T>());
458 setValue(other.
value<T>());
484 bool operator < (const BasicPropertyType<T>& other)
const
486 return value<T>() < other.value<T>();
491 return value<T>() > other.
value<T>();
509 if(!val.empty() && val !=
"")
529 if(!val.empty() && val !=
"")
537 std::stringstream stream;
538 stream.precision(10);
546 return serializeVariant<T>(value<T>());
551 setValue(deserializeVariant<T>(v));
579 void serialize(std::string val,
typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
583 std::stringstream stream(val);
586 setValue((N)someTemp);
590 void serialize(std::string val,
typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
599 GVariant* serializeVariant(T val,
typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
603 return (g_variant_new(
"i",(
int)val));
607 GVariant* serializeVariant(T val,
typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
615 T deserializeVariant(GVariant* v,
typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
623 T deserializeVariant(GVariant* v,
typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
684 return value<std::string>() < other.
value<std::string>();
700 return value<std::string>();
707 return g_variant_new_string(
toString().c_str());
713 setValue(std::string(g_variant_get_string(v,NULL)));
720 template <
class T = AbstractPropertyType>
740 std::vector<T> l = other.list();
769 appendPriv(property);
796 std::string str =
"[";
798 for(
auto itr = mList.begin(); itr != mList.end(); itr++)
821 if(str[0] ==
'[' && str[str.length()-1] ==
']')
823 str = str.substr(1,str.length() - 2);
826 std::vector<std::string> elements;
828 std::istringstream f(str);
831 while(std::getline(f,element,
','))
843 GVariantBuilder params;
844 g_variant_builder_init(¶ms, ((
const GVariantType *)
"av"));
846 for(
auto itr = mList.begin(); itr != mList.end(); itr++)
849 auto var = t.toVariant();
850 GVariant *newvar = g_variant_new(
"v", var);
851 g_variant_builder_add_value(¶ms, newvar);
854 GVariant* var = g_variant_builder_end(¶ms);
865 gsize dictsize = g_variant_n_children(v);
866 for (
int i=0;i<dictsize;i++)
868 GVariant *childvariant = g_variant_get_child_value(v,i);
869 GVariant *innervariant = g_variant_get_variant(childvariant);
871 t.fromVariant(innervariant);
876 std::vector<T> list() {
return mList; }
892 std::vector<T> 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:175
void fromVariant(GVariant *v)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:711
void setValue(boost::any val)
setValue
Definition: abstractpropertytype.h:569
Definition: abstractpropertytype.h:80
Definition: abstractpropertytype.h:70
void fromString(std::string val)
fromString converts from string value
Definition: abstractpropertytype.h:527
virtual const string signature()
signature
Definition: abstractpropertytype.h:229
AbstractPropertyType * copy()
copy
Definition: abstractpropertytype.h:522
T basicValue()
basicValue
Definition: abstractpropertytype.h:559
ListPropertyType is a AbstractPropertyType for arrays of AbstractPropertyTypes.
Definition: abstractpropertytype.h:721
Definition: abstractpropertytype.h:255
static const int Error
Error use when essential functionality is blocked.
Definition: debugout.h:64
Definition: abstractpropertytype.h:275
virtual AbstractPropertyType * copy()=0
copy
std::string toString() const
toString
Definition: abstractpropertytype.h:698
std::string toString() const
toString
Definition: abstractpropertytype.h:794
Priority priority
priority is used to tell the routing engine how to prioritize routing the value to plugins...
Definition: abstractpropertytype.h:194
void fromString(std::string str)
fromString converts from string value
Definition: abstractpropertytype.h:814
GVariant * toVariant()
toVariant
Definition: abstractpropertytype.h:840
Definition: abstractpropertytype.h:39
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:170
virtual std::string toString() const =0
toString
std::string toString() const
toString
Definition: abstractpropertytype.h:535
Definition: abstractpropertytype.h:252
Zone::Type zone
zone that the property is situated in.
Definition: abstractpropertytype.h:186
Definition: abstractpropertytype.h:82
Priority
The Priority enum describes prority of the property type.
Definition: abstractpropertytype.h:77
std::string name
name Property name.
Definition: abstractpropertytype.h:162
GVariant * toVariant()
toVariant
Definition: abstractpropertytype.h:703
void append(T property)
append - appends a property to the list
Definition: abstractpropertytype.h:761
void fromString(std::string val)
fromString converts from string value
Definition: abstractpropertytype.h:688
std::string sourceUuid
sourceUuid uuid of the source that produced this property. This is set by the routingengine if left u...
Definition: abstractpropertytype.h:181
AbstractPropertyType * copy()
copy
Definition: abstractpropertytype.h:693
Definition: abstractpropertytype.h:436
virtual void fromVariant(GVariant *)=0
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:81
GVariant * toVariant()
toVariant
Definition: abstractpropertytype.h:544
Definition: abstractpropertytype.h:630
std::vector< std::function< void(AbstractPropertyType *)> > destroyed
destroyed is called if this property is destroyed.
Definition: abstractpropertytype.h:244
Definition: abstractpropertytype.h:79
virtual void setValue(boost::any val)
setValue
Definition: abstractpropertytype.h:201
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:135
The DebugOut class represents a class used for outputing debug information The specified debug level ...
Definition: debugout.h:57
T value() const
value() native value. Does not use type coercion. Will throw if types do not match.
Definition: abstractpropertytype.h:211
void fromVariant(GVariant *v)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:860
boost::any anyValue()
anyValue
Definition: abstractpropertytype.h:220
void fromVariant(GVariant *v)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: abstractpropertytype.h:549
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:782
AbstractPropertyType * copy()
copy
Definition: abstractpropertytype.h:777