1 #ifndef __DALI_PROPERTY_MAP_H__
2 #define __DALI_PROPERTY_MAP_H__
5 * Copyright (c) 2018 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_CORE_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 Retrieves 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 @c true if empty, @c 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[in] key The key to insert
93 * @param[in] value The 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[in] key The key to insert
103 * @param[in] value The 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[in] key The key to insert
113 * @param[in] value The 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 Retrieves 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 Retrieves 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 * @param[in] position The specified position
193 * @return A copy of the key at the specified position.
195 * @note Will assert if position >= Count()
197 Key GetKeyAt( SizeType position ) const;
200 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
202 * @brief Retrieves the key & the value at the specified position.
205 * @param[in] position The specified position
206 * @return A reference to the pair of key and value at the specified position
208 * @note Will assert if position >= Count() or key at position is an index key.
210 StringValuePair& GetPair( SizeType position ) const DALI_DEPRECATED_API;
213 * @brief Retrieve the key & the value at the specified position.
216 * @param[in] position The specified position
217 * @return A copy of the pair of key and value at the specified position.
219 * @note Will assert if position >= Count()
221 KeyValuePair GetKeyValue( SizeType position ) const;
224 * @brief Finds the value for the specified key if it exists.
227 * @param[in] key The key to find
229 * @return A const pointer to the value if it exists, NULL otherwise
231 Value* Find( const char* key ) const;
234 * @brief Finds the value for the specified key if it exists.
237 * @param[in] key The key to find
239 * @return A const pointer to the value if it exists, NULL otherwise
241 Value* Find( const std::string& key ) const;
244 * @brief Finds the value for the specified key if it exists.
247 * @param[in] key The key to find
249 * @return A const pointer to the value if it exists, NULL otherwise
251 Value* Find( Property::Index key ) const;
254 * @brief Finds the value for the specified keys if either exist.
256 * Will search for the index key first.
259 * @param[in] indexKey The index key to find
260 * @param[in] stringKey The string key to find
262 * @return A const pointer to the value if it exists, NULL otherwise
264 Value* Find( Property::Index indexKey, const std::string& stringKey ) const;
267 * @brief Finds the value for the specified key if it exists and its type is type.
270 * @param[in] key The key to find
271 * @param[in] type The type to check
273 * @return A const pointer to the value if it exists, NULL otherwise
275 Value* Find( const std::string& key, Property::Type type ) const;
278 * @brief Finds the value for the specified key if it exists and its type is type.
281 * @param[in] key The key to find
282 * @param[in] type The type to check
284 * @return A const pointer to the value if it exists, NULL otherwise
286 Value* Find( Property::Index key, Property::Type type ) const;
289 * @brief Clears the map.
295 * @brief Merges values from the map 'from' to the current.
297 * Any values in 'from' will overwrite the values in the current map.
300 * @param[in] from The map to merge from
302 void Merge( const Map& from );
305 * @brief Const operator to access element with the specified string key.
308 * @param[in] key The key whose value to access
310 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
312 * @note Will assert if invalid-key is given.
314 const Value& operator[]( const std::string& key ) const;
317 * @brief Operator to access the element with the specified string key.
320 * @param[in] key The key whose value to access
322 * @return A reference to the value for the element with the specified key
324 * @note If an element with the key does not exist, then it is created.
326 Value& operator[]( const std::string& key );
329 * @brief Const operator to access element with the specified index key.
332 * @param[in] key The key whose value to access
334 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
336 * @note Will assert if invalid-key is given.
338 const Value& operator[]( Property::Index key ) const;
341 * @brief Operator to access the element with the specified index key.
344 * @param[in] key The key whose value to access
346 * @return A reference to the value for the element with the specified key
348 * @note If an element with the key does not exist, then it is created.
350 Value& operator[]( Property::Index key );
353 * @brief Assignment Operator.
356 * @param[in] other The map to copy from
358 * @return The copied map
360 Map& operator=( const Map& other );
363 * @brief Output to stream.
366 friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
369 struct DALI_INTERNAL Impl; ///< Private data
370 Impl* mImpl; ///< Pointer to private data
374 * @brief Converts the key/value pairs of the property map into a string and append to an output stream.
377 * @param[in] stream The output stream operator
378 * @param[in] map The map to insert
379 * @return The output stream operator
381 DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
388 #endif // __DALI_PROPERTY_MAP_H__