noexcept move for BaseHandle/InstrusivePtr/Math
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-array.cpp
index eca8182..9d204fc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -23,7 +23,6 @@
 
 namespace Dali
 {
-
 namespace
 {
 }; // unnamed namespace
@@ -36,16 +35,31 @@ struct Property::Array::Impl
 };
 
 Property::Array::Array()
-: mImpl( new Impl )
+: mImpl(new Impl)
+{
+}
+
+Property::Array::Array(const std::initializer_list<Property::Value>& values)
+: Array()
 {
+  for(auto&& value : values)
+  {
+    PushBack(value);
+  }
 }
 
-Property::Array::Array( const Property::Array& other )
-: mImpl( new Impl )
+Property::Array::Array(const Property::Array& other)
+: mImpl(new Impl)
 {
   mImpl->mArray = other.mImpl->mArray;
 }
 
+Property::Array::Array(Property::Array&& other) noexcept
+: mImpl(other.mImpl)
+{
+  other.mImpl = nullptr;
+}
+
 Property::Array::~Array()
 {
   delete mImpl;
@@ -53,61 +67,84 @@ Property::Array::~Array()
 
 Property::Array::SizeType Property::Array::Count() const
 {
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
   return mImpl->mArray.size();
 }
 
-void Property::Array::PushBack( const Value& value )
+void Property::Array::PushBack(const Value& value)
 {
-  mImpl->mArray.push_back( value );
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
+  mImpl->mArray.push_back(value);
 }
 
 void Property::Array::Clear()
 {
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
   mImpl->mArray.clear();
 }
 
-void Property::Array::Reserve( SizeType size )
+void Property::Array::Reserve(SizeType size)
 {
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
   mImpl->mArray.reserve(size);
 }
 
-void Property::Array::Resize( SizeType size )
+void Property::Array::Resize(SizeType size)
 {
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
   mImpl->mArray.resize(size);
 }
 
 Property::Array::SizeType Property::Array::Capacity()
 {
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
   return mImpl->mArray.capacity();
 }
 
-const Property::Value& Property::Array::operator[]( SizeType index ) const
+const Property::Value& Property::Array::operator[](SizeType index) const
 {
-  return mImpl->mArray[ index ];
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
+
+  // Note says no bounds checking is performed so we don't need to verify mImpl as Count() will return 0 anyway
+  return mImpl->mArray[index];
 }
 
-Property::Value& Property::Array::operator[]( SizeType index )
+Property::Value& Property::Array::operator[](SizeType index)
 {
-  return mImpl->mArray[ index ];
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
+
+  // Note says no bounds checking is performed so we don't need to verify mImpl as Count() will return 0 anyway
+  return mImpl->mArray[index];
 }
 
-Property::Array& Property::Array::operator=( const Property::Array& other )
+Property::Array& Property::Array::operator=(const Property::Array& other)
 {
-  if( this != &other )
+  DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
+
+  if(this != &other)
   {
-    delete mImpl;
-    mImpl = new Impl;
     mImpl->mArray = other.mImpl->mArray;
   }
   return *this;
 }
 
-std::ostream& operator<<( std::ostream& stream, const Property::Array& array )
+Property::Array& Property::Array::operator=(Property::Array&& other) noexcept
+{
+  if(this != &other)
+  {
+    delete mImpl;
+    mImpl       = other.mImpl;
+    other.mImpl = nullptr;
+  }
+  return *this;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Property::Array& array)
 {
   stream << "Array(" << array.Count() << ") = [";
-  for( unsigned int i=0; i<array.Count(); ++i )
+  for(Property::Array::SizeType i = 0; i < array.Count(); ++i)
   {
-    if( i>0 )
+    if(i > 0)
     {
       stream << ", ";
     }
@@ -118,5 +155,4 @@ std::ostream& operator<<( std::ostream& stream, const Property::Array& array )
   return stream;
 }
 
-
 } // namespace Dali