[NUI] Remove duplicate getCPtr from Disposable/View subclasses (#3544)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Common / TouchPointContainer.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
18 using System.Collections;
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
21
22 namespace Tizen.NUI
23 {
24     internal class TouchPointContainer : Disposable, IEnumerable, IEnumerable<TouchPoint>
25     {
26         internal TouchPointContainer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
27         {
28         }
29
30         protected override void ReleaseSwigCPtr(HandleRef swigCPtr)
31         {
32             Interop.TouchPointContainer.DeleteTouchPointContainer(swigCPtr);
33         }
34
35         public TouchPointContainer(ICollection c) : this()
36         {
37             if (c == null)
38                 throw new global::System.ArgumentNullException(nameof(c));
39             foreach (TouchPoint element in c)
40             {
41                 this.Add(element);
42             }
43         }
44
45         public bool IsFixedSize
46         {
47             get
48             {
49                 return false;
50             }
51         }
52
53         public bool IsReadOnly
54         {
55             get
56             {
57                 return false;
58             }
59         }
60
61         public TouchPoint this[int index]
62         {
63             get
64             {
65                 return getitem(index);
66             }
67             set
68             {
69                 setitem(index, value);
70             }
71         }
72
73         public int Capacity
74         {
75             get
76             {
77                 return (int)capacity();
78             }
79             set
80             {
81                 if (value < size())
82                     throw new global::System.ArgumentOutOfRangeException("Capacity");
83                 reserve((uint)value);
84             }
85         }
86
87         public int Count
88         {
89             get
90             {
91                 return (int)size();
92             }
93         }
94
95         public bool IsSynchronized
96         {
97             get
98             {
99                 return false;
100             }
101         }
102
103         public void CopyTo(TouchPoint[] array)
104         {
105             CopyTo(0, array, 0, this.Count);
106         }
107
108         public void CopyTo(TouchPoint[] array, int arrayIndex)
109         {
110             CopyTo(0, array, arrayIndex, this.Count);
111         }
112
113         public void CopyTo(int index, TouchPoint[] array, int arrayIndex, int count)
114         {
115             if (array == null)
116                 throw new global::System.ArgumentNullException(nameof(array));
117             if (index < 0)
118                 throw new global::System.ArgumentOutOfRangeException(nameof(index), "Value is less than zero");
119             if (arrayIndex < 0)
120                 throw new global::System.ArgumentOutOfRangeException(nameof(arrayIndex), "Value is less than zero");
121             if (count < 0)
122                 throw new global::System.ArgumentOutOfRangeException(nameof(count), "Value is less than zero");
123             if (array.Rank > 1)
124                 throw new global::System.ArgumentException("Multi dimensional array.", nameof(array));
125             if (index + count > this.Count || arrayIndex + count > array.Length)
126                 throw new global::System.ArgumentException("Number of elements to copy is too large.");
127             for (int i = 0; i < count; i++)
128                 array.SetValue(getitemcopy(index + i), arrayIndex + i);
129         }
130
131         IEnumerator<TouchPoint> IEnumerable<TouchPoint>.GetEnumerator()
132         {
133             return new TouchPointContainerEnumerator(this);
134         }
135
136         IEnumerator IEnumerable.GetEnumerator()
137         {
138             return new TouchPointContainerEnumerator(this);
139         }
140
141         public TouchPointContainerEnumerator GetEnumerator()
142         {
143             return new TouchPointContainerEnumerator(this);
144         }
145
146         // The type-safe enumerator.
147         /// Note that the IEnumerator documentation requires an InvalidOperationException to be thrown
148         /// whenever the collection is modified. This has been done for changes in the size of the
149         /// collection, but not when one of the elements of the collection is modified as it is a bit
150         /// tricky to detect unmanaged code that modifies the collection under our feet.
151         public sealed class TouchPointContainerEnumerator : IEnumerator, IEnumerator<TouchPoint>
152         {
153             private TouchPointContainer collectionRef;
154             private int currentIndex;
155             private object currentObject;
156             private int currentSize;
157
158             public TouchPointContainerEnumerator(TouchPointContainer collection)
159             {
160                 collectionRef = collection;
161                 currentIndex = -1;
162                 currentObject = null;
163                 currentSize = collectionRef.Count;
164             }
165
166             // Type-safe iterator Current
167             public TouchPoint Current
168             {
169                 get
170                 {
171                     if (currentIndex == -1)
172                         throw new global::System.InvalidOperationException("Enumeration not started.");
173                     if (currentIndex > currentSize - 1)
174                         throw new global::System.InvalidOperationException("Enumeration finished.");
175                     if (currentObject == null)
176                         throw new global::System.InvalidOperationException("Collection modified.");
177                     return (TouchPoint)currentObject;
178                 }
179             }
180
181             // Type-unsafe IEnumerator.Current
182             object global::System.Collections.IEnumerator.Current
183             {
184                 get
185                 {
186                     return Current;
187                 }
188             }
189
190             public bool MoveNext()
191             {
192                 int size = collectionRef.Count;
193                 bool moveOkay = (currentIndex + 1 < size) && (size == currentSize);
194                 if (moveOkay)
195                 {
196                     currentIndex++;
197                     currentObject = collectionRef[currentIndex];
198                 }
199                 else
200                 {
201                     currentObject = null;
202                 }
203                 return moveOkay;
204             }
205
206             public void Reset()
207             {
208                 currentIndex = -1;
209                 currentObject = null;
210                 if (collectionRef.Count != currentSize)
211                 {
212                     throw new global::System.InvalidOperationException("Collection modified.");
213                 }
214             }
215
216             public void Dispose()
217             {
218                 currentIndex = -1;
219                 currentObject = null;
220             }
221         }
222
223         public void Clear()
224         {
225             Interop.TouchPointContainer.Clear(SwigCPtr);
226             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227         }
228
229         public void Add(TouchPoint x)
230         {
231             Interop.TouchPointContainer.Add(SwigCPtr, TouchPoint.getCPtr(x));
232             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233         }
234
235         private uint size()
236         {
237             uint ret = Interop.TouchPointContainer.size(SwigCPtr);
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239             return ret;
240         }
241
242         private uint capacity()
243         {
244             uint ret = Interop.TouchPointContainer.capacity(SwigCPtr);
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246             return ret;
247         }
248
249         private void reserve(uint n)
250         {
251             Interop.TouchPointContainer.reserve(SwigCPtr, n);
252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253         }
254
255         public TouchPointContainer() : this(Interop.TouchPointContainer.NewTouchPointContainer(), true)
256         {
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258         }
259
260         public TouchPointContainer(TouchPointContainer other) : this(Interop.TouchPointContainer.NewTouchPointContainer(TouchPointContainer.getCPtr(other)), true)
261         {
262             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263         }
264
265         public TouchPointContainer(int capacity) : this(Interop.TouchPointContainer.NewTouchPointContainer(capacity), true)
266         {
267             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268         }
269
270         private TouchPoint getitemcopy(int index)
271         {
272             TouchPoint ret = new TouchPoint(Interop.TouchPointContainer.getitemcopy(SwigCPtr, index), true);
273             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274             return ret;
275         }
276
277         private TouchPoint getitem(int index)
278         {
279             TouchPoint ret = new TouchPoint(Interop.TouchPointContainer.getitem(SwigCPtr, index), false);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         private void setitem(int index, TouchPoint val)
285         {
286             Interop.TouchPointContainer.setitem(SwigCPtr, index, TouchPoint.getCPtr(val));
287             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288         }
289
290         public void AddRange(TouchPointContainer values)
291         {
292             Interop.TouchPointContainer.AddRange(SwigCPtr, TouchPointContainer.getCPtr(values));
293             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294         }
295
296         public TouchPointContainer GetRange(int index, int count)
297         {
298             global::System.IntPtr cPtr = Interop.TouchPointContainer.GetRange(SwigCPtr, index, count);
299             TouchPointContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TouchPointContainer(cPtr, true);
300             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301             return ret;
302         }
303
304         public void Insert(int index, TouchPoint x)
305         {
306             Interop.TouchPointContainer.Insert(SwigCPtr, index, TouchPoint.getCPtr(x));
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308         }
309
310         public void InsertRange(int index, TouchPointContainer values)
311         {
312             Interop.TouchPointContainer.InsertRange(SwigCPtr, index, TouchPointContainer.getCPtr(values));
313             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314         }
315
316         public void RemoveAt(int index)
317         {
318             Interop.TouchPointContainer.RemoveAt(SwigCPtr, index);
319             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320         }
321
322         public void RemoveRange(int index, int count)
323         {
324             Interop.TouchPointContainer.RemoveRange(SwigCPtr, index, count);
325             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326         }
327
328         public static TouchPointContainer Repeat(TouchPoint value, int count)
329         {
330             global::System.IntPtr cPtr = Interop.TouchPointContainer.Repeat(TouchPoint.getCPtr(value), count);
331             TouchPointContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TouchPointContainer(cPtr, true);
332             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333             return ret;
334         }
335
336         public void Reverse()
337         {
338             Interop.TouchPointContainer.Reverse(SwigCPtr);
339             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340         }
341
342         public void Reverse(int index, int count)
343         {
344             Interop.TouchPointContainer.Reverse(SwigCPtr, index, count);
345             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346         }
347
348         public void SetRange(int index, TouchPointContainer values)
349         {
350             Interop.TouchPointContainer.SetRange(SwigCPtr, index, TouchPointContainer.getCPtr(values));
351             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352         }
353     }
354 }