[dali_1.9.14] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-value.cpp
index ffd0f70..7132bfb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -22,6 +22,7 @@
 #include <ostream>
 
 // INTERNAL INCLUDES
+#include <dali/public-api/common/extents.h>
 #include <dali/public-api/math/angle-axis.h>
 #include <dali/public-api/math/radian.h>
 #include <dali/public-api/math/vector2.h>
@@ -52,11 +53,6 @@ inline bool IsIntegerType( Property::Type type )
 
 struct Property::Value::Impl
 {
-  Impl()
-  : type( Property::NONE ),
-    integerValue( 0 )
-  { }
-
   Impl( bool booleanValue )
   : type( Property::BOOLEAN ),
     integerValue( booleanValue )
@@ -67,7 +63,7 @@ struct Property::Value::Impl
     floatValue( floatValue )
   { }
 
-  Impl( int integerValue )
+  Impl( int32_t integerValue )
   : type( Property::INTEGER ),
     integerValue( integerValue )
   { }
@@ -112,30 +108,60 @@ struct Property::Value::Impl
     quaternionValue.ToAxisAngle( angleAxisValue->axis, angleAxisValue->angle );
   }
 
-  Impl(const std::string& stringValue)
+  Impl( const std::string& stringValue )
   : type( Property::STRING ),
     stringValue( new std::string( stringValue ) )
   {
   }
 
-  Impl( const Rect<int>& rectValue )
+  Impl( const Rect<int32_t>& rectValue )
   : type( Property::RECTANGLE ),
     rectValue( new Rect<int>( rectValue ) )
   {
   }
 
+  Impl( const Rect<float>& rectValue )
+  : type( Property::VECTOR4 ),
+    vector4Value( new Vector4( rectValue.x, rectValue.y, rectValue.width, rectValue.height ) )
+  {
+  }
+
   Impl( const Property::Array& arrayValue )
   : type( Property::ARRAY ),
     arrayValue( new Property::Array( arrayValue ) )
   {
   }
 
+  Impl( Property::Array&& arrayValue )
+  : type( Property::ARRAY ),
+    arrayValue( new Property::Array( std::move( arrayValue ) ) )
+  {
+  }
+
   Impl( const Property::Map& mapValue )
   : type( Property::MAP ),
     mapValue( new Property::Map( mapValue ) )
   {
   }
 
+  Impl( Property::Map&& mapValue )
+  : type( Property::MAP ),
+    mapValue( new Property::Map( std::move( mapValue ) ) )
+  {
+  }
+
+  Impl( const Extents& extentsValue )
+  : type( Property::EXTENTS ),
+    extentsValue( new Extents( extentsValue ) )
+  {
+  }
+
+  Impl( const std::initializer_list< KeyValuePair >& values )
+  : type( Property::MAP ),
+    mapValue( new Property::Map( values ) )
+  {
+  }
+
   /**
    * Destructor, takes care of releasing the dynamically allocated types
    */
@@ -200,6 +226,11 @@ struct Property::Value::Impl
         delete mapValue;
         break;
       }
+      case Property::EXTENTS:
+      {
+        delete extentsValue;
+        break;
+      }
     }
   }
 
@@ -208,7 +239,7 @@ public: // Data
   Type type;
   union
   {
-    int integerValue;
+    int32_t integerValue;
     float floatValue;
     // must use pointers for any class value pre c++ 11
     Vector2* vector2Value;
@@ -218,14 +249,22 @@ public: // Data
     Matrix* matrixValue;
     AngleAxis* angleAxisValue;
     std::string* stringValue;
-    Rect<int>* rectValue;
+    Rect<int32_t>* rectValue;
     Property::Array* arrayValue;
     Property::Map* mapValue;
+    Extents* extentsValue;
   };
+
+private:
+
+  // non-copyable
+  Impl( const Impl& ) = delete;
+  Impl& operator=( const Impl& ) = delete;
+
 };
 
 Property::Value::Value()
-: mImpl( NULL )
+: mImpl( nullptr )
 {
 }
 
@@ -239,7 +278,7 @@ Property::Value::Value( float floatValue )
 {
 }
 
-Property::Value::Value( int integerValue )
+Property::Value::Value( int32_t integerValue )
 : mImpl( new Impl( integerValue ) )
 {
 }
@@ -269,7 +308,12 @@ Property::Value::Value( const Matrix& matrixValue )
 {
 }
 
-Property::Value::Value( const Rect<int>& rectValue )
+Property::Value::Value( const Rect<int32_t>& rectValue )
+: mImpl( new Impl( rectValue ) )
+{
+}
+
+Property::Value::Value( const Rect<float>& rectValue )
 : mImpl( new Impl( rectValue ) )
 {
 }
@@ -290,9 +334,9 @@ Property::Value::Value( const std::string& stringValue )
 }
 
 Property::Value::Value( const char* stringValue )
-: mImpl( NULL )
+: mImpl( nullptr )
 {
-  if( stringValue ) // string constructor is undefined with NULL pointer
+  if( stringValue ) // string constructor is undefined with nullptr
   {
     mImpl = new Impl( std::string(stringValue) );
   }
@@ -307,12 +351,33 @@ Property::Value::Value( Property::Array& arrayValue )
 {
 }
 
+Property::Value::Value( Property::Array&& arrayValue )
+: mImpl( new Impl( std::move( arrayValue ) ) )
+{
+}
+
 Property::Value::Value( Property::Map& mapValue )
 : mImpl( new Impl( mapValue ) )
 {
 }
 
+Property::Value::Value( Property::Map&& mapValue )
+: mImpl( new Impl( std::move( mapValue ) ) )
+{
+}
+
+Property::Value::Value( const Extents& extentsValue )
+: mImpl( new Impl( extentsValue ) )
+{
+}
+
+Property::Value::Value( const std::initializer_list< KeyValuePair >& values )
+: mImpl( new Impl( values ) )
+{
+}
+
 Property::Value::Value( Type type )
+: mImpl( nullptr )
 {
   switch (type)
   {
@@ -348,7 +413,7 @@ Property::Value::Value( Type type )
     }
     case Property::RECTANGLE:
     {
-      mImpl = new Impl( Rect<int>(0,0,0,0) );
+      mImpl = new Impl( Rect<int32_t>(0,0,0,0) );
       break;
     }
     case Property::ROTATION:
@@ -381,21 +446,32 @@ Property::Value::Value( Type type )
       mImpl = new Impl( Property::Map() );
       break;
     }
+    case Property::EXTENTS:
+    {
+      mImpl = new Impl( Extents() );
+      break;
+    }
     case Property::NONE:
     {
-      mImpl = new Impl();
+      // No need to create an Impl
       break;
     }
   }
 }
 
 Property::Value::Value( const Property::Value& value )
-: mImpl( NULL )
+: mImpl( nullptr )
 {
   // reuse assignment operator
   operator=( value );
 }
 
+Property::Value::Value( Property::Value&& value )
+: mImpl( value.mImpl )
+{
+  value.mImpl = nullptr;
+}
+
 Property::Value& Property::Value::operator=( const Property::Value& value )
 {
   if ( this == &value )
@@ -407,7 +483,7 @@ Property::Value& Property::Value::operator=( const Property::Value& value )
   if( !value.mImpl )
   {
     delete mImpl;
-    mImpl = NULL;
+    mImpl = nullptr;
     return *this;
   }
   // first check if the type is the same, no need to change impl, just assign
@@ -480,15 +556,20 @@ Property::Value& Property::Value::operator=( const Property::Value& value )
         *mImpl->mapValue = *value.mImpl->mapValue; // type cannot change in mImpl so map is allocated
         break;
       }
+      case Property::EXTENTS:
+      {
+        *mImpl->extentsValue = *value.mImpl->extentsValue; // type cannot change in mImpl so extents is allocated
+        break;
+      }
       case Property::NONE:
-      { // mImpl will be NULL, there's no way to get to this case
+      { // mImpl will be a nullptr, there's no way to get to this case
       }
     }
   }
   else
   {
     // different type, release old impl and create new
-    Impl* newImpl( NULL );
+    Impl* newImpl( nullptr );
     switch ( value.mImpl->type )
     {
       case Property::BOOLEAN:
@@ -556,8 +637,13 @@ Property::Value& Property::Value::operator=( const Property::Value& value )
         newImpl = new Impl( *value.mImpl->mapValue ); // type cannot change in mImpl so map is allocated
         break;
       }
+      case Property::EXTENTS:
+      {
+        newImpl = new Impl( *value.mImpl->extentsValue ); // type cannot change in mImpl so extents is allocated
+        break;
+      }
       case Property::NONE:
-      { // NULL value will be used for "empty" value
+      { // nullptr value will be used for "empty" value
       }
     }
     delete mImpl;
@@ -567,6 +653,18 @@ Property::Value& Property::Value::operator=( const Property::Value& value )
   return *this;
 }
 
+Property::Value& Property::Value::operator=( Property::Value&& value )
+{
+  if( this != &value )
+  {
+    delete mImpl;
+    mImpl = value.mImpl;
+    value.mImpl = nullptr;
+  }
+
+  return *this;
+}
+
 Property::Value::~Value()
 {
   delete mImpl;
@@ -612,7 +710,7 @@ bool Property::Value::Get( float& floatValue ) const
   return converted;
 }
 
-bool Property::Value::Get( int& integerValue ) const
+bool Property::Value::Get( int32_t& integerValue ) const
 {
   bool converted = false;
   if( mImpl )
@@ -624,7 +722,7 @@ bool Property::Value::Get( int& integerValue ) const
     }
     else if( mImpl->type == FLOAT )
     {
-      integerValue = static_cast< int >( mImpl->floatValue );
+      integerValue = static_cast< int32_t >( mImpl->floatValue );
       converted = true;
     }
   }
@@ -712,7 +810,7 @@ bool Property::Value::Get( Matrix& matrixValue ) const
   return converted;
 }
 
-bool Property::Value::Get( Rect<int>& rectValue ) const
+bool Property::Value::Get( Rect<int32_t>& rectValue ) const
 {
   bool converted = false;
   if( mImpl && (mImpl->type == RECTANGLE) ) // type cannot change in mImpl so rect is allocated
@@ -780,7 +878,7 @@ bool Property::Value::Get( Property::Map& mapValue ) const
 
 Property::Array* Property::Value::GetArray() const
 {
-  Property::Array* array = NULL;
+  Property::Array* array = nullptr;
   if( mImpl && (mImpl->type == ARRAY) ) // type cannot change in mImpl so array is allocated
   {
     array = mImpl->arrayValue;
@@ -790,7 +888,7 @@ Property::Array* Property::Value::GetArray() const
 
 Property::Map* Property::Value::GetMap() const
 {
-  Property::Map* map = NULL;
+  Property::Map* map = nullptr;
   if( mImpl && (mImpl->type == MAP) ) // type cannot change in mImpl so map is allocated
   {
     map = mImpl->mapValue;
@@ -798,6 +896,28 @@ Property::Map* Property::Value::GetMap() const
   return map;
 }
 
+bool Property::Value::Get( Extents& extentsValue ) const
+{
+  bool converted = false;
+  if( mImpl )
+  {
+    if( mImpl->type == EXTENTS )
+    {
+      extentsValue = *(mImpl->extentsValue);
+      converted = true;
+    }
+    else if( mImpl->type == VECTOR4 )
+    {
+      extentsValue.start = static_cast< uint16_t >( mImpl->vector4Value->x );
+      extentsValue.end = static_cast< uint16_t >( mImpl->vector4Value->y );
+      extentsValue.top = static_cast< uint16_t >( mImpl->vector4Value->z );
+      extentsValue.bottom = static_cast< uint16_t >( mImpl->vector4Value->w );
+      converted = true;
+    }
+  }
+  return converted;
+}
+
 std::ostream& operator<<( std::ostream& stream, const Property::Value& value )
 {
   if( value.mImpl )
@@ -871,16 +991,19 @@ std::ostream& operator<<( std::ostream& stream, const Property::Value& value )
         stream << *(value.GetMap());
         break;
       }
-      case Dali::Property::NONE:
+      case Dali::Property::EXTENTS:
       {
-        stream << "undefined type";
+        stream << *impl.extentsValue;
         break;
       }
+      case Dali::Property::NONE:
+      { // mImpl will be a nullptr, there's no way to get to this case
+      }
     }
   }
   else
   {
-    stream << "empty type";
+    stream << "undefined type";
   }
   return stream;
 }