e71af1337a20b329d404ec70c78f7d058951cbea
[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()
33 {
34 }
35
36 bool MemoryPoolRelayoutContainer::Contains( const Dali::Actor& actor )
37 {
38   for( RelayoutInfoContainer::Iterator it = mRelayoutInfos.Begin(), itEnd = mRelayoutInfos.End(); it != itEnd; ++it )
39   {
40     RelayoutInfo* info = *it;
41
42     if( info->actor == actor )
43     {
44       return true;
45     }
46   }
47
48   return false;
49 }
50
51 void MemoryPoolRelayoutContainer::Add( const Dali::Actor& actor, const Vector2& size )
52 {
53   if( !Contains( actor ) )
54   {
55     RelayoutInfo* info = mAllocator.Allocate();
56     info->actor = actor;
57     info->size = size;
58
59     mRelayoutInfos.PushBack( info );
60   }
61 }
62
63 void MemoryPoolRelayoutContainer::PopBack()
64 {
65   if( mRelayoutInfos.Size() > 0 )
66   {
67     RelayoutInfoContainer::Iterator back = mRelayoutInfos.End();
68     back--;
69     RelayoutInfo* info = *back;
70     mAllocator.Destroy( info );
71     mRelayoutInfos.Erase( back );
72   }
73 }
74
75 void MemoryPoolRelayoutContainer::Get( size_t index, Dali::Actor& actorOut, Vector2& sizeOut  ) const
76 {
77   DALI_ASSERT_DEBUG( index < Size() );
78
79   RelayoutInfo* info = mRelayoutInfos[ index ];
80   actorOut = info->actor;
81   sizeOut = info->size;
82 }
83
84 size_t MemoryPoolRelayoutContainer::Size() const
85 {
86   return mRelayoutInfos.Size();
87 }
88
89 void MemoryPoolRelayoutContainer::Reserve( size_t capacity )
90 {
91   mRelayoutInfos.Reserve( capacity );
92 }
93
94 void MemoryPoolRelayoutContainer::Clear()
95 {
96   for( size_t i = 0; i < Size(); ++i )
97   {
98     RelayoutInfo* info = mRelayoutInfos[ i ];
99     mAllocator.Destroy( info );
100   }
101
102   mRelayoutInfos.Clear();
103 }
104
105 } // namespace Internal
106
107 } // namespace Dali