[NUI] Refactor dispose pattern to reduce duplication (#1112)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / VectorUint16Pair.cs
index ed9f24c..4ac5375 100755 (executable)
@@ -1,31 +1,27 @@
-/** Copyright (c) 2017 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-*/
+/*
+ * Copyright(c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 namespace Tizen.NUI
 {
-
-    internal class VectorUint16Pair : global::System.IDisposable
+    internal class VectorUint16Pair : Disposable
     {
-        private global::System.Runtime.InteropServices.HandleRef swigCPtr;
-        protected bool swigCMemOwn;
 
-        internal VectorUint16Pair(global::System.IntPtr cPtr, bool cMemoryOwn)
+        internal VectorUint16Pair(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
         {
-            swigCMemOwn = cMemoryOwn;
-            swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
 
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VectorUint16Pair obj)
@@ -33,93 +29,31 @@ namespace Tizen.NUI
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
         }
 
-        //A Flag to check who called Dispose(). (By User or DisposeQueue)
-        private bool isDisposeQueued = false;
-        //A Flat to check if it is already disposed.
-        protected bool disposed = false;
-
-
-        ~VectorUint16Pair()
-        {
-            if (!isDisposeQueued)
-            {
-                isDisposeQueued = true;
-                DisposeQueue.Instance.Add(this);
-            }
-        }
-
-        public void Dispose()
-        {
-            //Throw excpetion if Dispose() is called in separate thread.
-            if (!Window.IsInstalled())
-            {
-                throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
-            }
-
-            if (isDisposeQueued)
-            {
-                Dispose(DisposeTypes.Implicit);
-            }
-            else
-            {
-                Dispose(DisposeTypes.Explicit);
-                System.GC.SuppressFinalize(this);
-            }
-        }
-
-        protected virtual void Dispose(DisposeTypes type)
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
         {
-            if (disposed)
-            {
-                return;
-            }
-
-            if (type == DisposeTypes.Explicit)
-            {
-                //Called by User
-                //Release your own managed resources here.
-                //You should release all of your own disposable objects here.
-
-            }
-
-            //Release your own unmanaged resources here.
-            //You should not access any managed member here except static instance.
-            //because the execution order of Finalizes is non-deterministic.
-
-            if (swigCPtr.Handle != global::System.IntPtr.Zero)
-            {
-                if (swigCMemOwn)
-                {
-                    swigCMemOwn = false;
-                    NDalicPINVOKE.delete_VectorUint16Pair(swigCPtr);
-                }
-                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-            }
-
-            disposed = true;
+            Interop.VectorUint16Pair.delete_VectorUint16Pair(swigCPtr);
         }
 
-
-        public VectorUint16Pair() : this(NDalicPINVOKE.new_VectorUint16Pair__SWIG_0(), true)
+        public VectorUint16Pair() : this(Interop.VectorUint16Pair.new_VectorUint16Pair__SWIG_0(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        public VectorUint16Pair(VectorUint16Pair vector) : this(NDalicPINVOKE.new_VectorUint16Pair__SWIG_1(VectorUint16Pair.getCPtr(vector)), true)
+        public VectorUint16Pair(VectorUint16Pair vector) : this(Interop.VectorUint16Pair.new_VectorUint16Pair__SWIG_1(VectorUint16Pair.getCPtr(vector)), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public VectorUint16Pair Assign(VectorUint16Pair vector)
         {
-            VectorUint16Pair ret = new VectorUint16Pair(NDalicPINVOKE.VectorUint16Pair_Assign(swigCPtr, VectorUint16Pair.getCPtr(vector)), false);
+            VectorUint16Pair ret = new VectorUint16Pair(Interop.VectorUint16Pair.VectorUint16Pair_Assign(swigCPtr, VectorUint16Pair.getCPtr(vector)), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         public Uint16Pair Begin()
         {
-            global::System.IntPtr cPtr = NDalicPINVOKE.VectorUint16Pair_Begin(swigCPtr);
+            global::System.IntPtr cPtr = Interop.VectorUint16Pair.VectorUint16Pair_Begin(swigCPtr);
             Uint16Pair ret = (cPtr == global::System.IntPtr.Zero) ? null : new Uint16Pair(cPtr, false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
@@ -127,7 +61,7 @@ namespace Tizen.NUI
 
         public Uint16Pair End()
         {
-            global::System.IntPtr cPtr = NDalicPINVOKE.VectorUint16Pair_End(swigCPtr);
+            global::System.IntPtr cPtr = Interop.VectorUint16Pair.VectorUint16Pair_End(swigCPtr);
             Uint16Pair ret = (cPtr == global::System.IntPtr.Zero) ? null : new Uint16Pair(cPtr, false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
@@ -135,50 +69,50 @@ namespace Tizen.NUI
 
         public Uint16Pair ValueOfIndex(uint index)
         {
-            Uint16Pair ret = new Uint16Pair(NDalicPINVOKE.VectorUint16Pair_ValueOfIndex__SWIG_0(swigCPtr, index), false);
+            Uint16Pair ret = new Uint16Pair(Interop.VectorUint16Pair.VectorUint16Pair_ValueOfIndex__SWIG_0(swigCPtr, index), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         public void PushBack(Uint16Pair element)
         {
-            NDalicPINVOKE.VectorUint16Pair_PushBack(swigCPtr, Uint16Pair.getCPtr(element));
+            Interop.VectorUint16Pair.VectorUint16Pair_PushBack(swigCPtr, Uint16Pair.getCPtr(element));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Insert(Uint16Pair at, Uint16Pair element)
         {
-            NDalicPINVOKE.VectorUint16Pair_Insert__SWIG_0(swigCPtr, Uint16Pair.getCPtr(at), Uint16Pair.getCPtr(element));
+            Interop.VectorUint16Pair.VectorUint16Pair_Insert__SWIG_0(swigCPtr, Uint16Pair.getCPtr(at), Uint16Pair.getCPtr(element));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Insert(Uint16Pair at, Uint16Pair from, Uint16Pair to)
         {
-            NDalicPINVOKE.VectorUint16Pair_Insert__SWIG_1(swigCPtr, Uint16Pair.getCPtr(at), Uint16Pair.getCPtr(from), Uint16Pair.getCPtr(to));
+            Interop.VectorUint16Pair.VectorUint16Pair_Insert__SWIG_1(swigCPtr, Uint16Pair.getCPtr(at), Uint16Pair.getCPtr(from), Uint16Pair.getCPtr(to));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Reserve(uint count)
         {
-            NDalicPINVOKE.VectorUint16Pair_Reserve(swigCPtr, count);
+            Interop.VectorUint16Pair.VectorUint16Pair_Reserve(swigCPtr, count);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Resize(uint count)
         {
-            NDalicPINVOKE.VectorUint16Pair_Resize__SWIG_0(swigCPtr, count);
+            Interop.VectorUint16Pair.VectorUint16Pair_Resize__SWIG_0(swigCPtr, count);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Resize(uint count, Uint16Pair item)
         {
-            NDalicPINVOKE.VectorUint16Pair_Resize__SWIG_1(swigCPtr, count, Uint16Pair.getCPtr(item));
+            Interop.VectorUint16Pair.VectorUint16Pair_Resize__SWIG_1(swigCPtr, count, Uint16Pair.getCPtr(item));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public Uint16Pair Erase(Uint16Pair iterator)
         {
-            global::System.IntPtr cPtr = NDalicPINVOKE.VectorUint16Pair_Erase__SWIG_0(swigCPtr, Uint16Pair.getCPtr(iterator));
+            global::System.IntPtr cPtr = Interop.VectorUint16Pair.VectorUint16Pair_Erase__SWIG_0(swigCPtr, Uint16Pair.getCPtr(iterator));
             Uint16Pair ret = (cPtr == global::System.IntPtr.Zero) ? null : new Uint16Pair(cPtr, false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
@@ -186,7 +120,7 @@ namespace Tizen.NUI
 
         public Uint16Pair Erase(Uint16Pair first, Uint16Pair last)
         {
-            global::System.IntPtr cPtr = NDalicPINVOKE.VectorUint16Pair_Erase__SWIG_1(swigCPtr, Uint16Pair.getCPtr(first), Uint16Pair.getCPtr(last));
+            global::System.IntPtr cPtr = Interop.VectorUint16Pair.VectorUint16Pair_Erase__SWIG_1(swigCPtr, Uint16Pair.getCPtr(first), Uint16Pair.getCPtr(last));
             Uint16Pair ret = (cPtr == global::System.IntPtr.Zero) ? null : new Uint16Pair(cPtr, false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
@@ -194,30 +128,28 @@ namespace Tizen.NUI
 
         public void Remove(Uint16Pair iterator)
         {
-            NDalicPINVOKE.VectorUint16Pair_Remove(swigCPtr, Uint16Pair.getCPtr(iterator));
+            Interop.VectorUint16Pair.VectorUint16Pair_Remove(swigCPtr, Uint16Pair.getCPtr(iterator));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Swap(VectorUint16Pair vector)
         {
-            NDalicPINVOKE.VectorUint16Pair_Swap(swigCPtr, VectorUint16Pair.getCPtr(vector));
+            Interop.VectorUint16Pair.VectorUint16Pair_Swap(swigCPtr, VectorUint16Pair.getCPtr(vector));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Clear()
         {
-            NDalicPINVOKE.VectorUint16Pair_Clear(swigCPtr);
+            Interop.VectorUint16Pair.VectorUint16Pair_Clear(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Release()
         {
-            NDalicPINVOKE.VectorUint16Pair_Release(swigCPtr);
+            Interop.VectorUint16Pair.VectorUint16Pair_Release(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        public static readonly int BaseType = NDalicPINVOKE.VectorUint16Pair_BaseType_get();
-
+        public static readonly int BaseType = Interop.VectorUint16Pair.VectorUint16Pair_BaseType_get();
     }
-
 }