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 Retrieves 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 @c true if empty, @c 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[in] key The key to insert
90 * @param[in] value The 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[in] key The key to insert
100 * @param[in] value The 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[in] key The key to insert
110 * @param[in] value The value to insert
112 void Insert( Property::Index key, const Value& value );
115 * DEPRECATED_1_1.39. Retrieve the value with key instead of position, Use Find( key ) instead.
117 * @brief Retrieves the value of the string-value pair at the specified position.
120 * @param[in] position The specified position
121 * @return A reference to the value at the specified position
123 * @note Will assert if position >= Count()
125 Value& GetValue( SizeType position ) const;
128 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
130 * @brief Retrieves the key at the specified position.
133 * @param[in] position The specified position
134 * @return A const reference to the key at the specified position
136 * @note Will assert if position >= Count()
138 const std::string& GetKey( SizeType position ) const DALI_DEPRECATED_API;
141 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
143 * @brief Retrieves the key & the value at the specified position.
146 * @param[in] position The specified position
147 * @return A reference to the pair of key and value at the specified position
149 * @note Will assert if position >= Count() or key at position is an index key.
151 StringValuePair& GetPair( SizeType position ) const DALI_DEPRECATED_API;
154 * @brief Finds the value for the specified key if it exists.
157 * @param[in] key The key to find
159 * @return A const pointer to the value if it exists, NULL otherwise
161 Value* Find( const char* key ) const;
164 * @brief Finds the value for the specified key if it exists.
167 * @param[in] key The key to find
169 * @return A const pointer to the value if it exists, NULL otherwise
171 Value* Find( const std::string& key ) const;
174 * @brief Finds the value for the specified key if it exists.
177 * @param[in] key The key to find
179 * @return A const pointer to the value if it exists, NULL otherwise
181 Value* Find( Property::Index key ) const;
184 * @brief Finds the value for the specified keys if either exist.
186 * Will search for the index key first.
189 * @param[in] indexKey The index key to find
190 * @param[in] stringKey The string key to find
192 * @return A const pointer to the value if it exists, NULL otherwise
194 Value* Find( Property::Index indexKey, const std::string& stringKey ) const;
197 * @brief Finds the value for the specified key if it exists and its type is type.
200 * @param[in] key The key to find
201 * @param[in] type The type to check
203 * @return A const pointer to the value if it exists, NULL otherwise
205 Value* Find( const std::string& key, Property::Type type ) const;
208 * @brief Finds the value for the specified key if it exists and its type is type.
211 * @param[in] key The key to find
212 * @param[in] type The type to check
214 * @return A const pointer to the value if it exists, NULL otherwise
216 Value* Find( Property::Index key, Property::Type type ) const;
219 * @brief Clears the map.
225 * @brief Merges values from the map 'from' to the current.
227 * Any values in 'from' will overwrite the values in the current map.
230 * @param[in] from The map to merge from
232 void Merge( const Map& from );
235 * @brief Const operator to access element with the specified string key.
238 * @param[in] key The key whose value to access
240 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
242 * @note Will assert if invalid-key is given.
244 const Value& operator[]( const std::string& key ) const;
247 * @brief Operator to access the element with the specified string key.
250 * @param[in] key The key whose value to access
252 * @return A reference to the value for the element with the specified key
254 * @note If an element with the key does not exist, then it is created.
256 Value& operator[]( const std::string& key );
259 * @brief Const operator to access element with the specified index key.
262 * @param[in] key The key whose value to access
264 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned
266 * @note Will assert if invalid-key is given.
268 const Value& operator[]( Property::Index key ) const;
271 * @brief Operator to access the element with the specified index key.
274 * @param[in] key The key whose value to access
276 * @return A reference to the value for the element with the specified key
278 * @note If an element with the key does not exist, then it is created.
280 Value& operator[]( Property::Index key );
283 * @brief Assignment Operator.
286 * @param[in] other The map to copy from
288 * @return The copied map
290 Map& operator=( const Map& other );
293 * @brief Output to stream.
296 friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
299 struct DALI_INTERNAL Impl; ///< Private data
300 Impl* mImpl; ///< Pointer to private data
304 * @brief Converts the key/value pairs of the property map into a string and append to an output stream.
307 * @param[in] stream The output stream operator
308 * @param[in] map The map to insert
309 * @return The output stream operator
311 DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
319 #endif // __DALI_PROPERTY_MAP_H__