2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/public-api/object/property-array.h>
22 #include <dali/public-api/common/vector-wrapper.h>
29 }; // unnamed namespace
31 struct Property::Array::Impl
33 typedef std::vector<Value> Array;
38 Property::Array::Array()
43 Property::Array::Array( const std::initializer_list< Property::Value >& values )
46 for( auto&& value : values )
52 Property::Array::Array( const Property::Array& other )
55 mImpl->mArray = other.mImpl->mArray;
58 Property::Array::Array( Property::Array&& other )
59 : mImpl( other.mImpl )
61 other.mImpl = nullptr;
64 Property::Array::~Array()
69 Property::Array::SizeType Property::Array::Count() const
71 DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
72 return mImpl->mArray.size();
75 void Property::Array::PushBack( const Value& value )
77 DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
78 mImpl->mArray.push_back( value );
81 void Property::Array::Clear()
83 DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
84 mImpl->mArray.clear();
87 void Property::Array::Reserve( SizeType size )
89 DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
90 mImpl->mArray.reserve(size);
93 void Property::Array::Resize( SizeType size )
95 DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
96 mImpl->mArray.resize(size);
99 Property::Array::SizeType Property::Array::Capacity()
101 DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
102 return mImpl->mArray.capacity();
105 const Property::Value& Property::Array::operator[]( SizeType index ) const
107 DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
109 // Note says no bounds checking is performed so we don't need to verify mImpl as Count() will return 0 anyway
110 return mImpl->mArray[ index ];
113 Property::Value& Property::Array::operator[]( SizeType index )
115 DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
117 // Note says no bounds checking is performed so we don't need to verify mImpl as Count() will return 0 anyway
118 return mImpl->mArray[ index ];
121 Property::Array& Property::Array::operator=( const Property::Array& other )
123 DALI_ASSERT_DEBUG( mImpl && "Cannot use an object previously used as an r-value" );
127 mImpl->mArray = other.mImpl->mArray;
132 Property::Array& Property::Array::operator=( Property::Array&& other )
138 other.mImpl = nullptr;
143 std::ostream& operator<<( std::ostream& stream, const Property::Array& array )
145 stream << "Array(" << array.Count() << ") = [";
146 for( Property::Array::SizeType i=0; i<array.Count(); ++i )
152 stream << array.GetElementAt(i);