X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Fpublic-api%2Fobject%2Fproperty-array.cpp;h=9d204fc4989ace92bc53f39234557fcb235ba14c;hb=36ea2dd0841fadf61696fffc8bb649b63ebfe4b6;hp=eca8182d1d86721a6b6d2a510eb6677421cc1972;hpb=5197b928f899e8402d532066adff4df56cbd64b1;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/public-api/object/property-array.cpp b/dali/public-api/object/property-array.cpp index eca8182..9d204fc 100644 --- a/dali/public-api/object/property-array.cpp +++ b/dali/public-api/object/property-array.cpp @@ -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& 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; i0 ) + if(i > 0) { stream << ", "; } @@ -118,5 +155,4 @@ std::ostream& operator<<( std::ostream& stream, const Property::Array& array ) return stream; } - } // namespace Dali