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