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