All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Pool.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include <vector>
6 #include <limits>
7 
8 #include "PoolItemFactory.h"
9 #include "PoolHandle.h"
10 #include "PoolEntry.h"
11 #include "Types.h"
12 #include <stack>
13 
14 namespace Eegeo
15 {
16  namespace DataStructures
17  {
18  template <class T>
19  class Pool : protected Eegeo::NonCopyable
20  {
21  static_assert(std::is_pointer<T>::value, "Template type paramter provided to class Pool is not a pointer");
22 
23  typedef typename std::remove_pointer<T>::type TOmitPointer;
24 
25  std::vector<PoolEntry<T> > m_entries;
26  std::stack<u16, std::vector<u16>> m_freeIndices;
27  PoolItemFactory<T> *m_pInstanceFactory;
28  int m_count;
29 
30  public:
31  int GetCount() const { return m_count; }
32  int GetCapacity() const { return static_cast<int>(m_entries.size()); }
33  const std::vector<PoolEntry<T> >& GetEntries() { return m_entries; }
34 
35  Pool(int totalCapacity, PoolItemFactory<T> *pInstanceFactory);
36  ~Pool();
37  PoolHandle Allocate();
38  void Release(PoolHandle handle);
39  T Resolve(PoolHandle handle);
40  };
41  }
42 }
43 
44 #include "PoolImpl.h"