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 * @param[in] position The specified position
169 * @return A reference to the value at the specified position.
171 * @note Will assert if position >= Count()
173 Value& GetValue( SizeType position ) const;
176 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
178 * @brief Retrieve the key at the specified position.
181 * @param[in] position The specified position
182 * @return A const reference to the key at the specified position.
184 * @note Will assert if position >= Count()
186 const std::string& GetKey( SizeType position ) const DALI_DEPRECATED_API;
189 * @brief Retrieve the key at the specified position.
192 * @return A copy of the key at the specified position.
194 * @note Will assert if position >= Count()
196 Key GetKeyAt( SizeType position ) const;
199 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
201 * @brief Retrieve the key & the value at the specified position.
204 * @param[in] position The specified position
205 * @return A reference to the pair of key and value at the specified position.
207 * @note Will assert if position >= Count() or key at position is an index key.
209 StringValuePair& GetPair( SizeType position ) const DALI_DEPRECATED_API;
212 * @brief Retrieve the key & the value at the specified position.
215 * @return A copy of the pair of key and value at the specified position.
217 * @note Will assert if position >= Count()
219 KeyValuePair GetKeyValue( SizeType position ) const;
222 * @brief Finds the value for the specified key if it exists.
225 * @param[in] key The key to find.
227 * @return A const pointer to the value if it exists, NULL otherwise
229 Value* Find( const char* key ) const;
232 * @brief Finds the value for the specified key if it exists.
235 * @param[in] key The key to find.
237 * @return A const pointer to the value if it exists, NULL otherwise
239 Value* Find( const std::string& key ) const;
242 * @brief Finds the value for the specified key if it exists.
245 * @param[in] key The key to find.
247 * @return A const pointer to the value if it exists, NULL otherwise
249 Value* Find( Property::Index key ) const;
252 * @brief Finds the value for the specified keys if either exist.
254 * Will search for the index key first.
257 * @param[in] indexKey The index key to find.
258 * @param[in] stringKey The string key to find.
260 * @return A const pointer to the value if it exists, NULL otherwise
262 Value* Find( Property::Index indexKey, const std::string& stringKey ) const;
265 * @brief Finds the value for the specified key if it exists and its type is type
268 * @param[in] key The key to find.
269 * @param[in] type The type to check.
271 * @return A const pointer to the value if it exists, NULL otherwise
273 Value* Find( const std::string& key, Property::Type type ) const;
276 * @brief Finds the value for the specified key if it exists and its type is type
279 * @param[in] key The key to find.
280 * @param[in] type The type to check.
282 * @return A const pointer to the value if it exists, NULL otherwise
284 Value* Find( Property::Index key, Property::Type type ) const;
287 * @brief Clears the map.
293 * @brief Merges values from the map 'from' to the current.
295 * Any values in 'from' will overwrite the values in the current map.
298 * @param[in] from The map to merge from.
300 void Merge( const Map& from );
303 * @brief Const operator to access element with the specified string key.
306 * @param[in] key The key whose value to access.
308 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
310 * @note Will assert if invalid-key is given.
312 const Value& operator[]( const std::string& key ) const;
315 * @brief Operator to access the element with the specified string key.
318 * @param[in] key The key whose value to access.
320 * @return A reference to the value for the element with the specified key.
322 * @note If an element with the key does not exist, then it is created.
324 Value& operator[]( const std::string& key );
327 * @brief Const operator to access element with the specified index key.
330 * @param[in] key The key whose value to access.
332 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
334 * @note Will assert if invalid-key is given.
336 const Value& operator[]( Property::Index key ) const;
339 * @brief Operator to access the element with the specified index key.
342 * @param[in] key The key whose value to access.
344 * @return A reference to the value for the element with the specified key.
346 * @note If an element with the key does not exist, then it is created.
348 Value& operator[]( Property::Index key );
351 * @brief Assignment Operator
354 * @param[in] other The map to copy from.
356 * @return The copied map.
358 Map& operator=( const Map& other );
361 * @brief output to stream
364 friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
367 struct DALI_INTERNAL Impl; ///< Private data
368 Impl* mImpl; ///< Pointer to private data
372 * @brief Convert the key/value pairs of the property map into a string and append to an output stream.
375 * @param [in] stream The output stream operator.
376 * @param [in] map The map to insert
377 * @return The output stream operator.
379 DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
386 #endif // __DALI_PROPERTY_MAP_H__