NW4F Snd
Loading...
Searching...
No Matches
snd_InstancePool.h
Go to the documentation of this file.
1#ifndef NW_SND_INSTANCE_POOL_H_
2#define NW_SND_INSTANCE_POOL_H_
3
4#include <new>
5#include <nw/snd/snd_Global.h>
6
7namespace nw { namespace snd { namespace internal {
8
10{
11public:
13 : m_pNext(NULL)
14 {
15 }
16
17protected:
18 u32 CreateImpl(void* buffer, size_t size, u32 objSize);
20 int CountImpl() const;
21 void* AllocImpl();
22 void FreeImpl(void* ptr);
23
24private:
26};
27static_assert(sizeof(PoolImpl) == 4);
28
29template <typename T>
30class InstancePool : private PoolImpl
31{
32public:
33 u32 Create(void* buffer, unsigned long size)
34 {
35 u32 objSize =
36 (sizeof(T) > sizeof(InstancePool<T>*))
37 ? sizeof(T)
38 : sizeof(InstancePool<T>*);
39 return CreateImpl(buffer, size, objSize);
40 }
41
42 void Destroy()
43 {
45 }
46
47 int Count() const
48 {
49 return CountImpl();
50 }
51
52 T* Alloc()
53 {
54 void *ptr = AllocImpl();
55 if (ptr == NULL)
56 return NULL;
57 return new (ptr) T();
58 }
59
60 void Free(T* obj)
61 {
62 if (obj == NULL)
63 return;
64 obj->~T();
65 FreeImpl(obj);
66 }
67};
68
69} } } // namespace nw::snd::internal
70
71#endif // NW_SND_INSTANCE_POOL_H_
Definition snd_InstancePool.h:31
void Free(T *obj)
Definition snd_InstancePool.h:60
u32 Create(void *buffer, unsigned long size)
Definition snd_InstancePool.h:33
T * Alloc()
Definition snd_InstancePool.h:52
int Count() const
Definition snd_InstancePool.h:47
void Destroy()
Definition snd_InstancePool.h:42
Definition snd_InstancePool.h:10
PoolImpl()
Definition snd_InstancePool.h:12
u32 CreateImpl(void *buffer, size_t size, u32 objSize)
PoolImpl * m_pNext
Definition snd_InstancePool.h:25
Definition snd_BasicSound.cpp:3
Definition snd_BasicSound.cpp:3