331d1e934499918f4646ab2a6666e80ec441f46f
[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) 2018 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 Non-virtual destructor.
62    * @SINCE_1_0.0
63    */
64   ~Array();
65
66   /**
67    * @brief Retrieves the number of elements in the array.
68    *
69    * @SINCE_1_0.0
70    * @return The number of elements in the array
71    */
72   SizeType Size() const
73   {
74     return Count();
75   }
76
77   /**
78    * @brief Retrieves the number of elements in the array.
79    *
80    * @SINCE_1_0.0
81    * @return The number of elements in the array
82    */
83   SizeType Count() const;
84
85   /**
86    * @brief Returns whether the array is empty.
87    *
88    * @SINCE_1_0.0
89    * @return @c true if empty, @c false otherwise
90    */
91   bool Empty() const
92   {
93     return Count() == 0;
94   }
95
96   /**
97    * @brief Clears the array.
98    * @SINCE_1_0.0
99    */
100   void Clear();
101
102   /**
103    * @brief Increases the capacity of the array.
104    * @SINCE_1_0.0
105    * @param[in] size The size to reserve
106    */
107   void Reserve( SizeType size );
108
109   /**
110    * @brief Resizes to size.
111    * @SINCE_1_0.0
112    * @param[in] size The size to resize
113    */
114   void Resize( SizeType size );
115
116   /**
117    * @brief Retrieves the capacity of the array.
118    *
119    * @SINCE_1_0.0
120    * @return The allocated capacity of the array
121    */
122   SizeType Capacity();
123
124   /**
125    * @brief Adds an element to the array.
126    *
127    * @SINCE_1_0.0
128    * @param[in] value The value to add to the end of the array
129    */
130   void PushBack( const Value& value );
131
132   /**
133    * @brief Add an element to the array.
134    *
135    * @SINCE_1_2.11
136    * @param[in] value The value to add to the end of the array
137    * @return A reference to this object
138    */
139   inline Property::Array& Add( const Value& value )
140   {
141     PushBack( value );
142     return *this;
143   }
144
145   /**
146    * @brief Const access an element.
147    *
148    * @SINCE_1_0.0
149    * @param[in] index The element index to access. No bounds checking is performed
150    * @return The a reference to the element
151    */
152   const Value& GetElementAt( SizeType index ) const
153   {
154     return operator[]( index );
155   }
156
157   /**
158    * @brief Accesses an element.
159    *
160    * @SINCE_1_0.0
161    * @param[in] index The element index to access. No bounds checking is performed
162    * @return The a reference to the element
163    */
164   Value& GetElementAt( SizeType index )
165   {
166     return operator[]( index );
167   }
168
169   /**
170    * @brief Const operator to access an element.
171    *
172    * @SINCE_1_0.0
173    * @param[in] index The element index to access. No bounds checking is performed
174    * @return The a reference to the element
175    *
176    */
177   const Value& operator[]( SizeType index ) const;
178
179   /**
180    * @brief Operator to access an element.
181    *
182    * @SINCE_1_0.0
183    * @param[in] index The element index to access. No bounds checking is performed
184    * @return The a reference to the element
185    *
186    */
187   Value& operator[]( SizeType index );
188
189   /**
190    * @brief Assignment Operator.
191    *
192    * @SINCE_1_0.0
193    * @param[in] other The array to copy from
194    *
195    * @return The copied array.
196    */
197   Array& operator=( const Array& other );
198
199   /**
200    * @brief Output to stream.
201    * @SINCE_1_1.28
202    */
203   friend DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Array& array );
204
205 private:
206   struct DALI_INTERNAL Impl; ///< Private data
207   Impl* mImpl; ///< Pointer to private data
208 };
209
210 /**
211  * @brief Converts the values of the property array into a string and append to an output stream.
212  *
213  * @SINCE_1_1.28
214  * @param[in] stream The output stream operator
215  * @param[in] array The array to insert
216  * @return The output stream operator
217  */
218 DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Array& array );
219
220 /**
221  * @}
222  */
223 } // namespace Dali
224
225 #endif // __DALI_PROPERTY_ARRAY_H__