Implemented the Handle assignment operators properly 78/25878/2
authorPaul Wisbey <p.wisbey@samsung.com>
Mon, 11 Aug 2014 17:10:30 +0000 (18:10 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Mon, 11 Aug 2014 17:14:37 +0000 (18:14 +0100)
[Problem] Some unsafe handle assignments are allowed by the compiler e.g.
Actor notAnImageActor = Actor::New();
ImageActor notSafeToUse = notAnImageActor;
[Cause] using BaseHandle::operator= is unsafe
[Solution] Implemented the Handle assignment operators properly

Change-Id: I0df98636a08f49afbf195f0ee9f7d4f7bdbfdc5a

adaptors/common/color-controller.cpp
adaptors/common/orientation.cpp
adaptors/common/style-monitor.cpp
adaptors/common/timer.cpp
adaptors/common/window.cpp
adaptors/public-api/color-controller.h
adaptors/public-api/orientation.h
adaptors/public-api/style-monitor.h
adaptors/public-api/timer.h
adaptors/public-api/window.h

index 29ad1fb..5ec6545 100644 (file)
@@ -33,6 +33,19 @@ ColorController::ColorController(const ColorController& controller)
 {
 }
 
+ColorController& ColorController::operator=(const ColorController& rhs)
+{
+  BaseHandle::operator=(rhs);
+  return *this;
+}
+
+ColorController& ColorController::operator=(BaseHandle::NullType* rhs)
+{
+  DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
+  Reset();
+  return *this;
+}
+
 ColorController ColorController::Get()
 {
   return Internal::Adaptor::ColorController::Get();
index 7843cd3..f276b66 100644 (file)
@@ -32,6 +32,24 @@ Orientation::~Orientation()
 {
 }
 
+Orientation::Orientation(const Orientation& handle)
+: BaseHandle(handle)
+{
+}
+
+Orientation& Orientation::operator=(const Orientation& rhs)
+{
+  BaseHandle::operator=(rhs);
+  return *this;
+}
+
+Orientation& Orientation::operator=(BaseHandle::NullType* rhs)
+{
+  DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
+  Reset();
+  return *this;
+}
+
 int Orientation::GetDegrees() const
 {
   return Internal::Adaptor::GetImplementation(*this).GetDegrees();
index cb2848b..5bb0e28 100644 (file)
@@ -81,6 +81,13 @@ StyleMonitor& StyleMonitor::operator=(const StyleMonitor& monitor)
   return *this;
 }
 
+StyleMonitor& StyleMonitor::operator=(BaseHandle::NullType* rhs)
+{
+  DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
+  Reset();
+  return *this;
+}
+
 StyleMonitor::StyleMonitor(Internal::Adaptor::StyleMonitor* internal)
 : BaseHandle(internal)
 {
index 5a1b940..3dd28bb 100644 (file)
@@ -52,6 +52,13 @@ Timer& Timer::operator=( const Timer& timer )
   return *this;
 }
 
+Timer& Timer::operator=(BaseHandle::NullType* rhs)
+{
+  DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
+  Reset();
+  return *this;
+}
+
 Timer::~Timer()
 {
 }
index 4883b8d..a020be9 100644 (file)
@@ -39,6 +39,24 @@ Window::~Window()
 {
 }
 
+Window::Window(const Window& handle)
+: BaseHandle(handle)
+{
+}
+
+Window& Window::operator=(const Window& rhs)
+{
+  BaseHandle::operator=(rhs);
+  return *this;
+}
+
+Window& Window::operator=(BaseHandle::NullType* rhs)
+{
+  DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
+  Reset();
+  return *this;
+}
+
 void Window::SetIndicatorStyle( IndicatorStyle style )
 {
   GetImplementation(*this).SetIndicatorStyle( style );
index a063d2c..5011a01 100644 (file)
@@ -54,9 +54,22 @@ public:
   ColorController( const ColorController& colorController);
 
   /**
-   * @copydoc Dali::BaseHandle::operator=
+   * @brief This assignment operator is required for (smart) pointer semantics.
+   *
+   * @param [in] rhs  A reference to the copied handle
+   * @return A reference to this
+   */
+  ColorController& operator=(const ColorController& rhs);
+
+  /**
+   * @brief This method is defined to allow assignment of the NULL value,
+   * and will throw an exception if passed any other value.
+   *
+   * Assigning to NULL is an alias for Reset().
+   * @param [in] rhs  A NULL pointer
+   * @return A reference to this handle
    */
-  using BaseHandle::operator=;
+  ColorController& operator=(BaseHandle::NullType* rhs);
 
   /**
    * @brief Retrieve the initialized instance of the ColorController.
index 2256538..c6a26a2 100644 (file)
@@ -68,10 +68,29 @@ public:
   ~Orientation();
 
   /**
-   * @copydoc Dali::BaseHandle::operator=
+   * @brief This copy constructor is required for (smart) pointer semantics.
+   *
+   * @param [in] handle A reference to the copied handle
+   */
+  Orientation(const Orientation& handle);
+
+  /**
+   * @brief This assignment operator is required for (smart) pointer semantics.
+   *
+   * @param [in] rhs  A reference to the copied handle
+   * @return A reference to this
    */
-  using BaseHandle::operator=;
+  Orientation& operator=(const Orientation& rhs);
 
+  /**
+   * @brief This method is defined to allow assignment of the NULL value,
+   * and will throw an exception if passed any other value.
+   *
+   * Assigning to NULL is an alias for Reset().
+   * @param [in] rhs  A NULL pointer
+   * @return A reference to this handle
+   */
+  Orientation& operator=(BaseHandle::NullType* rhs);
 
   /**
    * @brief Returns the orientation of the device in degrees.
index 24439c2..cf17124 100644 (file)
@@ -100,11 +100,6 @@ public: // Creation & Destruction
    */
   static StyleMonitor DownCast( BaseHandle handle );
 
-  /**
-   * @copydoc Dali::BaseHandle::operator=
-   */
-  using BaseHandle::operator=;
-
 public: // Style Information
 
   /**
@@ -155,6 +150,15 @@ public: // Operators
    */
   StyleMonitor& operator=(const StyleMonitor& monitor);
 
+  /**
+   * @brief This method is defined to allow assignment of the NULL value,
+   * and will throw an exception if passed any other value.
+   *
+   * Assigning to NULL is an alias for Reset().
+   * @param [in] rhs  A NULL pointer
+   * @return A reference to this handle
+   */
+  StyleMonitor& operator=(BaseHandle::NullType* rhs);
 
 public: // Not intended for application developers
   /**
index b8ebcf4..75a3775 100644 (file)
@@ -91,6 +91,16 @@ public: // API
   Timer& operator=( const Timer& timer );
 
   /**
+   * @brief This method is defined to allow assignment of the NULL value,
+   * and will throw an exception if passed any other value.
+   *
+   * Assigning to NULL is an alias for Reset().
+   * @param [in] rhs  A NULL pointer
+   * @return A reference to this handle
+   */
+  Timer& operator=(BaseHandle::NullType* rhs);
+
+  /**
    * @brief Destructor
    *
    * This is non-virtual since derived Handle types must not contain data or virtual methods.
@@ -109,11 +119,6 @@ public: // API
   static Timer DownCast( BaseHandle handle );
 
   /**
-   * @copydoc Dali::BaseHandle::operator=
-   */
-  using BaseHandle::operator=;
-
-  /**
    * @brief Start timer.
    *
    * In case a Timer is already running it's time is reset and timer is restarted.
index 82be3cd..e3833a7 100644 (file)
@@ -123,9 +123,29 @@ public:
   ~Window();
 
   /**
-   * @copydoc Dali::BaseHandle::operator=
+   * @brief This copy constructor is required for (smart) pointer semantics.
+   *
+   * @param [in] handle A reference to the copied handle
+   */
+  Window(const Window& handle);
+
+  /**
+   * @brief This assignment operator is required for (smart) pointer semantics.
+   *
+   * @param [in] rhs  A reference to the copied handle
+   * @return A reference to this
+   */
+  Window& operator=(const Window& rhs);
+
+  /**
+   * @brief This method is defined to allow assignment of the NULL value,
+   * and will throw an exception if passed any other value.
+   *
+   * Assigning to NULL is an alias for Reset().
+   * @param [in] rhs  A NULL pointer
+   * @return A reference to this handle
    */
-  using BaseHandle::operator=;
+  Window& operator=(BaseHandle::NullType* rhs);
 
   /**
    * @brief This sets the style of indicator