Updated all code to new format
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / memory-pool-relayout-container.h
1 #ifndef DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H
2 #define DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali/public-api/size-negotiation/relayout-container.h>
25
26 #include <dali/internal/common/memory-pool-object-allocator.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 /**
33  * @brief Container to encapsulate information required for relayout.
34  *
35  * Uses a memory pool to manage data allocations.
36  */
37 class MemoryPoolRelayoutContainer : public RelayoutContainer
38 {
39 public:
40   /**
41    * Struct to store the relayout information
42    */
43   struct RelayoutInfo
44   {
45     Dali::Actor actor; ///< The actor to relayout
46     Vector2     size;  ///< The desired size of the actor
47   };
48
49   /**
50    * @brief Default constructor
51    *
52    * @param objectAllocator A memory pool that can allocate memory for RelayoutInfos
53    */
54   MemoryPoolRelayoutContainer(MemoryPoolObjectAllocator<RelayoutInfo>& objectAllocator);
55
56   /**
57    * Virtual destructor
58    */
59   ~MemoryPoolRelayoutContainer() override;
60
61   /**
62    * @brief Add relayout information to the container if it does'nt already exist
63    *
64    * @param actor The actor to relayout
65    * @param size The size to relayout
66    */
67   void Add(const Dali::Actor& actor, const Vector2& size) override;
68
69   /**
70    * @brief Remove information from the container
71    */
72   void PopBack();
73
74   /**
75    * @brief Retrieve relayout information for the given index
76    *
77    * @param index The index of the information to retrieve
78    */
79   void Get(size_t index, Dali::Actor& actorOut, Vector2& sizeOut) const;
80
81   /**
82    * @brief The count of information in the container
83    */
84   size_t Size() const;
85
86   /**
87    * @brief Set the capacity of the container
88    *
89    * @param capacity The new capacity for the container
90    */
91   void Reserve(size_t capacity);
92
93   /**
94    * @brief Reset the container, freeing all memory
95    */
96   void Clear();
97
98   /**
99    * @brief Returns if the container contains the actor or not
100    *
101    * @param actor The actor to search for
102    * @return Return if the actor was found or not
103    */
104   bool Contains(const Dali::Actor& actor);
105
106 private:
107   using RelayoutInfoContainer = Vector<RelayoutInfo*>;
108
109   RelayoutInfoContainer mRelayoutInfos; ///< The list of relayout infos
110
111   MemoryPoolObjectAllocator<RelayoutInfo>& mAllocator; ///< The memory pool from which the infos are allocated
112 };
113
114 } // namespace Internal
115
116 } // namespace Dali
117
118 #endif // DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H