ObjectArray.h
Go to the documentation of this file.
1 
20 #pragma once
21 
22 #include "ArrayBase.h"
23 #include "ArrayIterator.h"
24 
25 namespace ConfigDB
26 {
30 class ObjectArray : public ArrayBase
31 {
32 public:
33  using ArrayBase::ArrayBase;
34 
35  Object getObject(unsigned index)
36  {
37  return Object(*this, 0, index);
38  }
39 
40  Object getItem(unsigned index)
41  {
42  return getObject(index);
43  }
44 
45  unsigned getObjectCount() const
46  {
47  return getItemCount();
48  }
49 
50  template <typename Item = Object> Item addItem()
51  {
52  if(!this->writeCheck()) {
53  return {};
54  }
55  auto& array = getArray();
56  auto index = array.getCount();
57  auto& itemType = getItemType();
58  array.add(itemType.variant.object->defaultData);
59  return Item(*this, 0, index);
60  }
61 
62  template <typename Item = Object> Item insertItem(unsigned index)
63  {
64  if(!this->writeCheck()) {
65  return {};
66  }
67  auto& itemType = getItemType();
68  auto& array = getArray();
69  array.insert(index, itemType.variant.object->defaultData);
70  return Item(*this, 0, index);
71  }
72 
73  const PropertyInfo& getItemType() const
74  {
75  return typeinfo().propinfo[0];
76  }
77 };
78 
84 template <class ClassType, class ItemType> class ObjectArrayTemplate : public ObjectArray
85 {
86 public:
88 
89  using ObjectArray::ObjectArray;
90 
91  const ItemType operator[](unsigned index) const
92  {
93  return ItemType(*this, 0, index);
94  }
95 
96  Iterator begin() const
97  {
98  return Iterator(*this, 0);
99  }
100 
101  Iterator end() const
102  {
103  return Iterator(*this, this->getItemCount());
104  }
105 };
106 
113 template <class UpdaterType, class ClassType, class ItemType> class ObjectArrayUpdaterTemplate : public ClassType
114 {
115 public:
117 
118  using ClassType::ClassType;
119 
120  ItemType operator[](unsigned index)
121  {
122  return ItemType(*this, 0, index);
123  }
124 
125  ItemType addItem()
126  {
127  return ObjectArray::addItem<ItemType>();
128  }
129 
130  ItemType insertItem(unsigned index)
131  {
132  return ObjectArray::insertItem<ItemType>(index);
133  }
134 
136  {
137  return Iterator(*this, 0);
138  }
139 
141  {
142  return Iterator(*this, this->getItemCount());
143  }
144 };
145 
146 } // namespace ConfigDB
Base class to provide array of properties.
Definition: ArrayBase.h:31
unsigned getItemCount() const
Definition: ArrayBase.h:35
Object()
Definition: Libraries/ConfigDB/src/include/ConfigDB/Object.h:39
ArrayData & getArray()
Array iterator support.
Definition: ArrayIterator.h:28
Used by code generator.
Definition: ObjectArray.h:85
Iterator begin() const
Definition: ObjectArray.h:96
Iterator end() const
Definition: ObjectArray.h:101
const ArrayIterator< const ObjectArrayTemplate, const ItemType > Iterator
Definition: ObjectArray.h:87
const ItemType operator[](unsigned index) const
Definition: ObjectArray.h:91
Used by code generator.
Definition: ObjectArray.h:114
Iterator begin()
Definition: ObjectArray.h:135
ItemType addItem()
Definition: ObjectArray.h:125
Iterator end()
Definition: ObjectArray.h:140
ItemType insertItem(unsigned index)
Definition: ObjectArray.h:130
ArrayIterator< ObjectArrayUpdaterTemplate, ItemType > Iterator
Definition: ObjectArray.h:116
ItemType operator[](unsigned index)
Definition: ObjectArray.h:120
Base class to provide array of objects.
Definition: ObjectArray.h:31
Item addItem()
Definition: ObjectArray.h:50
const PropertyInfo & getItemType() const
Definition: ObjectArray.h:73
Item insertItem(unsigned index)
Definition: ObjectArray.h:62
Object getObject(unsigned index)
Definition: ObjectArray.h:35
unsigned getObjectCount() const
Definition: ObjectArray.h:45
Object getItem(unsigned index)
Definition: ObjectArray.h:40
An object can contain other objects, properties and arrays.
Definition: Libraries/ConfigDB/src/include/ConfigDB/Object.h:37
const ObjectInfo & typeinfo() const
Definition: Libraries/ConfigDB/src/include/ConfigDB/Object.h:232
bool writeCheck() const
Definition: Array.h:26
const PropertyInfo propinfo[]
Definition: ObjectInfo.h:45
Property metadata.
Definition: PropertyInfo.h:112