[dali_1.2.6] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-map.h
1 #ifndef __DALI_PROPERTY_MAP_H__
2 #define __DALI_PROPERTY_MAP_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/property-value.h>
27 #include <dali/public-api/object/property.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_core_object
33  * @{
34  */
35
36 typedef std::pair<std::string, Property::Value> StringValuePair;
37
38 /**
39  * @brief A Map of property values, the key type could be String or Property::Index.
40  * @SINCE_1_0.0
41  */
42 class DALI_IMPORT_API Property::Map
43 {
44 public:
45
46   typedef std::size_t SizeType;
47
48   /**
49    * @brief Default constructor.
50    * @SINCE_1_0.0
51    */
52   Map();
53
54   /**
55    * @brief Copy Constructor.
56    *
57    * @SINCE_1_0.0
58    * @param[in] other The Map to copy from.
59    */
60   Map( const Map& other );
61
62   /**
63    * @brief Non-virtual destructor.
64    * @SINCE_1_0.0
65    */
66   ~Map();
67
68   /**
69    * @brief Retrieve the number of elements in the map.
70    *
71    * @SINCE_1_0.0
72    * @return The number of elements in the map.
73    */
74   SizeType Count() const;
75
76   /**
77    * @brief Returns whether the map is empty.
78    *
79    * @SINCE_1_0.0
80    * @return true if empty, false otherwise
81    */
82   bool Empty() const;
83
84   /**
85    * @brief Inserts the key-value pair in the Map, with the key type as string.
86    *
87    * Does not check for duplicates
88    * @SINCE_1_0.0
89    * @param key to insert
90    * @param value to insert
91    */
92   void Insert( const char* key, const Value& value );
93
94   /**
95    * @brief Inserts the key-value pair in the Map, with the key type as string.
96    *
97    * Does not check for duplicates
98    * @SINCE_1_0.0
99    * @param key to insert
100    * @param value to insert
101    */
102   void Insert( const std::string& key, const Value& value );
103
104   /**
105    * @brief Inserts the key-value pair in the Map, with the key type as index.
106    *
107    * Does not check for duplicates
108    * @SINCE_1_1.39
109    * @param key to insert
110    * @param value to insert
111    */
112   void Insert( Property::Index key, const Value& value );
113
114
115   /**
116    * @brief Inserts the key-value pair in the Map, with the key type as string.
117    *
118    * Does not check for duplicates
119    * @SINCE_1_2.5
120    * @param key to insert
121    * @param value to insert
122    * @return a reference to this object
123    */
124   inline Property::Map& Add( const char* key, const Value& value )
125   {
126     Insert(key, value);
127     return *this;
128   }
129
130   /**
131    * @brief Inserts the key-value pair in the Map, with the key type as string.
132    *
133    * Does not check for duplicates
134    * @SINCE_1_2.5
135    * @param key to insert
136    * @param value to insert
137    * @return a reference to this object
138    */
139   inline Property::Map& Add( const std::string& key, const Value& value )
140   {
141     Insert(key, value);
142     return *this;
143   }
144
145
146   /**
147    * @brief Inserts the key-value pair in the Map, with the key type as index.
148    *
149    * Does not check for duplicates
150    * @SINCE_1_2.5
151    * @param key to insert
152    * @param value to insert
153    * @return a reference to this object
154    */
155   inline Property::Map& Add( Property::Index key, const Value& value )
156   {
157     Insert(key, value);
158     return *this;
159   }
160
161   /**
162    * DEPRECATED_1_1.39. Retrieve the value with key instead of position, Use Find( key ) instead.
163    *
164    * @brief Retrieve the value of the string-value pair at the specified position.
165    *
166    * @SINCE_1_0.0
167    * @return A reference to the value at the specified position.
168    *
169    * @note Will assert if position >= Count()
170    */
171   Value& GetValue( SizeType position ) const;
172
173   /**
174    * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
175    *
176    * @brief Retrieve the key at the specified position.
177    *
178    * @SINCE_1_0.0
179    * @return A const reference to the key at the specified position.
180    *
181    * @note Will assert if position >= Count()
182    */
183   const std::string& GetKey( SizeType position ) const;
184
185   /**
186    * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
187    *
188    * @brief Retrieve the key & the value at the specified position.
189    *
190    * @SINCE_1_0.0
191    * @return A reference to the pair of key and value at the specified position.
192    *
193    * @note Will assert if position >= Count()
194    */
195   StringValuePair& GetPair( SizeType position ) const;
196
197   /**
198    * @brief Finds the value for the specified key if it exists.
199    *
200    * @SINCE_1_0.0
201    * @param[in]  key   The key to find.
202    *
203    * @return A const pointer to the value if it exists, NULL otherwise
204    */
205   Value* Find( const char* key ) const;
206
207   /**
208    * @brief Finds the value for the specified key if it exists.
209    *
210    * @SINCE_1_0.0
211    * @param[in]  key   The key to find.
212    *
213    * @return A const pointer to the value if it exists, NULL otherwise
214    */
215   Value* Find( const std::string& key ) const;
216
217   /**
218    * @brief Finds the value for the specified key if it exists.
219    *
220    * @SINCE_1_1.39
221    * @param[in]  key   The key to find.
222    *
223    * @return A const pointer to the value if it exists, NULL otherwise
224    */
225   Value* Find( Property::Index key ) const;
226
227   /**
228    * @brief Finds the value for the specified keys if either exist.
229    *
230    * Will search for the index key first.
231    *
232    * @SINCE_1_1.45
233    * @param[in]  indexKey   The index key to find.
234    * @param[in]  stringKey  The string key to find.
235    *
236    * @return A const pointer to the value if it exists, NULL otherwise
237    */
238   Value* Find( Property::Index indexKey, const std::string& stringKey ) const;
239
240   /**
241    * @brief Finds the value for the specified key if it exists and its type is type
242    *
243    * @SINCE_1_0.0
244    * @param[in]  key   The key to find.
245    * @param[in]  type  The type to check.
246    *
247    * @return A const pointer to the value if it exists, NULL otherwise
248    */
249   Value* Find( const std::string& key, Property::Type type ) const;
250
251   /**
252    * @brief Finds the value for the specified key if it exists and its type is type
253    *
254    * @SINCE_1_1.39
255    * @param[in]  key   The key to find.
256    * @param[in]  type  The type to check.
257    *
258    * @return A const pointer to the value if it exists, NULL otherwise
259    */
260   Value* Find( Property::Index key, Property::Type type ) const;
261
262   /**
263    * @brief Clears the map.
264    * @SINCE_1_0.0
265    */
266   void Clear();
267
268   /**
269    * @brief Merges values from the map 'from' to the current.
270    *
271    * Any values in 'from' will overwrite the values in the current map.
272    *
273    * @SINCE_1_0.0
274    * @param[in]  from  The map to merge from.
275    */
276   void Merge( const Map& from );
277
278   /**
279    * @brief Const operator to access element with the specified string key.
280    *
281    * @SINCE_1_0.0
282    * @param[in] key The key whose value to access.
283    *
284    * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
285    *
286    * @note Will assert if invalid-key is given.
287    */
288   const Value& operator[]( const std::string& key ) const;
289
290   /**
291    * @brief Operator to access the element with the specified string key.
292    *
293    * @SINCE_1_0.0
294    * @param[in] key The key whose value to access.
295    *
296    * @return A reference to the value for the element with the specified key.
297    *
298    * @note If an element with the key does not exist, then it is created.
299    */
300   Value& operator[]( const std::string& key );
301
302   /**
303    * @brief Const operator to access element with the specified index key.
304    *
305    * @SINCE_1_1.39
306    * @param[in] key The key whose value to access.
307    *
308    * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
309    *
310    * @note Will assert if invalid-key is given.
311    */
312   const Value& operator[]( Property::Index key ) const;
313
314   /**
315    * @brief Operator to access the element with the specified index key.
316    *
317    * @SINCE_1_1.39
318    * @param[in] key The key whose value to access.
319    *
320    * @return A reference to the value for the element with the specified key.
321    *
322    * @note If an element with the key does not exist, then it is created.
323    */
324   Value& operator[]( Property::Index key );
325
326   /**
327    * @brief Assignment Operator
328    *
329    * @SINCE_1_0.0
330    * @param[in] other The map to copy from.
331    *
332    * @return The copied map.
333    */
334   Map& operator=( const Map& other );
335
336   /**
337    * @brief output to stream
338    * @SINCE_1_1.28
339    */
340   friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
341
342 private:
343   struct DALI_INTERNAL Impl; ///< Private data
344   Impl* mImpl; ///< Pointer to private data
345 };
346
347 /**
348  * @brief Convert the key/value pairs of the property map into a string and append to an output stream.
349  *
350  * @SINCE_1_1.28
351  * @param [in] stream The output stream operator.
352  * @param [in] map The map to insert
353  * @return The output stream operator.
354  */
355 DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
356
357
358 /**
359  * @}
360  */
361 } // namespace Dali
362
363 #endif // __DALI_PROPERTY_MAP_H__