hx3d  1
2D/3D Simple Game Framework
pool.hpp
1 /*
2  Pool system.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_UTILS_POOL
22 #define HX3D_UTILS_POOL
23 
24 #include "hx3d/utils/ptr.hpp"
25 
26 #include <set>
27 #include <queue>
28 
29 namespace hx3d {
30 
34 template <class T>
35 class Pool {
36 public:
37 
44  template <class... Args>
45  Pool(unsigned int size, Args... args);
46  ~Pool();
47 
53  const Ptr<T>& take();
54 
60  void release(const Ptr<T>& ptr);
61 
67  const std::set<Ptr<T>>& getWorking();
68 
69 private:
70  std::queue<unsigned int> _available;
71  std::set<unsigned int> _locked;
72 
73  std::set<Ptr<T>> _working;
74  std::vector<Ptr<T>> _content;
75 
76  unsigned int size;
77 
78 };
79 
80 } /* hx3d */
81 
82 #include "hx3d/utils/_inline/pool.inl.hpp"
83 
84 #endif
void release(const Ptr< T > &ptr)
Release a poolable element.
Definition: pool.inl.hpp:55
Pool(unsigned int size, Args...args)
Construct a pool with a size and arguments.
Definition: pool.inl.hpp:27
const Ptr< T > & take()
Fetch a free poolable element.
Definition: pool.inl.hpp:41
Manage poolable elements.
Definition: pool.hpp:35
hx3d framework namespace
Definition: audio.hpp:26
const std::set< Ptr< T > > & getWorking()
Get the locked elements.
Definition: pool.inl.hpp:70
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34