2 * Copyright (c) 2015 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 "memory-pool-relayout-container.h"
27 MemoryPoolRelayoutContainer::MemoryPoolRelayoutContainer( MemoryPoolObjectAllocator< RelayoutInfo >& objectAllocator )
28 : mAllocator( objectAllocator )
32 MemoryPoolRelayoutContainer::~MemoryPoolRelayoutContainer()
36 bool MemoryPoolRelayoutContainer::Contains( const Dali::Actor& actor )
38 for( RelayoutInfoContainer::Iterator it = mRelayoutInfos.Begin(), itEnd = mRelayoutInfos.End(); it != itEnd; ++it )
40 RelayoutInfo* info = *it;
42 if( info->actor == actor )
51 void MemoryPoolRelayoutContainer::Add( const Dali::Actor& actor, const Vector2& size )
53 if( !Contains( actor ) )
55 RelayoutInfo* info = mAllocator.Allocate();
59 mRelayoutInfos.PushBack( info );
63 void MemoryPoolRelayoutContainer::PopBack()
65 if( mRelayoutInfos.Size() > 0 )
67 RelayoutInfoContainer::Iterator back = mRelayoutInfos.End();
69 RelayoutInfo* info = *back;
70 mAllocator.Destroy( info );
71 mRelayoutInfos.Erase( back );
75 void MemoryPoolRelayoutContainer::Get( size_t index, Dali::Actor& actorOut, Vector2& sizeOut ) const
77 DALI_ASSERT_DEBUG( index < Size() );
79 RelayoutInfo* info = mRelayoutInfos[ index ];
80 actorOut = info->actor;
84 size_t MemoryPoolRelayoutContainer::Size() const
86 return mRelayoutInfos.Size();
89 void MemoryPoolRelayoutContainer::Reserve( size_t capacity )
91 mRelayoutInfos.Reserve( capacity );
94 void MemoryPoolRelayoutContainer::Clear()
96 for( size_t i = 0; i < Size(); ++i )
98 RelayoutInfo* info = mRelayoutInfos[ i ];
99 mAllocator.Destroy( info );
102 mRelayoutInfos.Clear();
105 } // namespace Internal