e4ac80490270a16869b7f1391affa4452f0af086
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-array.h
1 #ifndef DALI_PROPERTY_ARRAY_H
2 #define DALI_PROPERTY_ARRAY_H
3
4 /*
5  * Copyright (c) 2019 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 /**
37  * @brief A Array of property values.
38  * @SINCE_1_0.0
39  */
40 class DALI_CORE_API Property::Array
41 {
42 public:
43
44   typedef std::size_t SizeType;
45
46   /**
47    * @brief Default constructor.
48    * @SINCE_1_0.0
49    */
50   Array();
51
52   /**
53    * @brief Copy Constructor.
54    *
55    * @SINCE_1_0.0
56    * @param[in] other The Array to copy from
57    */
58   Array( const Array& other );
59
60   /**
61    * @brief Move Constructor.
62    *
63    * @SINCE_1_4.17
64    * @param[in] other The Array to move from
65    * @note The other array is an r-value so becomes invalid and is no longer usable.
66    */
67   Array( Array&& other );
68
69   /**
70    * @brief Non-virtual destructor.
71    * @SINCE_1_0.0
72    */
73   ~Array();
74
75   /**
76    * @brief Retrieves the number of elements in the array.
77    *
78    * @SINCE_1_0.0
79    * @return The number of elements in the array
80    */
81   SizeType Size() const
82   {
83     return Count();
84   }
85
86   /**
87    * @brief Retrieves the number of elements in the array.
88    *
89    * @SINCE_1_0.0
90    * @return The number of elements in the array
91    */
92   SizeType Count() const;
93
94   /**
95    * @brief Returns whether the array is empty.
96    *
97    * @SINCE_1_0.0
98    * @return @c true if empty, @c false otherwise
99    */
100   bool Empty() const
101   {
102     return Count() == 0;
103   }
104
105   /**
106    * @brief Clears the array.
107    * @SINCE_1_0.0
108    */
109   void Clear();
110
111   /**
112    * @brief Increases the capacity of the array.
113    * @SINCE_1_0.0
114    * @param[in] size The size to reserve
115    */
116   void Reserve( SizeType size );
117
118   /**
119    * @brief Resizes to size.
120    * @SINCE_1_0.0
121    * @param[in] size The size to resize
122    */
123   void Resize( SizeType size );
124
125   /**
126    * @brief Retrieves the capacity of the array.
127    *
128    * @SINCE_1_0.0
129    * @return The allocated capacity of the array
130    */
131   SizeType Capacity();
132
133   /**
134    * @brief Adds an element to the array.
135    *
136    * @SINCE_1_0.0
137    * @param[in] value The value to add to the end of the array
138    */
139   void PushBack( const Value& value );
140
141   /**
142    * @brief Add an element to the array.
143    *
144    * @SINCE_1_2.11
145    * @param[in] value The value to add to the end of the array
146    * @return A reference to this object
147    */
148   inline Property::Array& Add( const Value& value )
149   {
150     PushBack( value );
151     return *this;
152   }
153
154   /**
155    * @brief Const access an element.
156    *
157    * @SINCE_1_0.0
158    * @param[in] index The element index to access. No bounds checking is performed
159    * @return The a reference to the element
160    */
161   const Value& GetElementAt( SizeType index ) const
162   {
163     return operator[]( index );
164   }
165
166   /**
167    * @brief Accesses an element.
168    *
169    * @SINCE_1_0.0
170    * @param[in] index The element index to access. No bounds checking is performed
171    * @return The a reference to the element
172    */
173   Value& GetElementAt( SizeType index )
174   {
175     return operator[]( index );
176   }
177
178   /**
179    * @brief Const operator to access an element.
180    *
181    * @SINCE_1_0.0
182    * @param[in] index The element index to access. No bounds checking is performed
183    * @return The a reference to the element
184    *
185    */
186   const Value& operator[]( SizeType index ) const;
187
188   /**
189    * @brief Operator to access an element.
190    *
191    * @SINCE_1_0.0
192    * @param[in] index The element index to access. No bounds checking is performed
193    * @return The a reference to the element
194    *
195    */
196   Value& operator[]( SizeType index );
197
198   /**
199    * @brief Assignment Operator.
200    *
201    * @SINCE_1_0.0
202    * @param[in] other The array to copy from
203    *
204    * @return The copied array.
205    */
206   Array& operator=( const Array& other );
207
208   /**
209    * @brief Move Assignment Operator.
210    *
211    * @SINCE_1_4.17
212    * @param[in] other The array to copy from
213    *
214    * @return The moved array.
215    *
216    * @note The other array is an r-value so becomes invalid and is no longer usable.
217    */
218   Array& operator=( Array&& other );
219
220   /**
221    * @brief Output to stream.
222    * @SINCE_1_1.28
223    */
224   friend DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Array& array );
225
226 private:
227   struct DALI_INTERNAL Impl; ///< Private data
228   Impl* mImpl; ///< Pointer to private data
229 };
230
231 /**
232  * @brief Converts the values of the property array into a string and append to an output stream.
233  *
234  * @SINCE_1_1.28
235  * @param[in] stream The output stream operator
236  * @param[in] array The array to insert
237  * @return The output stream operator
238  */
239 DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Array& array );
240
241 /**
242  * @}
243  */
244 } // namespace Dali
245
246 #endif // DALI_PROPERTY_ARRAY_H