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