Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / memory-pool-relayout-container.cpp
1 /*
2  * Copyright (c) 2015 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 // FILE HEADER
19 #include "memory-pool-relayout-container.h"
20
21 namespace Dali
22 {
23
24 namespace Internal
25 {
26
27 MemoryPoolRelayoutContainer::MemoryPoolRelayoutContainer( MemoryPoolObjectAllocator< RelayoutInfo >& objectAllocator )
28 : mAllocator( objectAllocator )
29 {
30 }
31
32 MemoryPoolRelayoutContainer::~MemoryPoolRelayoutContainer() = default;
33
34 bool MemoryPoolRelayoutContainer::Contains( const Dali::Actor& actor )
35 {
36   for( RelayoutInfoContainer::Iterator it = mRelayoutInfos.Begin(), itEnd = mRelayoutInfos.End(); it != itEnd; ++it )
37   {
38     RelayoutInfo* info = *it;
39
40     if( info->actor == actor )
41     {
42       return true;
43     }
44   }
45
46   return false;
47 }
48
49 void MemoryPoolRelayoutContainer::Add( const Dali::Actor& actor, const Vector2& size )
50 {
51   if( !Contains( actor ) )
52   {
53     RelayoutInfo* info = mAllocator.Allocate();
54     info->actor = actor;
55     info->size = size;
56
57     mRelayoutInfos.PushBack( info );
58   }
59 }
60
61 void MemoryPoolRelayoutContainer::PopBack()
62 {
63   if( mRelayoutInfos.Size() > 0 )
64   {
65     RelayoutInfoContainer::Iterator back = mRelayoutInfos.End();
66     back--;
67     RelayoutInfo* info = *back;
68     mAllocator.Destroy( info );
69     mRelayoutInfos.Erase( back );
70   }
71 }
72
73 void MemoryPoolRelayoutContainer::Get( size_t index, Dali::Actor& actorOut, Vector2& sizeOut  ) const
74 {
75   DALI_ASSERT_DEBUG( index < Size() );
76
77   RelayoutInfo* info = mRelayoutInfos[ index ];
78   actorOut = info->actor;
79   sizeOut = info->size;
80 }
81
82 size_t MemoryPoolRelayoutContainer::Size() const
83 {
84   return mRelayoutInfos.Size();
85 }
86
87 void MemoryPoolRelayoutContainer::Reserve( size_t capacity )
88 {
89   mRelayoutInfos.Reserve( capacity );
90 }
91
92 void MemoryPoolRelayoutContainer::Clear()
93 {
94   for( size_t i = 0; i < Size(); ++i )
95   {
96     RelayoutInfo* info = mRelayoutInfos[ i ];
97     mAllocator.Destroy( info );
98   }
99
100   mRelayoutInfos.Clear();
101 }
102
103 } // namespace Internal
104
105 } // namespace Dali