Revert "[Tizen] Add codes for Dali Windows Backend"
[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) 2018 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 #include <sstream>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/object/property.h>
28 #include <dali/public-api/object/property-key.h>
29 #include <dali/public-api/object/property-value.h>
30
31 namespace Dali
32 {
33 /**
34  * @addtogroup dali_core_object
35  * @{
36  */
37
38 typedef std::pair< Property::Key, Property::Value > KeyValuePair;
39 typedef std::pair<std::string, Property::Value> StringValuePair;
40
41 /**
42  * @brief A Map of property values, the key type could be String or Property::Index.
43  * @SINCE_1_0.0
44  */
45 class DALI_CORE_API Property::Map
46 {
47 public:
48
49   typedef std::size_t SizeType;
50
51   /**
52    * @brief Default constructor.
53    * @SINCE_1_0.0
54    */
55   Map();
56
57   /**
58    * @brief Copy Constructor.
59    *
60    * @SINCE_1_0.0
61    * @param[in] other The Map to copy from
62    */
63   Map( const Map& other );
64
65   /**
66    * @brief Non-virtual destructor.
67    * @SINCE_1_0.0
68    */
69   ~Map();
70
71   /**
72    * @brief Retrieves the number of elements in the map.
73    *
74    * @SINCE_1_0.0
75    * @return The number of elements in the map
76    */
77   SizeType Count() const;
78
79   /**
80    * @brief Returns whether the map is empty.
81    *
82    * @SINCE_1_0.0
83    * @return @c true if empty, @c false otherwise
84    */
85   bool Empty() const;
86
87   /**
88    * @brief Inserts the key-value pair in the Map, with the key type as string.
89    *
90    * Does not check for duplicates.
91    * @SINCE_1_0.0
92    * @param[in] key The key to insert
93    * @param[in] value The value to insert
94    */
95   void Insert( const char* key, const Value& value );
96
97   /**
98    * @brief Inserts the key-value pair in the Map, with the key type as string.
99    *
100    * Does not check for duplicates.
101    * @SINCE_1_0.0
102    * @param[in] key The key to insert
103    * @param[in] value The value to insert
104    */
105   void Insert( const std::string& key, const Value& value );
106
107   /**
108    * @brief Inserts the key-value pair in the Map, with the key type as index.
109    *
110    * Does not check for duplicates.
111    * @SINCE_1_1.39
112    * @param[in] key The key to insert
113    * @param[in] value The value to insert
114    */
115   void Insert( Property::Index key, const Value& value );
116
117
118   /**
119    * @brief Inserts the key-value pair in the Map, with the key type as string.
120    *
121    * Does not check for duplicates
122    * @SINCE_1_2.5
123    * @param key to insert
124    * @param value to insert
125    * @return a reference to this object
126    */
127   inline Property::Map& Add( const char* key, const Value& value )
128   {
129     Insert(key, value);
130     return *this;
131   }
132
133   /**
134    * @brief Inserts the key-value pair in the Map, with the key type as string.
135    *
136    * Does not check for duplicates
137    * @SINCE_1_2.5
138    * @param key to insert
139    * @param value to insert
140    * @return a reference to this object
141    */
142   inline Property::Map& Add( const std::string& key, const Value& value )
143   {
144     Insert(key, value);
145     return *this;
146   }
147
148
149   /**
150    * @brief Inserts the key-value pair in the Map, with the key type as index.
151    *
152    * Does not check for duplicates
153    * @SINCE_1_2.5
154    * @param key to insert
155    * @param value to insert
156    * @return a reference to this object
157    */
158   inline Property::Map& Add( Property::Index key, const Value& value )
159   {
160     Insert(key, value);
161     return *this;
162   }
163
164   /**
165    * @brief Retrieves the value at the specified position.
166    *
167    * @SINCE_1_0.0
168    * @param[in] position The specified position
169    * @return A reference to the value at the specified position
170    *
171    * @note Will assert if position >= Count()
172    */
173   Value& GetValue( SizeType position ) const;
174
175   /**
176    * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
177    *
178    * @brief Retrieves the key at the specified position.
179    *
180    * @SINCE_1_0.0
181    * @param[in] position The specified position
182    * @return A const reference to the key at the specified position
183    *
184    * @note Will assert if position >= Count()
185    */
186   const std::string& GetKey( SizeType position ) const DALI_DEPRECATED_API;
187
188   /**
189    * @brief Retrieve the key at the specified position.
190    *
191    * @SINCE_1_2.7
192    * @param[in] position The specified position
193    * @return A copy of the key at the specified position.
194    *
195    * @note Will assert if position >= Count()
196    */
197   Key GetKeyAt( SizeType position ) const;
198
199   /**
200    * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
201    *
202    * @brief Retrieves the key & the value at the specified position.
203    *
204    * @SINCE_1_0.0
205    * @param[in] position The specified position
206    * @return A reference to the pair of key and value at the specified position
207    *
208    * @note Will assert if position >= Count() or key at position is an index key.
209    */
210   StringValuePair& GetPair( SizeType position ) const DALI_DEPRECATED_API;
211
212   /**
213    * @brief Retrieve the key & the value at the specified position.
214    *
215    * @SINCE_1_2.7
216    * @param[in] position The specified position
217    * @return A copy of the pair of key and value at the specified position.
218    *
219    * @note Will assert if position >= Count()
220    */
221   KeyValuePair GetKeyValue( SizeType position ) const;
222
223   /**
224    * @brief Finds the value for the specified key if it exists.
225    *
226    * @SINCE_1_0.0
227    * @param[in] key The key to find
228    *
229    * @return A const pointer to the value if it exists, NULL otherwise
230    */
231   Value* Find( const char* key ) const;
232
233   /**
234    * @brief Finds the value for the specified key if it exists.
235    *
236    * @SINCE_1_0.0
237    * @param[in] key The key to find
238    *
239    * @return A const pointer to the value if it exists, NULL otherwise
240    */
241   Value* Find( const std::string& key ) const;
242
243   /**
244    * @brief Finds the value for the specified key if it exists.
245    *
246    * @SINCE_1_1.39
247    * @param[in] key The key to find
248    *
249    * @return A const pointer to the value if it exists, NULL otherwise
250    */
251   Value* Find( Property::Index key ) const;
252
253   /**
254    * @brief Finds the value for the specified keys if either exist.
255    *
256    * Will search for the index key first.
257    *
258    * @SINCE_1_1.45
259    * @param[in] indexKey  The index key to find
260    * @param[in] stringKey The string key to find
261    *
262    * @return A const pointer to the value if it exists, NULL otherwise
263    */
264   Value* Find( Property::Index indexKey, const std::string& stringKey ) const;
265
266   /**
267    * @brief Finds the value for the specified key if it exists and its type is type.
268    *
269    * @SINCE_1_0.0
270    * @param[in] key  The key to find
271    * @param[in] type The type to check
272    *
273    * @return A const pointer to the value if it exists, NULL otherwise
274    */
275   Value* Find( const std::string& key, Property::Type type ) const;
276
277   /**
278    * @brief Finds the value for the specified key if it exists and its type is type.
279    *
280    * @SINCE_1_1.39
281    * @param[in] key  The key to find
282    * @param[in] type The type to check
283    *
284    * @return A const pointer to the value if it exists, NULL otherwise
285    */
286   Value* Find( Property::Index key, Property::Type type ) const;
287
288   /**
289    * @brief Clears the map.
290    * @SINCE_1_0.0
291    */
292   void Clear();
293
294   /**
295    * @brief Merges values from the map 'from' to the current.
296    *
297    * Any values in 'from' will overwrite the values in the current map.
298    *
299    * @SINCE_1_0.0
300    * @param[in] from The map to merge from
301    */
302   void Merge( const Map& from );
303
304   /**
305    * @brief Const operator to access element with the specified string key.
306    *
307    * @SINCE_1_0.0
308    * @param[in] key The key whose value to access
309    *
310    * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
311    *
312    * @note Will assert if invalid-key is given.
313    */
314   const Value& operator[]( const std::string& key ) const;
315
316   /**
317    * @brief Operator to access the element with the specified string key.
318    *
319    * @SINCE_1_0.0
320    * @param[in] key The key whose value to access
321    *
322    * @return A reference to the value for the element with the specified key
323    *
324    * @note If an element with the key does not exist, then it is created.
325    */
326   Value& operator[]( const std::string& key );
327
328   /**
329    * @brief Const operator to access element with the specified index key.
330    *
331    * @SINCE_1_1.39
332    * @param[in] key The key whose value to access
333    *
334    * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
335    *
336    * @note Will assert if invalid-key is given.
337    */
338   const Value& operator[]( Property::Index key ) const;
339
340   /**
341    * @brief Operator to access the element with the specified index key.
342    *
343    * @SINCE_1_1.39
344    * @param[in] key The key whose value to access
345    *
346    * @return A reference to the value for the element with the specified key
347    *
348    * @note If an element with the key does not exist, then it is created.
349    */
350   Value& operator[]( Property::Index key );
351
352   /**
353    * @brief Assignment Operator.
354    *
355    * @SINCE_1_0.0
356    * @param[in] other The map to copy from
357    *
358    * @return The copied map
359    */
360   Map& operator=( const Map& other );
361
362   /**
363    * @brief Output to stream.
364    * @SINCE_1_1.28
365    */
366   friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
367
368 private:
369   struct DALI_INTERNAL Impl; ///< Private data
370   Impl* mImpl; ///< Pointer to private data
371 };
372
373 /**
374  * @brief Converts the key/value pairs of the property map into a string and append to an output stream.
375  *
376  * @SINCE_1_1.28
377  * @param[in] stream The output stream operator
378  * @param[in] map The map to insert
379  * @return The output stream operator
380  */
381 DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
382
383 /**
384  * @}
385  */
386 } // namespace Dali
387
388 #endif // __DALI_PROPERTY_MAP_H__