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