1 #ifndef _MAPPROPERTYTYPE_H_
2 #define _MAPPROPERTYTYPE_H_
5 #include "abstractpropertytype.h"
11 template <
class T,
class N>
17 void append(T key, N
value)
19 appendPriv(key,value);
38 std::stringstream str;
42 for(
auto itr = mMap.begin(); itr != mMap.end(); itr++)
49 str <<
"'"<< t.first.toString() <<
"':'"<<t.second.toString()<<
"'";
59 json_object *rootobject;
60 json_tokener *tokener = json_tokener_new();
61 enum json_tokener_error err;
64 rootobject = json_tokener_parse_ex(tokener, str.c_str(),str.length());
65 }
while ((err = json_tokener_get_error(tokener)) == json_tokener_continue);
66 if (err != json_tokener_success)
68 fprintf(stderr,
"Error: %s\n", json_tokener_error_desc(err));
71 if (tokener->char_offset < str.length())
80 json_object_object_foreach(rootobject, key, val)
83 N two(
"", std::string(json_object_get_string(val)));
87 json_object_put(rootobject);
88 json_tokener_free(tokener);
94 GVariantBuilder params;
95 g_variant_builder_init(¶ms, G_VARIANT_TYPE_DICTIONARY);
96 for(
auto itr = mMap.begin(); itr != mMap.end(); itr++)
98 auto &foo = (*itr).first;
99 g_variant_builder_add(¶ms,
"{?*}",const_cast<T&>(foo).
toVariant(),(*itr).second.toVariant());
102 GVariant* var = g_variant_builder_end(¶ms);
111 gsize dictsize = g_variant_n_children(variant);
112 for (
int i=0;i<dictsize;i++)
114 GVariant *childvariant = g_variant_get_child_value(variant,i);
115 gsize dictvalsize = g_variant_n_children(childvariant);
116 if (dictvalsize == 2)
119 GVariant *keyvariant = g_variant_get_child_value(childvariant,0);
120 GVariant *valvariant = g_variant_get_child_value(childvariant,1);
122 t.fromVariant(keyvariant);
124 n.fromVariant(valvariant);
131 void setMap(std::map<T, N> m)
143 void appendPriv(T key, N value)
Definition: mappropertytype.hpp:12
int32_t sequence
sequence internal counter. Useful as a unique indentifier. values is -1 if not used (default)...
Definition: abstractpropertytype.h:174
Definition: abstractpropertytype.h:69
GVariant * toVariant()
toVariant
Definition: mappropertytype.hpp:92
std::string toString() const
toString
Definition: mappropertytype.hpp:36
void fromString(std::string str)
fromString converts from string value
Definition: mappropertytype.hpp:57
double timestamp
timestamp. Timestamp when the value was last updated by the system. This is updated automatically any...
Definition: abstractpropertytype.h:169
AbstractPropertyType * copy()
copy
Definition: mappropertytype.hpp:22
Zone::Type zone
zone that the property is situated in.
Definition: abstractpropertytype.h:185
std::string name
name Property name.
Definition: abstractpropertytype.h:161
void fromVariant(GVariant *variant)
fromVariant converts GVariant value into compatible native value. Caller owns GVariant argument...
Definition: mappropertytype.hpp:107
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
T value() const
value() native value. Does not use type coercion. Will throw if types do not match.
Definition: abstractpropertytype.h:210