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.
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.
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.
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 Retrieve the value at the specified position.
108 * @return A reference to the value at the specified position.
110 * @note Will assert if position >= Count()
112 Value& GetValue( SizeType position ) const;
115 * @brief Retrieve the key at the specified position.
118 * @return A const reference to the key at the specified position.
120 * @note Will assert if position >= Count()
122 const std::string& GetKey( SizeType position ) const;
125 * @brief Retrieve the key & the value at the specified position.
128 * @return A reference to the pair of key and value at the specified position.
130 * @note Will assert if position >= Count()
132 StringValuePair& GetPair( SizeType position ) const;
135 * @brief Finds the value for the specified key if it exists.
138 * @param[in] key The key to find.
140 * @return A const pointer to the value if it exists, NULL otherwise
142 Value* Find( const char* key ) const;
145 * @brief Finds the value for the specified key if it exists.
148 * @param[in] key The key to find.
150 * @return A const pointer to the value if it exists, NULL otherwise
152 Value* Find( const std::string& key ) const;
155 * @brief Finds the value for the specified key if it exists and its type is type
158 * @param[in] key The key to find.
159 * @param[in] type The type to check.
161 * @return A const pointer to the value if it exists, NULL otherwise
163 Value* Find( const std::string& key, Property::Type type ) const;
166 * @brief Clears the map.
172 * @brief Merges values from the map 'from' to the current.
174 * Any values in 'from' will overwrite the values in the current map.
177 * @param[in] from The map to merge from.
179 void Merge( const Map& from );
182 * @brief Const operator to access element with the specified key.
185 * @param[in] key The key whose value to access.
187 * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
189 * @note Will assert if invalid-key is given.
191 const Value& operator[]( const std::string& key ) const;
194 * @brief Operator to access the element with the specified key.
197 * @param[in] key The key whose value to access.
199 * @return A reference to the value for the element with the specified key.
201 * @note If an element with the key does not exist, then it is created.
203 Value& operator[]( const std::string& key );
206 * @brief Assignment Operator
209 * @param[in] other The map to copy from.
211 * @return The copied map.
213 Map& operator=( const Map& other );
216 * @brief output to stream
219 friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
222 struct DALI_INTERNAL Impl; ///< Private data
223 Impl* mImpl; ///< Pointer to private data
227 * @brief Convert the key/value pairs of the property map into a string and append to an output stream.
230 * @param [in] stream The output stream operator.
231 * @param [in] map The map to insert
232 * @return The output stream operator.
234 DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
242 #endif // __DALI_PROPERTY_MAP_H__