1 #ifndef __DALI_PROPERTY_MAP_H__
2 #define __DALI_PROPERTY_MAP_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
34 * @addtogroup dali_core_object
38 typedef std::pair< Property::Key, Property::Value > KeyValuePair;
39 typedef std::pair<std::string, Property::Value> StringValuePair;
42 * @brief A Map of property values, the key type could be String or Property::Index.
45 class DALI_IMPORT_API Property::Map
49 typedef std::size_t SizeType;
52 * @brief Default constructor.
58 * @brief Copy Constructor.
61 * @param[in] other The Map to copy from.
63 Map( const Map& other );
66 * @brief Non-virtual destructor.
72 * @brief Retrieve the number of elements in the map.
75 * @return The number of elements in the map.
77 SizeType Count() const;
80 * @brief Returns whether the map is empty.
83 * @return true if empty, false otherwise
88 * @brief Inserts the key-value pair in the Map, with the key type as string.
90 * Does not check for duplicates
92 * @param key to insert
93 * @param value to insert
95 void Insert( const char* key, const Value& value );
98 * @brief Inserts the key-value pair in the Map, with the key type as string.
100 * Does not check for duplicates
102 * @param key to insert
103 * @param value to insert
105 void Insert( const std::string& key, const Value& value );
108 * @brief Inserts the key-value pair in the Map, with the key type as index.
110 * Does not check for duplicates
112 * @param key to insert
113 * @param value to insert
115 void Insert( Property::Index key, const Value& value );
119 * @brief Inserts the key-value pair in the Map, with the key type as string.
121 * Does not check for duplicates
123 * @param key to insert
124 * @param value to insert
125 * @return a reference to this object
127 inline Property::Map& Add( const char* key, const Value& value )
134 * @brief Inserts the key-value pair in the Map, with the key type as string.
136 * Does not check for duplicates
138 * @param key to insert
139 * @param value to insert
140 * @return a reference to this object
142 inline Property::Map& Add( const std::string& key, const Value& value )
150 * @brief Inserts the key-value pair in the Map, with the key type as index.
152 * Does not check for duplicates
154 * @param key to insert
155 * @param value to insert
156 * @return a reference to this object
158 inline Property::Map& Add( Property::Index key, const Value& value )
165 * @brief Retrieve the value at the specified position.
168 * @return A reference to the value at the specified position.
170 * @note Will assert if position >= Count()
172 Value& GetValue( SizeType position ) const;
175 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
177 * @brief Retrieve the key at the specified position.
180 * @return A const reference to the key at the specified position.
182 * @note Will assert if position >= Count()
184 const std::string& GetKey( SizeType position ) const;
187 * @brief Retrieve the key at the specified position.
190 * @return A copy of the key at the specified position.
192 * @note Will assert if position >= Count()
194 Key GetKeyAt( SizeType position ) const;
197 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
199 * @brief Retrieve the key & the value at the specified position.
202 * @return A reference to the pair of key and value at the specified position.
204 * @note Will assert if position >= Count() or key at position is an index key.
206 StringValuePair& GetPair( SizeType position ) const;
209 * @brief Retrieve the key & the value at the specified position.
212 * @return A copy of the pair of key and value at the specified position.
214 * @note Will assert if position >= Count()
216 KeyValuePair GetKeyValue( SizeType position ) const;
219 * @brief Finds the value for the specified key if it exists.
222 * @param[in] key The key to find.
224 * @return A const pointer to the value if it exists, NULL otherwise
226 Value* Find( const char* key ) const;
229 * @brief Finds the value for the specified key if it exists.
232 * @param[in] key The key to find.
234 * @return A const pointer to the value if it exists, NULL otherwise
236 Value* Find( const std::string& key ) const;
239 * @brief Finds the value for the specified key if it exists.
242 * @param[in] key The key to find.
244 * @return A const pointer to the value if it exists, NULL otherwise
246 Value* Find( Property::Index key ) const;
249 * @brief Finds the value for the specified keys if either exist.
251 * Will search for the index key first.
254 * @param[in] indexKey The index key to find.
255 * @param[in] stringKey The string key to find.
257 * @return A const pointer to the value if it exists, NULL otherwise
259 Value* Find( Property::Index indexKey, const std::string& stringKey ) const;
262 * @brief Finds the value for the specified key if it exists and its type is type
265 * @param[in] key The key to find.
266 * @param[in] type The type to check.
268 * @return A const pointer to the value if it exists, NULL otherwise
270 Value* Find( const std::string& key, Property::Type type ) const;
273 * @brief Finds the value for the specified key if it exists and its type is type
276 * @param[in] key The key to find.
277 * @param[in] type The type to check.
279 * @return A const pointer to the value if it exists, NULL otherwise
281 Value* Find( Property::Index key, Property::Type type ) const;
284 * @brief Clears the map.
290 * @brief Merges values from the map 'from' to the current.
292 * Any values in 'from' will overwrite the values in the current map.
295 * @param[in] from The map to merge from.
297 void Merge( const Map& from );
300 * @brief Const operator to access element with the specified string key.
303 * @param[in] key The key whose value to access.
305 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
307 * @note Will assert if invalid-key is given.
309 const Value& operator[]( const std::string& key ) const;
312 * @brief Operator to access the element with the specified string key.
315 * @param[in] key The key whose value to access.
317 * @return A reference to the value for the element with the specified key.
319 * @note If an element with the key does not exist, then it is created.
321 Value& operator[]( const std::string& key );
324 * @brief Const operator to access element with the specified index key.
327 * @param[in] key The key whose value to access.
329 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
331 * @note Will assert if invalid-key is given.
333 const Value& operator[]( Property::Index key ) const;
336 * @brief Operator to access the element with the specified index key.
339 * @param[in] key The key whose value to access.
341 * @return A reference to the value for the element with the specified key.
343 * @note If an element with the key does not exist, then it is created.
345 Value& operator[]( Property::Index key );
348 * @brief Assignment Operator
351 * @param[in] other The map to copy from.
353 * @return The copied map.
355 Map& operator=( const Map& other );
358 * @brief output to stream
361 friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
364 struct DALI_INTERNAL Impl; ///< Private data
365 Impl* mImpl; ///< Pointer to private data
369 * @brief Convert the key/value pairs of the property map into a string and append to an output stream.
372 * @param [in] stream The output stream operator.
373 * @param [in] map The map to insert
374 * @return The output stream operator.
376 DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
383 #endif // __DALI_PROPERTY_MAP_H__