[dali_1.9.14] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-value.cpp
index e02e8ce..7132bfb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 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.
@@ -53,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 )
@@ -113,7 +108,7 @@ 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 ) )
   {
@@ -125,24 +120,48 @@ struct Property::Value::Impl
   {
   }
 
+  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
    */
@@ -238,12 +257,14 @@ public: // Data
 
 private:
 
-  Impl( const Impl& ); ///< Undefined
-  Impl& operator=( const Impl& ); ///< Undefined
+  // non-copyable
+  Impl( const Impl& ) = delete;
+  Impl& operator=( const Impl& ) = delete;
+
 };
 
 Property::Value::Value()
-: mImpl( NULL )
+: mImpl( nullptr )
 {
 }
 
@@ -287,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 ) )
 {
 }
@@ -308,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) );
   }
@@ -325,18 +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( NULL )
+: mImpl( nullptr )
 {
   switch (type)
   {
@@ -412,19 +453,25 @@ Property::Value::Value( Type type )
     }
     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 )
@@ -436,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
@@ -515,14 +562,14 @@ Property::Value& Property::Value::operator=( const Property::Value& value )
         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:
@@ -596,7 +643,7 @@ Property::Value& Property::Value::operator=( const Property::Value& value )
         break;
       }
       case Property::NONE:
-      { // NULL value will be used for "empty" value
+      { // nullptr value will be used for "empty" value
       }
     }
     delete mImpl;
@@ -606,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;
@@ -651,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 )
@@ -751,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
@@ -819,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;
@@ -829,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;
@@ -938,15 +997,13 @@ std::ostream& operator<<( std::ostream& stream, const Property::Value& value )
         break;
       }
       case Dali::Property::NONE:
-      {
-        stream << "undefined type";
-        break;
+      { // mImpl will be a nullptr, there's no way to get to this case
       }
     }
   }
   else
   {
-    stream << "empty type";
+    stream << "undefined type";
   }
   return stream;
 }