Check if the surfarce rect is changed
[platform/core/uifw/dali-core.git] / dali / internal / common / owner-pointer.h
index 758e7e6..e780920 100644 (file)
@@ -1,21 +1,25 @@
 #ifndef __DALI_INTERNAL_OWNER_POINTER_H__
 #define __DALI_INTERNAL_OWNER_POINTER_H__
 
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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) 2014 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.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <cstddef>    // NULL
 
 // INTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
@@ -34,8 +38,8 @@ public:
    * Default constructor. Creates an OwnerPointer that does not own any object.
    */
   OwnerPointer()
+  : mObject(NULL)
   {
-    mObject = NULL;
   }
 
   /**
@@ -43,17 +47,20 @@ public:
    * @param[in] object A pointer to a heap allocated object.
    */
   OwnerPointer( T* object )
+  : mObject(object)
   {
-    mObject = object;
   }
 
   /**
    * Copy constructor. Passes the ownership of a pointer to another.
    * @param[in] other The pointer that gives away the ownership.
    */
-  OwnerPointer( OwnerPointer& other )
+  OwnerPointer( const OwnerPointer& other )
+  : mObject(NULL)
   {
-    Init( other );
+    // other needs to be const for compiler to pick up this as copy constructor;
+    // though we are using this as move as there can only be one owner
+    Swap( const_cast<OwnerPointer&>( other ) );
   }
 
   /**
@@ -64,8 +71,8 @@ public:
   {
     if( this != &other )    // no self-assignment
     {
-      Reset();
-      Init( other );
+      // Creation of temportaty object to prevent premature deletion of object
+      OwnerPointer(other).Swap(*this);
     }
 
     // return self
@@ -174,11 +181,21 @@ public:
    * Returns a const pointer to the object owned.
    * @return a const pointer to the object.
    */
-  const T* Get()
+  const T* Get() const
   {
     return mObject;
   }
 
+  /**
+   * Swap owned objects
+   */
+  void Swap( OwnerPointer& other )
+  {
+    T* tmp = mObject;
+    mObject = other.mObject;
+    other.mObject = tmp;
+  }
+
   // Handle comparisons - This is a variation of the safe bool idiom
 
   /**
@@ -202,19 +219,6 @@ private:
    */
   void ThisIsSaferThanReturningVoidStar() const {}
 
-private:
-
-  /**
-   * Initialise this pointer from another one.
-   * ownerPointer parameter looses ownership.
-   * @param ownerPointer owner pointer
-   */
-  void Init( OwnerPointer& ownerPointer )
-  {
-    mObject = ownerPointer.mObject;
-    ownerPointer.mObject = NULL;
-  }
-
   // data
   T* mObject; ///< Raw pointer to the object
 };