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)
28 mDummyRelayoutInfo.reset(new RelayoutInfo());
31 MemoryPoolRelayoutContainer::~MemoryPoolRelayoutContainer() = default;
33 bool MemoryPoolRelayoutContainer::Contains(const Dali::Actor& actor)
35 // Store actor into dummy info.
36 // It will be used for check comparision.
37 mDummyRelayoutInfo->actor = actor;
39 bool ret = (mRelayoutInfos.Find(mDummyRelayoutInfo.get()) != mRelayoutInfos.End());
41 // Reset empty handle for deference.
42 mDummyRelayoutInfo->actor = Dali::Actor();
46 void MemoryPoolRelayoutContainer::Add(const Dali::Actor& actor, const Vector2& size)
50 void* ptr = mAllocator.AllocateRaw();
51 RelayoutInfo* info = new(ptr) RelayoutInfo();
55 mRelayoutInfos.PushBack(info);
59 void MemoryPoolRelayoutContainer::PopBack()
61 if(mRelayoutInfos.Count() > 0)
63 RelayoutInfoContainer::Iterator back = mRelayoutInfos.End();
65 RelayoutInfo* info = *back;
66 mRelayoutInfos.Erase(back);
68 // Need to be destroyed after mRelayoutInfos erased.
69 mAllocator.Destroy(info);
73 void MemoryPoolRelayoutContainer::GetBack(Dali::Actor& actorOut, Vector2& sizeOut) const
75 if(mRelayoutInfos.Count() > 0)
77 RelayoutInfoContainer::ConstIterator back = mRelayoutInfos.End();
79 RelayoutInfo* info = *back;
80 actorOut = info->actor;
85 size_t MemoryPoolRelayoutContainer::Size() const
87 return mRelayoutInfos.Count();
90 void MemoryPoolRelayoutContainer::Reserve(size_t capacity)
92 mRelayoutInfos.Reserve(capacity);
95 void MemoryPoolRelayoutContainer::Clear()
97 for(auto& info : mRelayoutInfos)
99 mAllocator.Destroy(info);
102 mRelayoutInfos.Clear();
105 } // namespace Internal