2 * Copyright (c) 2022 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>
28 }; // unnamed namespace
30 struct Property::Array::Impl
32 typedef std::vector<Value> Array;
37 Property::Array::Array()
42 Property::Array::Array(const std::initializer_list<Property::Value>& values)
45 for(auto&& value : values)
51 Property::Array::Array(const Property::Array& other)
54 mImpl->mArray = other.mImpl->mArray;
57 Property::Array::Array(Property::Array&& other) noexcept
60 other.mImpl = nullptr;
63 Property::Array::~Array()
68 Property::Array::SizeType Property::Array::Count() const
70 DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
71 return mImpl->mArray.size();
74 void Property::Array::PushBack(const Value& value)
76 DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
77 mImpl->mArray.push_back(value);
80 void Property::Array::Clear()
82 DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
83 mImpl->mArray.clear();
86 void Property::Array::Reserve(SizeType size)
88 DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
89 mImpl->mArray.reserve(size);
92 void Property::Array::Resize(SizeType size)
94 DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
95 mImpl->mArray.resize(size);
98 Property::Array::SizeType Property::Array::Capacity()
100 DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
101 return mImpl->mArray.capacity();
104 const Property::Value& Property::Array::operator[](SizeType index) const
106 DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
108 // Note says no bounds checking is performed so we don't need to verify mImpl as Count() will return 0 anyway
109 return mImpl->mArray[index];
112 Property::Value& Property::Array::operator[](SizeType index)
114 DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
116 // Note says no bounds checking is performed so we don't need to verify mImpl as Count() will return 0 anyway
117 return mImpl->mArray[index];
120 Property::Array& Property::Array::operator=(const Property::Array& other)
122 DALI_ASSERT_DEBUG(mImpl && "Cannot use an object previously used as an r-value");
126 mImpl->mArray = other.mImpl->mArray;
131 Property::Array& Property::Array::operator=(Property::Array&& other) noexcept
137 other.mImpl = nullptr;
142 std::ostream& operator<<(std::ostream& stream, const Property::Array& array)
144 stream << "Array(" << array.Count() << ") = [";
145 for(Property::Array::SizeType i = 0; i < array.Count(); ++i)
151 stream << array.GetElementAt(i);