[NUI] Refactor dispose pattern to reduce duplication (#1112)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / ItemIdContainer.cs
1 /*
2  * Copyright(c) 2019 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.ComponentModel;
19
20 namespace Tizen.NUI
21 {
22     /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
23     [EditorBrowsable(EditorBrowsableState.Never)]
24     public class ItemIdContainer : Disposable, global::System.Collections.IEnumerable,
25         global::System.Collections.Generic.IList<uint>
26     {
27
28         internal ItemIdContainer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
29         {
30         }
31
32         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ItemIdContainer obj)
33         {
34             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
35         }
36
37         /// This will be public opened.
38         [EditorBrowsable(EditorBrowsableState.Never)]
39         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
40         {
41             Interop.ItemIdContainer.delete_ItemIdContainer(swigCPtr);
42         }
43
44         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
45         [EditorBrowsable(EditorBrowsableState.Never)]
46         public ItemIdContainer(global::System.Collections.ICollection c) : this()
47         {
48             if (c == null)
49                 throw new global::System.ArgumentNullException("c");
50             foreach (uint element in c)
51             {
52                 this.Add(element);
53             }
54         }
55
56         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
57         [EditorBrowsable(EditorBrowsableState.Never)]
58         public bool IsFixedSize
59         {
60             get
61             {
62                 return false;
63             }
64         }
65
66         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public bool IsReadOnly
69         {
70             get
71             {
72                 return false;
73             }
74         }
75
76         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
77         [EditorBrowsable(EditorBrowsableState.Never)]
78         public uint this[int index]
79         {
80             get
81             {
82                 return getitem(index);
83             }
84             set
85             {
86                 setitem(index, value);
87             }
88         }
89
90         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
91         [EditorBrowsable(EditorBrowsableState.Never)]
92         public int Capacity
93         {
94             get
95             {
96                 return (int)capacity();
97             }
98             set
99             {
100                 if (value < size())
101                     throw new global::System.ArgumentOutOfRangeException("Capacity");
102                 reserve((uint)value);
103             }
104         }
105
106         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
107         [EditorBrowsable(EditorBrowsableState.Never)]
108         public int Count
109         {
110             get
111             {
112                 return (int)size();
113             }
114         }
115
116         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
117         [EditorBrowsable(EditorBrowsableState.Never)]
118         public bool IsSynchronized
119         {
120             get
121             {
122                 return false;
123             }
124         }
125
126         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
127         [EditorBrowsable(EditorBrowsableState.Never)]
128         public void CopyTo(uint[] array)
129         {
130             CopyTo(0, array, 0, this.Count);
131         }
132
133         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
134         [EditorBrowsable(EditorBrowsableState.Never)]
135         public void CopyTo(uint[] array, int arrayIndex)
136         {
137             CopyTo(0, array, arrayIndex, this.Count);
138         }
139
140         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
141         [EditorBrowsable(EditorBrowsableState.Never)]
142         public void CopyTo(int index, uint[] array, int arrayIndex, int count)
143         {
144             if (array == null)
145                 throw new global::System.ArgumentNullException("array");
146             if (index < 0)
147                 throw new global::System.ArgumentOutOfRangeException("index", "Value is less than zero");
148             if (arrayIndex < 0)
149                 throw new global::System.ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
150             if (count < 0)
151                 throw new global::System.ArgumentOutOfRangeException("count", "Value is less than zero");
152             if (array.Rank > 1)
153                 throw new global::System.ArgumentException("Multi dimensional array.", "array");
154             if (index + count > this.Count || arrayIndex + count > array.Length)
155                 throw new global::System.ArgumentException("Number of elements to copy is too large.");
156             for (int i = 0; i < count; i++)
157                 array.SetValue(getitemcopy(index + i), arrayIndex + i);
158         }
159
160         global::System.Collections.Generic.IEnumerator<uint> global::System.Collections.Generic.IEnumerable<uint>.GetEnumerator()
161         {
162             return new ItemIdContainerEnumerator(this);
163         }
164
165         global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
166         {
167             return new ItemIdContainerEnumerator(this);
168         }
169
170         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
171         [EditorBrowsable(EditorBrowsableState.Never)]
172         public ItemIdContainerEnumerator GetEnumerator()
173         {
174             return new ItemIdContainerEnumerator(this);
175         }
176
177         // The type-safe enumerator.
178         /// Note that the IEnumerator documentation requires an InvalidOperationException to be thrown
179         /// whenever the collection is modified. This has been done for changes in the size of the
180         /// collection, but not when one of the elements of the collection is modified as it is a bit
181         /// tricky to detect unmanaged code that modifies the collection under our feet.
182         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
183         [EditorBrowsable(EditorBrowsableState.Never)]
184         public sealed class ItemIdContainerEnumerator : global::System.Collections.IEnumerator
185           , global::System.Collections.Generic.IEnumerator<uint>
186         {
187             private ItemIdContainer collectionRef;
188             private int currentIndex;
189             private object currentObject;
190             private int currentSize;
191
192             /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
193             [EditorBrowsable(EditorBrowsableState.Never)]
194             public ItemIdContainerEnumerator(ItemIdContainer collection)
195             {
196                 collectionRef = collection;
197                 currentIndex = -1;
198                 currentObject = null;
199                 currentSize = collectionRef.Count;
200             }
201
202             // Type-safe iterator Current
203             /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
204             [EditorBrowsable(EditorBrowsableState.Never)]
205             public uint Current
206             {
207                 get
208                 {
209                     if (currentIndex == -1)
210                         throw new global::System.InvalidOperationException("Enumeration not started.");
211                     if (currentIndex > currentSize - 1)
212                         throw new global::System.InvalidOperationException("Enumeration finished.");
213                     if (currentObject == null)
214                         throw new global::System.InvalidOperationException("Collection modified.");
215                     return (uint)currentObject;
216                 }
217             }
218
219             // Type-unsafe IEnumerator.Current
220             object global::System.Collections.IEnumerator.Current
221             {
222                 get
223                 {
224                     return Current;
225                 }
226             }
227
228             /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
229             [EditorBrowsable(EditorBrowsableState.Never)]
230             public bool MoveNext()
231             {
232                 int size = collectionRef.Count;
233                 bool moveOkay = (currentIndex + 1 < size) && (size == currentSize);
234                 if (moveOkay)
235                 {
236                     currentIndex++;
237                     currentObject = collectionRef[currentIndex];
238                 }
239                 else
240                 {
241                     currentObject = null;
242                 }
243                 return moveOkay;
244             }
245
246             /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
247             [EditorBrowsable(EditorBrowsableState.Never)]
248             public void Reset()
249             {
250                 currentIndex = -1;
251                 currentObject = null;
252                 if (collectionRef.Count != currentSize)
253                 {
254                     throw new global::System.InvalidOperationException("Collection modified.");
255                 }
256             }
257
258             /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
259             [EditorBrowsable(EditorBrowsableState.Never)]
260             public void Dispose()
261             {
262                 currentIndex = -1;
263                 currentObject = null;
264             }
265         }
266
267         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
268         [EditorBrowsable(EditorBrowsableState.Never)]
269         public void Clear()
270         {
271             Interop.ItemIdContainer.ItemIdContainer_Clear(swigCPtr);
272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273         }
274
275         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
276         [EditorBrowsable(EditorBrowsableState.Never)]
277         public void Add(uint x)
278         {
279             Interop.ItemIdContainer.ItemIdContainer_Add(swigCPtr, x);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281         }
282
283         private uint size()
284         {
285             uint ret = Interop.ItemIdContainer.ItemIdContainer_size(swigCPtr);
286             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287             return ret;
288         }
289
290         private uint capacity()
291         {
292             uint ret = Interop.ItemIdContainer.ItemIdContainer_capacity(swigCPtr);
293             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294             return ret;
295         }
296
297         private void reserve(uint n)
298         {
299             Interop.ItemIdContainer.ItemIdContainer_reserve(swigCPtr, n);
300             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301         }
302
303         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
304         [EditorBrowsable(EditorBrowsableState.Never)]
305         public ItemIdContainer() : this(Interop.ItemIdContainer.new_ItemIdContainer__SWIG_0(), true)
306         {
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308         }
309
310         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
311         [EditorBrowsable(EditorBrowsableState.Never)]
312         public ItemIdContainer(ItemIdContainer other) : this(Interop.ItemIdContainer.new_ItemIdContainer__SWIG_1(ItemIdContainer.getCPtr(other)), true)
313         {
314             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315         }
316
317         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
318         [EditorBrowsable(EditorBrowsableState.Never)]
319         public ItemIdContainer(int capacity) : this(Interop.ItemIdContainer.new_ItemIdContainer__SWIG_2(capacity), true)
320         {
321             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322         }
323
324         private uint getitemcopy(int index)
325         {
326             uint ret = Interop.ItemIdContainer.ItemIdContainer_getitemcopy(swigCPtr, index);
327             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328             return ret;
329         }
330
331         private uint getitem(int index)
332         {
333             uint ret = Interop.ItemIdContainer.ItemIdContainer_getitem(swigCPtr, index);
334             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335             return ret;
336         }
337
338         private void setitem(int index, uint val)
339         {
340             Interop.ItemIdContainer.ItemIdContainer_setitem(swigCPtr, index, val);
341             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342         }
343
344         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
345         [EditorBrowsable(EditorBrowsableState.Never)]
346         public void AddRange(ItemIdContainer values)
347         {
348             Interop.ItemIdContainer.ItemIdContainer_AddRange(swigCPtr, ItemIdContainer.getCPtr(values));
349             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350         }
351
352         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
353         [EditorBrowsable(EditorBrowsableState.Never)]
354         public ItemIdContainer GetRange(int index, int count)
355         {
356             global::System.IntPtr cPtr = Interop.ItemIdContainer.ItemIdContainer_GetRange(swigCPtr, index, count);
357             ItemIdContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new ItemIdContainer(cPtr, true);
358             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359             return ret;
360         }
361
362         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
363         [EditorBrowsable(EditorBrowsableState.Never)]
364         public void Insert(int index, uint x)
365         {
366             Interop.ItemIdContainer.ItemIdContainer_Insert(swigCPtr, index, x);
367             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368         }
369
370         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
371         [EditorBrowsable(EditorBrowsableState.Never)]
372         public void InsertRange(int index, ItemIdContainer values)
373         {
374             Interop.ItemIdContainer.ItemIdContainer_InsertRange(swigCPtr, index, ItemIdContainer.getCPtr(values));
375             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376         }
377
378         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
379         [EditorBrowsable(EditorBrowsableState.Never)]
380         public void RemoveAt(int index)
381         {
382             Interop.ItemIdContainer.ItemIdContainer_RemoveAt(swigCPtr, index);
383             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384         }
385
386         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
387         [EditorBrowsable(EditorBrowsableState.Never)]
388         public void RemoveRange(int index, int count)
389         {
390             Interop.ItemIdContainer.ItemIdContainer_RemoveRange(swigCPtr, index, count);
391             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392         }
393
394         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
395         [EditorBrowsable(EditorBrowsableState.Never)]
396         public static ItemIdContainer Repeat(uint value, int count)
397         {
398             global::System.IntPtr cPtr = Interop.ItemIdContainer.ItemIdContainer_Repeat(value, count);
399             ItemIdContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new ItemIdContainer(cPtr, true);
400             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401             return ret;
402         }
403
404         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
405         [EditorBrowsable(EditorBrowsableState.Never)]
406         public void Reverse()
407         {
408             Interop.ItemIdContainer.ItemIdContainer_Reverse__SWIG_0(swigCPtr);
409             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
410         }
411
412         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
413         [EditorBrowsable(EditorBrowsableState.Never)]
414         public void Reverse(int index, int count)
415         {
416             Interop.ItemIdContainer.ItemIdContainer_Reverse__SWIG_1(swigCPtr, index, count);
417             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418         }
419
420         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
421         [EditorBrowsable(EditorBrowsableState.Never)]
422         public void SetRange(int index, ItemIdContainer values)
423         {
424             Interop.ItemIdContainer.ItemIdContainer_SetRange(swigCPtr, index, ItemIdContainer.getCPtr(values));
425             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
426         }
427
428         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
429         [EditorBrowsable(EditorBrowsableState.Never)]
430         public bool Contains(uint value)
431         {
432             bool ret = Interop.ItemIdContainer.ItemIdContainer_Contains(swigCPtr, value);
433             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434             return ret;
435         }
436
437         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
438         [EditorBrowsable(EditorBrowsableState.Never)]
439         public int IndexOf(uint value)
440         {
441             int ret = Interop.ItemIdContainer.ItemIdContainer_IndexOf(swigCPtr, value);
442             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443             return ret;
444         }
445
446         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
447         [EditorBrowsable(EditorBrowsableState.Never)]
448         public int LastIndexOf(uint value)
449         {
450             int ret = Interop.ItemIdContainer.ItemIdContainer_LastIndexOf(swigCPtr, value);
451             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
452             return ret;
453         }
454
455         /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
456         [EditorBrowsable(EditorBrowsableState.Never)]
457         public bool Remove(uint value)
458         {
459             bool ret = Interop.ItemIdContainer.ItemIdContainer_Remove(swigCPtr, value);
460             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461             return ret;
462         }
463     }
464 }