Making DALi public API typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-array.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/object/property-array.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23
24 namespace Dali
25 {
26
27 namespace
28 {
29 }; // unnamed namespace
30
31 struct Property::Array::Impl
32 {
33   typedef std::vector<Value> Array;
34
35   Array mArray;
36 };
37
38 Property::Array::Array()
39 : mImpl( new Impl )
40 {
41 }
42
43 Property::Array::Array( const Property::Array& other )
44 : mImpl( new Impl )
45 {
46   mImpl->mArray = other.mImpl->mArray;
47 }
48
49 Property::Array::~Array()
50 {
51   delete mImpl;
52 }
53
54 Property::Array::SizeType Property::Array::Count() const
55 {
56   return mImpl->mArray.size();
57 }
58
59 void Property::Array::PushBack( const Value& value )
60 {
61   mImpl->mArray.push_back( value );
62 }
63
64 void Property::Array::Clear()
65 {
66   mImpl->mArray.clear();
67 }
68
69 void Property::Array::Reserve( SizeType size )
70 {
71   mImpl->mArray.reserve(size);
72 }
73
74 void Property::Array::Resize( SizeType size )
75 {
76   mImpl->mArray.resize(size);
77 }
78
79 Property::Array::SizeType Property::Array::Capacity()
80 {
81   return mImpl->mArray.capacity();
82 }
83
84 const Property::Value& Property::Array::operator[]( SizeType index ) const
85 {
86   return mImpl->mArray[ index ];
87 }
88
89 Property::Value& Property::Array::operator[]( SizeType index )
90 {
91   return mImpl->mArray[ index ];
92 }
93
94 Property::Array& Property::Array::operator=( const Property::Array& other )
95 {
96   if( this != &other )
97   {
98     delete mImpl;
99     mImpl = new Impl;
100     mImpl->mArray = other.mImpl->mArray;
101   }
102   return *this;
103 }
104
105 std::ostream& operator<<( std::ostream& stream, const Property::Array& array )
106 {
107   stream << "Array(" << array.Count() << ") = [";
108   for( Property::Array::SizeType i=0; i<array.Count(); ++i )
109   {
110     if( i>0 )
111     {
112       stream << ", ";
113     }
114     stream << array.GetElementAt(i);
115   }
116   stream << "]";
117
118   return stream;
119 }
120
121
122 } // namespace Dali