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