[NUI] Remove duplicate getCPtr from Disposable/View subclasses (#3544)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Common / PropertyArray.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System.ComponentModel;
18
19 namespace Tizen.NUI
20 {
21     /// <summary>
22     /// An array of property values.
23     /// </summary>
24     /// <since_tizen> 3 </since_tizen>
25     public class PropertyArray : Disposable
26     {
27         /// <summary>
28         /// The constructor.
29         /// </summary>
30         /// <since_tizen> 3 </since_tizen>
31         public PropertyArray() : this(Interop.Property.NewPropertyArray(), true)
32         {
33             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
34         }
35
36         internal PropertyArray(PropertyArray other) : this(Interop.Property.NewPropertyArray(PropertyArray.getCPtr(other)), true)
37         {
38             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
39         }
40
41         internal PropertyArray(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
42         {
43         }
44
45         /// <summary>
46         /// The operator to access an element.
47         /// </summary>
48         /// <param name="index">The element index to access. No bounds checking is performed.</param>
49         /// <returns>The reference to the element.</returns>
50         /// <since_tizen> 3 </since_tizen>
51         public PropertyValue this[uint index]
52         {
53             get
54             {
55                 return ValueOfIndex(index);
56             }
57         }
58
59         /// <summary>
60         /// Retrieves the number of elements in the array.
61         /// </summary>
62         /// <returns>The number of elements in the array.</returns>
63         /// <since_tizen> 3 </since_tizen>
64         public uint Size()
65         {
66             uint ret = Interop.Property.ArraySize(SwigCPtr);
67             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
68             return ret;
69         }
70
71         /// <summary>
72         /// Retrieves the number of elements in the array.
73         /// </summary>
74         /// <returns>The number of elements in the array.</returns>
75         /// <since_tizen> 3 </since_tizen>
76         public uint Count()
77         {
78             uint ret = Interop.Property.ArrayCount(SwigCPtr);
79             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80             return ret;
81         }
82
83         /// <summary>
84         /// Returns whether the array is empty.
85         /// </summary>
86         /// <returns>Returns true if empty, false otherwise.</returns>
87         /// <since_tizen> 3 </since_tizen>
88         public bool Empty()
89         {
90             bool ret = Interop.Property.ArrayEmpty(SwigCPtr);
91             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92             return ret;
93         }
94
95         /// <summary>
96         /// Clears the array.
97         /// </summary>
98         /// <since_tizen> 3 </since_tizen>
99         public void Clear()
100         {
101             Interop.Property.ArrayClear(SwigCPtr);
102             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103         }
104
105         /// <summary>
106         /// Increases the capacity of the array.
107         /// </summary>
108         /// <param name="size">The size to reserve.</param>
109         /// <since_tizen> 3 </since_tizen>
110         public void Reserve(uint size)
111         {
112             Interop.Property.ArrayReserve(SwigCPtr, size);
113             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114         }
115
116         /// <summary>
117         /// Resizes to size.
118         /// </summary>
119         /// <param name="size">The size to resize</param>
120         /// <since_tizen> 3 </since_tizen>
121         public void Resize(uint size)
122         {
123             Interop.Property.ArrayResize(SwigCPtr, size);
124             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125         }
126
127         /// <summary>
128         /// Retrieves the capacity of the array.
129         /// </summary>
130         /// <returns>The allocated capacity of the array.</returns>
131         /// <since_tizen> 3 </since_tizen>
132         public uint Capacity()
133         {
134             uint ret = Interop.Property.ArrayCapacity(SwigCPtr);
135             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136             return ret;
137         }
138
139         /// <summary>
140         /// Adds an element to the array.
141         /// </summary>
142         /// <param name="value">The value to add at the end of the array.</param>
143         /// <since_tizen> 3 </since_tizen>
144         public void PushBack(PropertyValue value)
145         {
146             Interop.Property.ArrayPushBack(SwigCPtr, PropertyValue.getCPtr(value));
147             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148         }
149
150         /// <summary>
151         /// Adds an keyvalue to the array.
152         /// This function should be first
153         /// </summary>
154         /// <param name="value">The value to add at the end of the array.</param>
155         /// <exception cref="global::System.ArgumentNullException"> Thrown when value is null. </exception>
156         public PropertyArray Add(KeyValue value)
157         {
158             if (null == value)
159             {
160                 throw new global::System.ArgumentNullException(nameof(value));
161             }
162             PropertyArray ret = new PropertyArray(Interop.Property.ArrayAdd(SwigCPtr, PropertyValue.getCPtr(value.TrueValue)), false);
163             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164             return ret;
165         }
166
167         /// <summary>
168         /// Adds an element to the array.
169         /// </summary>
170         /// <param name="value">The value to add at the end of the array.</param>
171         /// <since_tizen> 3 </since_tizen>
172         public PropertyArray Add(PropertyValue value)
173         {
174             PropertyArray ret = new PropertyArray(Interop.Property.ArrayAdd(SwigCPtr, PropertyValue.getCPtr(value)), false);
175             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176             return ret;
177         }
178
179         /// <summary>
180         /// Accesses an element.
181         /// </summary>
182         /// <param name="index">The element index to access. No bounds checking is performed.</param>
183         /// <returns>The reference to the element.</returns>
184         /// <since_tizen> 3 </since_tizen>
185         public PropertyValue GetElementAt(uint index)
186         {
187             PropertyValue ret = new PropertyValue(Interop.Property.ArrayGetElementAt(SwigCPtr, index), false);
188             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189             return ret;
190         }
191
192         /// This will not be public opened.
193         [EditorBrowsable(EditorBrowsableState.Never)]
194         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
195         {
196             Interop.Property.DeletePropertyArray(swigCPtr);
197         }
198
199         /// <summary>
200         /// Retrieves the value of elements in the array.
201         /// </summary>
202         /// <param name="index">The element index to retrieve.</param>
203         /// <returns>The reference to the element.</returns>
204         private PropertyValue ValueOfIndex(uint index)
205         {
206             PropertyValue ret = new PropertyValue(Interop.Property.ArrayValueOfIndex(SwigCPtr, index), false);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208             return ret;
209         }
210     }
211 }