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.
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/property-value.h>
27 #include <dali/public-api/object/property.h>
32 * @addtogroup dali_core_object
36 typedef std::pair<std::string, Property::Value> StringValuePair;
39 * @brief A Map of property values, the key type could be String or Property::Index.
42 class DALI_IMPORT_API Property::Map
46 typedef std::size_t SizeType;
49 * @brief Default constructor.
55 * @brief Copy Constructor.
58 * @param[in] other The Map to copy from.
60 Map( const Map& other );
63 * @brief Non-virtual destructor.
69 * @brief Retrieve the number of elements in the map.
72 * @return The number of elements in the map.
74 SizeType Count() const;
77 * @brief Returns whether the map is empty.
80 * @return true if empty, false otherwise
85 * @brief Inserts the key-value pair in the Map, with the key type as string.
87 * Does not check for duplicates
89 * @param key to insert
90 * @param value to insert
92 void Insert( const char* key, const Value& value );
95 * @brief Inserts the key-value pair in the Map, with the key type as string.
97 * Does not check for duplicates
99 * @param key to insert
100 * @param value to insert
102 void Insert( const std::string& key, const Value& value );
105 * @brief Inserts the key-value pair in the Map, with the key type as index.
107 * Does not check for duplicates
109 * @param key to insert
110 * @param value to insert
112 void Insert( Property::Index 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 key to insert
121 * @param value to insert
122 * @return a reference to this object
124 inline Property::Map& Add( const char* key, const Value& value )
131 * @brief Inserts the key-value pair in the Map, with the key type as string.
133 * Does not check for duplicates
135 * @param key to insert
136 * @param value to insert
137 * @return a reference to this object
139 inline Property::Map& Add( const std::string& key, const Value& value )
147 * @brief Inserts the key-value pair in the Map, with the key type as index.
149 * Does not check for duplicates
151 * @param key to insert
152 * @param value to insert
153 * @return a reference to this object
155 inline Property::Map& Add( Property::Index key, const Value& value )
162 * DEPRECATED_1_1.39. Retrieve the value with key instead of position, Use Find( key ) instead.
164 * @brief Retrieve the value of the string-value pair at the specified position.
167 * @return A reference to the value at the specified position.
169 * @note Will assert if position >= Count()
171 Value& GetValue( SizeType position ) const;
174 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
176 * @brief Retrieve the key at the specified position.
179 * @return A const reference to the key at the specified position.
181 * @note Will assert if position >= Count()
183 const std::string& GetKey( SizeType position ) const;
186 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
188 * @brief Retrieve the key & the value at the specified position.
191 * @return A reference to the pair of key and value at the specified position.
193 * @note Will assert if position >= Count()
195 StringValuePair& GetPair( SizeType position ) const;
198 * @brief Finds the value for the specified key if it exists.
201 * @param[in] key The key to find.
203 * @return A const pointer to the value if it exists, NULL otherwise
205 Value* Find( const char* key ) const;
208 * @brief Finds the value for the specified key if it exists.
211 * @param[in] key The key to find.
213 * @return A const pointer to the value if it exists, NULL otherwise
215 Value* Find( const std::string& key ) const;
218 * @brief Finds the value for the specified key if it exists.
221 * @param[in] key The key to find.
223 * @return A const pointer to the value if it exists, NULL otherwise
225 Value* Find( Property::Index key ) const;
228 * @brief Finds the value for the specified keys if either exist.
230 * Will search for the index key first.
233 * @param[in] indexKey The index key to find.
234 * @param[in] stringKey The string key to find.
236 * @return A const pointer to the value if it exists, NULL otherwise
238 Value* Find( Property::Index indexKey, const std::string& stringKey ) const;
241 * @brief Finds the value for the specified key if it exists and its type is type
244 * @param[in] key The key to find.
245 * @param[in] type The type to check.
247 * @return A const pointer to the value if it exists, NULL otherwise
249 Value* Find( const std::string& key, Property::Type type ) const;
252 * @brief Finds the value for the specified key if it exists and its type is type
255 * @param[in] key The key to find.
256 * @param[in] type The type to check.
258 * @return A const pointer to the value if it exists, NULL otherwise
260 Value* Find( Property::Index key, Property::Type type ) const;
263 * @brief Clears the map.
269 * @brief Merges values from the map 'from' to the current.
271 * Any values in 'from' will overwrite the values in the current map.
274 * @param[in] from The map to merge from.
276 void Merge( const Map& from );
279 * @brief Const operator to access element with the specified string key.
282 * @param[in] key The key whose value to access.
284 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
286 * @note Will assert if invalid-key is given.
288 const Value& operator[]( const std::string& key ) const;
291 * @brief Operator to access the element with the specified string key.
294 * @param[in] key The key whose value to access.
296 * @return A reference to the value for the element with the specified key.
298 * @note If an element with the key does not exist, then it is created.
300 Value& operator[]( const std::string& key );
303 * @brief Const operator to access element with the specified index 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[]( Property::Index key ) const;
315 * @brief Operator to access the element with the specified index 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[]( Property::Index key );
327 * @brief Assignment Operator
330 * @param[in] other The map to copy from.
332 * @return The copied map.
334 Map& operator=( const Map& other );
337 * @brief output to stream
340 friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
343 struct DALI_INTERNAL Impl; ///< Private data
344 Impl* mImpl; ///< Pointer to private data
348 * @brief Convert the key/value pairs of the property map into a string and append to an output stream.
351 * @param [in] stream The output stream operator.
352 * @param [in] map The map to insert
353 * @return The output stream operator.
355 DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
363 #endif // __DALI_PROPERTY_MAP_H__