Example of First Person 3D game with DALI
[platform/core/uifw/dali-demo.git] / examples / fpp-game / game-container.h
1 #ifndef GAME_CONTAINER_H
2 #define GAME_CONTAINER_H
3
4 /*
5  * Copyright (c) 2016 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 #include <dali/public-api/common/dali-vector.h>
22
23
24 /**
25  * GameContainer is a vector which owns heap-allocated objects.
26  * Unlike vector this will call delete on the stored pointers during destruction.
27  * For example, you can define a vector of heap-allocated Node objects:
28  * @code
29  *   typedef GameContainer< GameEntity* > EntityArray;
30  *
31  *   EntityArray entites;
32  *   entites.PushBack( new GameEntity() );
33  *   // container is now responsible for calling delete on GameEntity
34  *
35  * @endcode
36  */
37 template< class T > class GameContainer : public Dali::Vector< T >
38 {
39 public:
40
41   typedef typename Dali::Vector< T >::Iterator Iterator;
42   typedef typename Dali::Vector< T >::ConstIterator ConstIterator;
43
44   /**
45    * Create a owner container.
46    */
47   GameContainer()
48   {
49   }
50
51   /**
52    * Non-virtual destructor; GameCache<T> is not suitable as base class.
53    */
54   ~GameContainer()
55   {
56     Clear();
57     Dali::VectorBase::Release();
58   }
59
60   /**
61    * Destroy all of the elements in the container.
62    */
63   void Clear()
64   {
65     ConstIterator end = Dali::Vector< T >::End();
66     for( Iterator iter = Dali::Vector< T >::Begin(); iter != end; ++iter )
67     {
68       delete (*iter);
69     }
70     Dali::Vector< T >::Clear();
71   }
72
73 private:
74
75   // Undefined copy constructor.
76   GameContainer( const GameContainer& );
77
78   // Undefined assignment operator.
79   GameContainer& operator=( const GameContainer& );
80 };
81
82 #endif // GAMECACHE_H