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.
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 Move Constructor.
69 * @param[in] other The Map to move from
70 * @note The other array is an r-value so becomes invalid and is no longer usable.
75 * @brief Non-virtual destructor.
81 * @brief Retrieves the number of elements in the map.
84 * @return The number of elements in the map
86 SizeType Count() const;
89 * @brief Returns whether the map is empty.
92 * @return @c true if empty, @c false otherwise
97 * @brief Inserts the key-value pair in the Map, with the key type as string.
99 * Does not check for duplicates.
101 * @param[in] key The key to insert
102 * @param[in] value The value to insert
104 void Insert( const char* key, const Value& value );
107 * @brief Inserts the key-value pair in the Map, with the key type as string.
109 * Does not check for duplicates.
111 * @param[in] key The key to insert
112 * @param[in] value The value to insert
114 void Insert( const std::string& key, const Value& value );
117 * @brief Inserts the key-value pair in the Map, with the key type as index.
119 * Does not check for duplicates.
121 * @param[in] key The key to insert
122 * @param[in] value The value to insert
124 void Insert( Property::Index key, const Value& value );
128 * @brief Inserts the key-value pair in the Map, with the key type as string.
130 * Does not check for duplicates
132 * @param key to insert
133 * @param value to insert
134 * @return a reference to this object
136 inline Property::Map& Add( const char* key, const Value& value )
143 * @brief Inserts the key-value pair in the Map, with the key type as string.
145 * Does not check for duplicates
147 * @param key to insert
148 * @param value to insert
149 * @return a reference to this object
151 inline Property::Map& Add( const std::string& key, const Value& value )
159 * @brief Inserts the key-value pair in the Map, with the key type as index.
161 * Does not check for duplicates
163 * @param key to insert
164 * @param value to insert
165 * @return a reference to this object
167 inline Property::Map& Add( Property::Index key, const Value& value )
174 * @brief Retrieves the value at the specified position.
177 * @param[in] position The specified position
178 * @return A reference to the value at the specified position
180 * @note Will assert if position >= Count()
182 Value& GetValue( SizeType position ) const;
185 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
187 * @brief Retrieves the key at the specified position.
190 * @param[in] position The specified position
191 * @return A const reference to the key at the specified position
193 * @note Will assert if position >= Count()
195 const std::string& GetKey( SizeType position ) const DALI_DEPRECATED_API;
198 * @brief Retrieve the key at the specified position.
201 * @param[in] position The specified position
202 * @return A copy of the key at the specified position.
204 * @note Will assert if position >= Count()
206 Key GetKeyAt( SizeType position ) const;
209 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
211 * @brief Retrieves the key & the value at the specified position.
214 * @param[in] position The specified position
215 * @return A reference to the pair of key and value at the specified position
217 * @note Will assert if position >= Count() or key at position is an index key.
219 StringValuePair& GetPair( SizeType position ) const DALI_DEPRECATED_API;
222 * @brief Retrieve the key & the value at the specified position.
225 * @param[in] position The specified position
226 * @return A copy of the pair of key and value at the specified position.
228 * @note Will assert if position >= Count()
230 KeyValuePair GetKeyValue( SizeType position ) const;
233 * @brief Finds the value for the specified key if it exists.
236 * @param[in] key The key to find
238 * @return A const pointer to the value if it exists, NULL otherwise
240 Value* Find( const char* key ) const;
243 * @brief Finds the value for the specified key if it exists.
246 * @param[in] key The key to find
248 * @return A const pointer to the value if it exists, NULL otherwise
250 Value* Find( const std::string& key ) const;
253 * @brief Finds the value for the specified key if it exists.
256 * @param[in] key The key to find
258 * @return A const pointer to the value if it exists, NULL otherwise
260 Value* Find( Property::Index key ) const;
263 * @brief Finds the value for the specified keys if either exist.
265 * Will search for the index key first.
268 * @param[in] indexKey The index key to find
269 * @param[in] stringKey The string key to find
271 * @return A const pointer to the value if it exists, NULL otherwise
273 Value* Find( Property::Index indexKey, const std::string& stringKey ) 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( const std::string& key, Property::Type type ) const;
287 * @brief Finds the value for the specified key if it exists and its type is type.
290 * @param[in] key The key to find
291 * @param[in] type The type to check
293 * @return A const pointer to the value if it exists, NULL otherwise
295 Value* Find( Property::Index key, Property::Type type ) const;
298 * @brief Clears the map.
304 * @brief Merges values from the map 'from' to the current.
306 * Any values in 'from' will overwrite the values in the current map.
309 * @param[in] from The map to merge from
311 void Merge( const Map& from );
314 * @brief Const operator to access element with the specified string key.
317 * @param[in] key The key whose value to access
319 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
321 * @note Will assert if invalid-key is given.
323 const Value& operator[]( const std::string& key ) const;
326 * @brief Operator to access the element with the specified string key.
329 * @param[in] key The key whose value to access
331 * @return A reference to the value for the element with the specified key
333 * @note If an element with the key does not exist, then it is created.
335 Value& operator[]( const std::string& key );
338 * @brief Const operator to access element with the specified index key.
341 * @param[in] key The key whose value to access
343 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
345 * @note Will assert if invalid-key is given.
347 const Value& operator[]( Property::Index key ) const;
350 * @brief Operator to access the element with the specified index key.
353 * @param[in] key The key whose value to access
355 * @return A reference to the value for the element with the specified key
357 * @note If an element with the key does not exist, then it is created.
359 Value& operator[]( Property::Index key );
362 * @brief Assignment Operator.
365 * @param[in] other The map to copy from
367 * @return The copied map
369 Map& operator=( const Map& other );
372 * @brief Move Assignment Operator.
375 * @param[in] other The map to move from
377 * @return The moved map
379 * @note The other array is an r-value so becomes invalid and is no longer usable.
381 Map& operator=( Map&& other );
384 * @brief Output to stream.
387 friend DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
390 struct DALI_INTERNAL Impl; ///< Private data
391 Impl* mImpl; ///< Pointer to private data
395 * @brief Converts the key/value pairs of the property map into a string and append to an output stream.
398 * @param[in] stream The output stream operator
399 * @param[in] map The map to insert
400 * @return The output stream operator
402 DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
409 #endif // DALI_PROPERTY_MAP_H