1 #ifndef DALI_PROPERTY_MAP_H
2 #define DALI_PROPERTY_MAP_H
5 * Copyright (c) 2019 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.
24 #include <initializer_list>
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/object/property.h>
29 #include <dali/public-api/object/property-key.h>
30 #include <dali/public-api/object/property-value.h>
35 * @addtogroup dali_core_object
39 typedef std::pair< Property::Key, Property::Value > KeyValuePair;
40 typedef std::pair<std::string, Property::Value> StringValuePair;
43 * @brief A Map of property values, the key type could be String or Property::Index.
46 class DALI_CORE_API Property::Map
50 typedef std::size_t SizeType;
53 * @brief Default constructor.
59 * @brief Constructor from initializer_list.
62 * @param[in] values An initializer_list of pairs of index and value.
64 Map( const std::initializer_list< KeyValuePair >& values );
67 * @brief Copy Constructor.
70 * @param[in] other The Map to copy from
72 Map( const Map& other );
75 * @brief Move Constructor.
78 * @param[in] other The Map to move from
79 * @note The other array is an r-value so becomes invalid and is no longer usable.
84 * @brief Non-virtual destructor.
90 * @brief Retrieves the number of elements in the map.
93 * @return The number of elements in the map
95 SizeType Count() const;
98 * @brief Returns whether the map is empty.
101 * @return @c true if empty, @c false otherwise
106 * @brief Inserts the key-value pair in the Map, with the key type as string.
108 * Does not check for duplicates.
110 * @param[in] key The key to insert
111 * @param[in] value The value to insert
113 void Insert( const char* key, const Value& value );
116 * @brief Inserts the key-value pair in the Map, with the key type as string.
118 * Does not check for duplicates.
120 * @param[in] key The key to insert
121 * @param[in] value The value to insert
123 void Insert( const std::string& key, const Value& value );
126 * @brief Inserts the key-value pair in the Map, with the key type as index.
128 * Does not check for duplicates.
130 * @param[in] key The key to insert
131 * @param[in] value The value to insert
133 void Insert( Property::Index key, const Value& value );
137 * @brief Inserts the key-value pair in the Map, with the key type as string.
139 * Does not check for duplicates
141 * @param key to insert
142 * @param value to insert
143 * @return a reference to this object
145 inline Property::Map& Add( const char* key, const Value& value )
152 * @brief Inserts the key-value pair in the Map, with the key type as string.
154 * Does not check for duplicates
156 * @param key to insert
157 * @param value to insert
158 * @return a reference to this object
160 inline Property::Map& Add( const std::string& key, const Value& value )
168 * @brief Inserts the key-value pair in the Map, with the key type as index.
170 * Does not check for duplicates
172 * @param key to insert
173 * @param value to insert
174 * @return a reference to this object
176 inline Property::Map& Add( Property::Index key, const Value& value )
183 * @brief Retrieves the value at the specified position.
186 * @param[in] position The specified position
187 * @return A reference to the value at the specified position
189 * @note Will assert if position >= Count()
191 Value& GetValue( SizeType position ) const;
194 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
196 * @brief Retrieves the key at the specified position.
199 * @param[in] position The specified position
200 * @return A const reference to the key at the specified position
202 * @note Will assert if position >= Count()
204 const std::string& GetKey( SizeType position ) const DALI_DEPRECATED_API;
207 * @brief Retrieve the key at the specified position.
210 * @param[in] position The specified position
211 * @return A copy of the key at the specified position.
213 * @note Will assert if position >= Count()
215 Key GetKeyAt( SizeType position ) const;
218 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
220 * @brief Retrieves the key & the value at the specified position.
223 * @param[in] position The specified position
224 * @return A reference to the pair of key and value at the specified position
226 * @note Will assert if position >= Count() or key at position is an index key.
228 StringValuePair& GetPair( SizeType position ) const DALI_DEPRECATED_API;
231 * @brief Retrieve the key & the value at the specified position.
234 * @param[in] position The specified position
235 * @return A copy of the pair of key and value at the specified position.
237 * @note Will assert if position >= Count()
239 KeyValuePair GetKeyValue( SizeType position ) 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( const char* key ) const;
252 * @brief Finds the value for the specified key if it exists.
255 * @param[in] key The key to find
257 * @return A const pointer to the value if it exists, NULL otherwise
259 Value* Find( const std::string& key ) const;
262 * @brief Finds the value for the specified key if it exists.
265 * @param[in] key The key to find
267 * @return A const pointer to the value if it exists, NULL otherwise
269 Value* Find( Property::Index key ) const;
272 * @brief Finds the value for the specified keys if either exist.
274 * Will search for the index key first.
277 * @param[in] indexKey The index key to find
278 * @param[in] stringKey The string key to find
280 * @return A const pointer to the value if it exists, NULL otherwise
282 Value* Find( Property::Index indexKey, const std::string& stringKey ) const;
285 * @brief Finds the value for the specified key if it exists and its type is type.
288 * @param[in] key The key to find
289 * @param[in] type The type to check
291 * @return A const pointer to the value if it exists, NULL otherwise
293 Value* Find( const std::string& key, Property::Type type ) const;
296 * @brief Finds the value for the specified key if it exists and its type is type.
299 * @param[in] key The key to find
300 * @param[in] type The type to check
302 * @return A const pointer to the value if it exists, NULL otherwise
304 Value* Find( Property::Index key, Property::Type type ) const;
307 * @brief Clears the map.
313 * @brief Merges values from the map 'from' to the current.
315 * Any values in 'from' will overwrite the values in the current map.
318 * @param[in] from The map to merge from
320 void Merge( const Map& from );
323 * @brief Const operator to access element with the specified string key.
326 * @param[in] key The key whose value to access
328 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
330 * @note Will assert if invalid-key is given.
332 const Value& operator[]( const std::string& key ) const;
335 * @brief Operator to access the element with the specified string key.
338 * @param[in] key The key whose value to access
340 * @return A reference to the value for the element with the specified key
342 * @note If an element with the key does not exist, then it is created.
344 Value& operator[]( const std::string& key );
347 * @brief Const operator to access element with the specified index key.
350 * @param[in] key The key whose value to access
352 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
354 * @note Will assert if invalid-key is given.
356 const Value& operator[]( Property::Index key ) const;
359 * @brief Operator to access the element with the specified index key.
362 * @param[in] key The key whose value to access
364 * @return A reference to the value for the element with the specified key
366 * @note If an element with the key does not exist, then it is created.
368 Value& operator[]( Property::Index key );
371 * @brief Assignment Operator.
374 * @param[in] other The map to copy from
376 * @return The copied map
378 Map& operator=( const Map& other );
381 * @brief Move Assignment Operator.
384 * @param[in] other The map to move from
386 * @return The moved map
388 * @note The other array is an r-value so becomes invalid and is no longer usable.
390 Map& operator=( Map&& other );
393 * @brief Output to stream.
396 friend DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
399 struct DALI_INTERNAL Impl; ///< Private data
400 Impl* mImpl; ///< Pointer to private data
404 * @brief Converts the key/value pairs of the property map into a string and append to an output stream.
407 * @param[in] stream The output stream operator
408 * @param[in] map The map to insert
409 * @return The output stream operator
411 DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
418 #endif // DALI_PROPERTY_MAP_H