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 );
115 * DEPRECATED_1_1.39. Retrieve the value with key instead of position, Use Find( key ) instead.
117 * @brief Retrieve the value of the string-value pair at the specified position.
120 * @return A reference to the value at the specified position.
122 * @note Will assert if position >= Count()
124 Value& GetValue( SizeType position ) const;
127 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
129 * @brief Retrieve the key at the specified position.
132 * @return A const reference to the key at the specified position.
134 * @note Will assert if position >= Count()
136 const std::string& GetKey( SizeType position ) const;
139 * DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
141 * @brief Retrieve the key & the value at the specified position.
144 * @return A reference to the pair of key and value at the specified position.
146 * @note Will assert if position >= Count()
148 StringValuePair& GetPair( SizeType position ) const;
151 * @brief Finds the value for the specified key if it exists.
154 * @param[in] key The key to find.
156 * @return A const pointer to the value if it exists, NULL otherwise
158 Value* Find( const char* key ) const;
161 * @brief Finds the value for the specified key if it exists.
164 * @param[in] key The key to find.
166 * @return A const pointer to the value if it exists, NULL otherwise
168 Value* Find( const std::string& key ) const;
171 * @brief Finds the value for the specified key if it exists.
174 * @param[in] key The key to find.
176 * @return A const pointer to the value if it exists, NULL otherwise
178 Value* Find( Property::Index key ) const;
181 * @brief Finds the value for the specified key if it exists and its type is type
184 * @param[in] key The key to find.
185 * @param[in] type The type to check.
187 * @return A const pointer to the value if it exists, NULL otherwise
189 Value* Find( const std::string& key, Property::Type type ) const;
192 * @brief Finds the value for the specified key if it exists and its type is type
195 * @param[in] key The key to find.
196 * @param[in] type The type to check.
198 * @return A const pointer to the value if it exists, NULL otherwise
200 Value* Find( Property::Index key, Property::Type type ) const;
203 * @brief Clears the map.
209 * @brief Merges values from the map 'from' to the current.
211 * Any values in 'from' will overwrite the values in the current map.
214 * @param[in] from The map to merge from.
216 void Merge( const Map& from );
219 * @brief Const operator to access element with the specified string key.
222 * @param[in] key The key whose value to access.
224 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
226 * @note Will assert if invalid-key is given.
228 const Value& operator[]( const std::string& key ) const;
231 * @brief Operator to access the element with the specified string key.
234 * @param[in] key The key whose value to access.
236 * @return A reference to the value for the element with the specified key.
238 * @note If an element with the key does not exist, then it is created.
240 Value& operator[]( const std::string& key );
243 * @brief Const operator to access element with the specified index key.
246 * @param[in] key The key whose value to access.
248 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
250 * @note Will assert if invalid-key is given.
252 const Value& operator[]( Property::Index key ) const;
255 * @brief Operator to access the element with the specified index key.
258 * @param[in] key The key whose value to access.
260 * @return A reference to the value for the element with the specified key.
262 * @note If an element with the key does not exist, then it is created.
264 Value& operator[]( Property::Index key );
267 * @brief Assignment Operator
270 * @param[in] other The map to copy from.
272 * @return The copied map.
274 Map& operator=( const Map& other );
277 * @brief output to stream
280 friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
283 struct DALI_INTERNAL Impl; ///< Private data
284 Impl* mImpl; ///< Pointer to private data
288 * @brief Convert the key/value pairs of the property map into a string and append to an output stream.
291 * @param [in] stream The output stream operator.
292 * @param [in] map The map to insert
293 * @return The output stream operator.
295 DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
303 #endif // __DALI_PROPERTY_MAP_H__