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"
25 MemoryPoolRelayoutContainer::MemoryPoolRelayoutContainer(MemoryPoolObjectAllocator<RelayoutInfo>& objectAllocator)
26 : mAllocator(objectAllocator)
30 MemoryPoolRelayoutContainer::~MemoryPoolRelayoutContainer() = default;
32 bool MemoryPoolRelayoutContainer::Contains(const Dali::Actor& actor)
34 for(RelayoutInfoContainer::Iterator it = mRelayoutInfos.Begin(), itEnd = mRelayoutInfos.End(); it != itEnd; ++it)
36 RelayoutInfo* info = *it;
38 if(info->actor == actor)
47 void MemoryPoolRelayoutContainer::Add(const Dali::Actor& actor, const Vector2& size)
51 RelayoutInfo* info = mAllocator.Allocate();
55 mRelayoutInfos.PushBack(info);
59 void MemoryPoolRelayoutContainer::PopBack()
61 if(mRelayoutInfos.Size() > 0)
63 RelayoutInfoContainer::Iterator back = mRelayoutInfos.End();
65 RelayoutInfo* info = *back;
66 mAllocator.Destroy(info);
67 mRelayoutInfos.Erase(back);
71 void MemoryPoolRelayoutContainer::Get(size_t index, Dali::Actor& actorOut, Vector2& sizeOut) const
73 DALI_ASSERT_DEBUG(index < Size());
75 RelayoutInfo* info = mRelayoutInfos[index];
76 actorOut = info->actor;
80 size_t MemoryPoolRelayoutContainer::Size() const
82 return mRelayoutInfos.Size();
85 void MemoryPoolRelayoutContainer::Reserve(size_t capacity)
87 mRelayoutInfos.Reserve(capacity);
90 void MemoryPoolRelayoutContainer::Clear()
92 for(size_t i = 0; i < Size(); ++i)
94 RelayoutInfo* info = mRelayoutInfos[i];
95 mAllocator.Destroy(info);
98 mRelayoutInfos.Clear();
101 } // namespace Internal