[dali_1.1.28] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-map.h
1 #ifndef __DALI_PROPERTY_MAP_H__
2 #define __DALI_PROPERTY_MAP_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
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>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_core_object
33  * @{
34  */
35
36 typedef std::pair<std::string, Property::Value> StringValuePair;
37
38 /**
39  * @brief A Map of property values.
40  * @SINCE_1_0.0
41  */
42 class DALI_IMPORT_API Property::Map
43 {
44 public:
45
46   typedef std::size_t SizeType;
47
48   /**
49    * @brief Default constructor.
50    * @SINCE_1_0.0
51    */
52   Map();
53
54   /**
55    * @brief Copy Constructor.
56    *
57    * @SINCE_1_0.0
58    * @param[in] other The Map to copy from.
59    */
60   Map( const Map& other );
61
62   /**
63    * @brief Non-virtual destructor.
64    * @SINCE_1_0.0
65    */
66   ~Map();
67
68   /**
69    * @brief Retrieve the number of elements in the map.
70    *
71    * @SINCE_1_0.0
72    * @return The number of elements in the map.
73    */
74   SizeType Count() const;
75
76   /**
77    * @brief Returns whether the map is empty.
78    *
79    * @SINCE_1_0.0
80    * @return true if empty, false otherwise
81    */
82   bool Empty() const;
83
84   /**
85    * @brief Inserts the key-value pair in the Map.
86    *
87    * Does not check for duplicates
88    * @SINCE_1_0.0
89    * @param key to insert
90    * @param value to insert
91    */
92   void Insert( const char* key, const Value& value );
93
94   /**
95    * @brief Inserts the key-value pair in the Map.
96    *
97    * Does not check for duplicates
98    * @SINCE_1_0.0
99    * @param key to insert
100    * @param value to insert
101    */
102   void Insert( const std::string& key, const Value& value );
103
104   /**
105    * @brief Retrieve the value at the specified position.
106    *
107    * @SINCE_1_0.0
108    * @return A reference to the value at the specified position.
109    *
110    * @note Will assert if position >= Count()
111    */
112   Value& GetValue( SizeType position ) const;
113
114   /**
115    * @brief Retrieve the key at the specified position.
116    *
117    * @SINCE_1_0.0
118    * @return A const reference to the key at the specified position.
119    *
120    * @note Will assert if position >= Count()
121    */
122   const std::string& GetKey( SizeType position ) const;
123
124   /**
125    * @brief Retrieve the key & the value at the specified position.
126    *
127    * @SINCE_1_0.0
128    * @return A reference to the pair of key and value at the specified position.
129    *
130    * @note Will assert if position >= Count()
131    */
132   StringValuePair& GetPair( SizeType position ) const;
133
134   /**
135    * @brief Finds the value for the specified key if it exists.
136    *
137    * @SINCE_1_0.0
138    * @param[in]  key   The key to find.
139    *
140    * @return A const pointer to the value if it exists, NULL otherwise
141    */
142   Value* Find( const char* key ) const;
143
144   /**
145    * @brief Finds the value for the specified key if it exists.
146    *
147    * @SINCE_1_0.0
148    * @param[in]  key   The key to find.
149    *
150    * @return A const pointer to the value if it exists, NULL otherwise
151    */
152   Value* Find( const std::string& key ) const;
153
154   /**
155    * @brief Finds the value for the specified key if it exists and its type is type
156    *
157    * @SINCE_1_0.0
158    * @param[in]  key   The key to find.
159    * @param[in]  type  The type to check.
160    *
161    * @return A const pointer to the value if it exists, NULL otherwise
162    */
163   Value* Find( const std::string& key, Property::Type type ) const;
164
165   /**
166    * @brief Clears the map.
167    * @SINCE_1_0.0
168    */
169   void Clear();
170
171   /**
172    * @brief Merges values from the map 'from' to the current.
173    *
174    * Any values in 'from' will overwrite the values in the current map.
175    *
176    * @SINCE_1_0.0
177    * @param[in]  from  The map to merge from.
178    */
179   void Merge( const Map& from );
180
181   /**
182    * @brief Const operator to access element with the specified key.
183    *
184    * @SINCE_1_0.0
185    * @param[in] key The key whose value to access.
186    *
187    * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
188    *
189    * @note Will assert if invalid-key is given.
190    */
191   const Value& operator[]( const std::string& key ) const;
192
193   /**
194    * @brief Operator to access the element with the specified key.
195    *
196    * @SINCE_1_0.0
197    * @param[in] key The key whose value to access.
198    *
199    * @return A reference to the value for the element with the specified key.
200    *
201    * @note If an element with the key does not exist, then it is created.
202    */
203   Value& operator[]( const std::string& key );
204
205   /**
206    * @brief Assignment Operator
207    *
208    * @SINCE_1_0.0
209    * @param[in] other The map to copy from.
210    *
211    * @return The copied map.
212    */
213   Map& operator=( const Map& other );
214
215   /**
216    * @brief output to stream
217    * @SINCE_1_1.28
218    */
219   friend std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
220
221 private:
222   struct DALI_INTERNAL Impl; ///< Private data
223   Impl* mImpl; ///< Pointer to private data
224 };
225
226 /**
227  * @brief Convert the key/value pairs of the property map into a string and append to an output stream.
228  *
229  * @SINCE_1_1.28
230  * @param [in] stream The output stream operator.
231  * @param [in] map The map to insert
232  * @return The output stream operator.
233  */
234 DALI_IMPORT_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
235
236
237 /**
238  * @}
239  */
240 } // namespace Dali
241
242 #endif // __DALI_PROPERTY_MAP_H__