TDME2  1.9.200
BaseProperties.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 #include <string>
6 #include <vector>
7 
8 #include <tdme/tdme.h>
11 
12 using std::map;
13 using std::string;
14 using std::unique_ptr;
15 using std::vector;
16 
18 
21 
22 /**
23  * Base properties
24  * @author Andreas Drewke
25  */
27 {
28 private:
29  map<string, BaseProperty*> propertiesByName;
30  vector<unique_ptr<BaseProperty>> properties;
31 
32 protected:
33  string name;
34  string description;
35 
36 public:
37  // forbid class copy
39 
40  /**
41  * Public constructor
42  * @param name name
43  * @param description description
44  */
45  BaseProperties(const string& name, const string& description);
46 
47  /**
48  * Destructor
49  */
50  virtual ~BaseProperties();
51 
52  /**
53  * @return name
54  */
55  inline const string& getName() {
56  return name;
57  }
58 
59  /**
60  * Set up name
61  * @param name name
62  */
63  inline void setName(const string& name) {
64  this->name = name;
65  }
66 
67  /**
68  * @return description
69  */
70  inline const string& getDescription() {
71  return description;
72  }
73 
74  /**
75  * Set up description
76  * @param description description
77  */
78  inline void setDescription(const string& description) {
79  this->description = description;
80  }
81 
82  /**
83  * Clears properties
84  */
85  void clearProperties();
86 
87  /**
88  * Retrieve property by name
89  * @param name name
90  * @return property or null
91  */
92  const BaseProperty* getProperty(const string& name) const;
93 
94  /**
95  * Retrieve property by name
96  * @param name name
97  * @return property or null
98  */
99  BaseProperty* getProperty(const string& name);
100 
101  /**
102  * Get property index
103  * @param name name
104  * @return index or -1 if not found
105  */
106  const int getPropertyIndex(const string& name) const;
107 
108  /**
109  * Get property index
110  * @param name name
111  * @return index or -1 if not found
112  */
113  int getPropertyIndex(const string& name);
114 
115  /**
116  * @return Const properties iterator
117  */
120  }
121 
122  /**
123  * @return Properties iterator
124  */
126  return UniquePtrSequenceIterator<BaseProperty>(&(*properties.begin()), &(*properties.end()));
127  }
128 
129  /**
130  * @return property count
131  */
132  inline int getPropertyCount() {
133  return properties.size();
134  }
135 
136  /**
137  * Get property by index
138  * @param idx idx
139  * @return property or null
140  */
141  inline const BaseProperty* getPropertyAt(int idx) const {
142  return idx >= 0 && idx < properties.size()?properties[idx].get():nullptr;
143  }
144 
145  /**
146  * Get property by index
147  * @param idx idx
148  * @return property or null
149  */
150  inline BaseProperty* getPropertyAt(int idx) {
151  return idx >= 0 && idx < properties.size()?properties[idx].get():nullptr;
152  }
153 
154  /**
155  * Add a property
156  * @param name name
157  * @param value value
158  */
159  bool addProperty(const string& name, const string& value);
160 
161  /**
162  * Rename a property
163  * @param oldName old name
164  * @param name name
165  * @return success
166  */
167  bool renameProperty(const string& oldName, const string& name);
168 
169  /**
170  * Update a property
171  * @param oldName old name
172  * @param name name
173  * @param value value
174  * @return success
175  */
176  bool updateProperty(const string& oldName, const string& name, const string& value);
177 
178  /**
179  * Removes a property
180  * @param name property name
181  */
182  bool removeProperty(const string& name);
183 
184 };
void clearProperties()
Clears properties.
UniquePtrSequenceIterator< BaseProperty > getProperties()
bool updateProperty(const string &oldName, const string &name, const string &value)
Update a property.
vector< unique_ptr< BaseProperty > > properties
const BaseProperty * getPropertyAt(int idx) const
Get property by index.
BaseProperty * getPropertyAt(int idx)
Get property by index.
void setName(const string &name)
Set up name.
const int getPropertyIndex(const string &name) const
Get property index.
const BaseProperty * getProperty(const string &name) const
Retrieve property by name.
map< string, BaseProperty * > propertiesByName
BaseProperties(const string &name, const string &description)
Public constructor.
ConstUniquePtrSequenceIterator< BaseProperty > getProperties() const
bool addProperty(const string &name, const string &value)
Add a property.
bool removeProperty(const string &name)
Removes a property.
bool renameProperty(const string &oldName, const string &name)
Rename a property.
void setDescription(const string &description)
Set up description.
Base property model class.
Definition: BaseProperty.h:15
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6