added new properties
[profile/ivi/automotive-message-broker.git] / lib / abstractpropertytype.cpp
1 #include "abstractpropertytype.h"
2
3
4 void ListPropertyType::append(AbstractPropertyType *property)
5 {
6         mList.push_back(property->copy());
7 }
8
9
10 ListPropertyType::ListPropertyType()
11 {
12
13 }
14
15 ListPropertyType::ListPropertyType(int)
16 {
17
18 }
19
20 ListPropertyType::ListPropertyType(ListPropertyType &other)
21 {
22         std::list<AbstractPropertyType*> l = other.list();
23         for(auto itr = l.begin(); itr != l.end(); itr++)
24         {
25                 append(*itr);
26         }
27 }
28
29
30 ListPropertyType::~ListPropertyType()
31 {
32
33 }
34
35
36 uint ListPropertyType::count()
37 {
38         return mList.size();
39 }
40
41
42 AbstractPropertyType *ListPropertyType::copy()
43 {
44         return new ListPropertyType(*this);
45 }
46
47
48 std::string ListPropertyType::toString() const
49 {
50         std::string str = "[";
51
52         for(auto itr = mList.begin(); itr != mList.end(); itr++)
53         {
54                 if(str != "[")
55                         str += ",";
56
57                 AbstractPropertyType* t = *itr;
58
59                 str += t->toString();
60         }
61
62         str += "]";
63
64         return str;
65 }
66
67
68 void ListPropertyType::fromString(std::string)
69 {
70         /// TODO: try to use VehicleProperty::getPropertyType... here
71 }
72
73
74 GVariant *ListPropertyType::toVariant()
75 {
76         GVariantBuilder params;
77         g_variant_builder_init(&params,G_VARIANT_TYPE_ARRAY);
78
79         for(auto itr = mList.begin(); itr != mList.end(); itr++)
80         {
81                 AbstractPropertyType* t;
82                 g_variant_builder_add_value(&params, t->toVariant());
83         }
84
85         return g_variant_builder_end(&params);
86 }
87
88
89 void ListPropertyType::fromVariant(GVariant *v)
90 {
91
92 }