8cd31041805e4b80ba7715ce39756620652253de
[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) 2019 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
22 // INTERNAL INCLUDES
23 #include <dali/public-api/size-negotiation/relayout-container.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/actors/actor.h>
26
27 #include <dali/internal/common/memory-pool-object-allocator.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 /**
36  * @brief Container to encapsulate information required for relayout.
37  *
38  * Uses a memory pool to manage data allocations.
39  */
40 class MemoryPoolRelayoutContainer : public RelayoutContainer
41 {
42 public:
43
44   /**
45    * Struct to store the relayout information
46    */
47   struct RelayoutInfo
48   {
49     Dali::Actor actor;            ///< The actor to relayout
50     Vector2 size;           ///< The desired size of the actor
51   };
52
53   /**
54    * @brief Default constructor
55    *
56    * @param objectAllocator A memory pool that can allocate memory for RelayoutInfos
57    */
58   MemoryPoolRelayoutContainer( MemoryPoolObjectAllocator< RelayoutInfo >& objectAllocator );
59
60   /**
61    * Virtual destructor
62    */
63   virtual ~MemoryPoolRelayoutContainer();
64
65   /**
66    * @brief Add relayout information to the container if it does'nt already exist
67    *
68    * @param actor The actor to relayout
69    * @param size The size to relayout
70    */
71   virtual void Add( const Dali::Actor& actor, const Vector2& size );
72
73   /**
74    * @brief Remove information from the container
75    */
76   void PopBack();
77
78   /**
79    * @brief Retrieve relayout information for the given index
80    *
81    * @param index The index of the information to retrieve
82    */
83   void Get( size_t index, Dali::Actor& actorOut, Vector2& sizeOut  ) const;
84
85   /**
86    * @brief The count of information in the container
87    */
88   size_t Size() const;
89
90   /**
91    * @brief Set the capacity of the container
92    *
93    * @param capacity The new capacity for the container
94    */
95   void Reserve( size_t capacity );
96
97   /**
98    * @brief Reset the container, freeing all memory
99    */
100   void Clear();
101
102   /**
103    * @brief Returns if the container contains the actor or not
104    *
105    * @param actor The actor to search for
106    * @return Return if the actor was found or not
107    */
108   bool Contains( const Dali::Actor& actor );
109
110 private:
111   using RelayoutInfoContainer = Vector<RelayoutInfo*>;
112
113   RelayoutInfoContainer mRelayoutInfos;     ///< The list of relayout infos
114
115   MemoryPoolObjectAllocator< RelayoutInfo >& mAllocator;         ///< The memory pool from which the infos are allocated
116 };
117
118 } // namespace Internal
119
120 } // namespace Dali
121
122 #endif // DALI_INTERNAL_MEMORY_POOL_RELAYOUT_CONTAINER_H