Merge branch 'devel/master' into devel/new_mesh
[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 typedef std::pair<std::string, Property::Value> StringValuePair;
32
33 /**
34  * @brief A Map of property values.
35  */
36 class DALI_IMPORT_API Property::Map
37 {
38 public:
39
40   typedef std::size_t SizeType;
41
42   /**
43    * @brief Default constructor.
44    */
45   Map();
46
47   /**
48    * @brief Copy Constructor.
49    *
50    * @param[in] other The Map to copy from.
51    */
52   Map( const Map& other );
53
54   /**
55    * @brief Non-virtual destructor.
56    */
57   ~Map();
58
59   /**
60    * @brief Retrieve the number of elements in the map.
61    *
62    * @return The number of elements in the map.
63    */
64   SizeType Count() const;
65
66   /**
67    * @brief Returns whether the map is empty.
68    *
69    * @return true if empty, false otherwise
70    */
71   bool Empty() const;
72
73   /**
74    * @brief Inserts the key-value pair in the Map.
75    *
76    * Does not check for duplicates
77    * @param key to insert
78    * @param value to insert
79    */
80   void Insert( const char* key, const Value& value );
81
82   /**
83    * @brief Inserts the key-value pair in the Map.
84    *
85    * Does not check for duplicates
86    * @param key to insert
87    * @param value to insert
88    */
89   void Insert( const std::string& key, const Value& value );
90
91   /**
92    * @brief Retrieve the value at the specified position.
93    *
94    * @return A reference to the value at the specified position.
95    *
96    * @note Will assert if position >= Count()
97    */
98   Value& GetValue( SizeType position ) const;
99
100   /**
101    * @brief Retrieve the key at the specified position.
102    *
103    * @return A const reference to the key at the specified position.
104    *
105    * @note Will assert if position >= Count()
106    */
107   const std::string& GetKey( SizeType position ) const;
108
109   /**
110    * @brief Retrieve the key & the value at the specified position.
111    *
112    * @return A reference to the pair of key and value at the specified position.
113    *
114    * @note Will assert if position >= Count()
115    */
116   StringValuePair& GetPair( SizeType position ) const;
117
118   /**
119    * @brief Finds the value for the specified key if it exists.
120    *
121    * @param[in]  key   The key to find.
122    *
123    * @return A const pointer to the value if it exists, NULL otherwise
124    */
125   Value* Find( const char* key ) const;
126
127   /**
128    * @brief Finds the value for the specified key if it exists.
129    *
130    * @param[in]  key   The key to find.
131    *
132    * @return A const pointer to the value if it exists, NULL otherwise
133    */
134   Value* Find( const std::string& key ) const;
135
136   /**
137    * @brief Finds the value for the specified key if it exists and its type is type
138    *
139    * @param[in]  key   The key to find.
140    * @param[in]  type  The type to check.
141    *
142    * @return A const pointer to the value if it exists, NULL otherwise
143    */
144   Value* Find( const std::string& key, Property::Type type ) const;
145
146   /**
147    * @brief Clears the map.
148    */
149   void Clear();
150
151   /**
152    * @brief Merges values from the map 'from' to the current.
153    *
154    * Any values in 'from' will overwrite the values in the current map.
155    *
156    * @param[in]  from  The map to merge from.
157    */
158   void Merge( const Map& from );
159
160   /**
161    * @brief Const operator to access element with the specified key.
162    *
163    * @param[in] key The key whose value to access.
164    *
165    * @return The value for the element with the specified key, if key doesn't exist, then Property::NONE is returned.
166    *
167    * @note Will assert if invalid-key is given.
168    */
169   const Value& operator[]( const std::string& key ) const;
170
171   /**
172    * @brief Operator to access the element with the specified key.
173    *
174    * @param[in] key The key whose value to access.
175    *
176    * @return A reference to the value for the element with the specified key.
177    *
178    * @note If an element with the key does not exist, then it is created.
179    */
180   Value& operator[]( const std::string& key );
181
182   /**
183    * @brief Assignment Operator
184    *
185    * @param[in] other The map to copy from.
186    *
187    * @return The copied map.
188    */
189   Map& operator=( const Map& other );
190
191 private:
192   struct DALI_INTERNAL Impl; ///< Private data
193   Impl* mImpl; ///< Pointer to private data
194 };
195
196 } // namespace Dali
197
198 #endif // __DALI_PROPERTY_MAP_H__