Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
InstancePool.h
Go to the documentation of this file.
1#ifndef NW4HBM_SND_INSTANCE_POOL_H
2#define NW4HBM_SND_INSTANCE_POOL_H
3
4#include <new>
5#include <revolution/types.h>
6
7namespace nw4hbm {
8 namespace snd {
9 namespace detail {
10 class PoolImpl {
11 public:
12 PoolImpl() : mNext(NULL) {}
13
14 protected:
15 u32 CreateImpl(void* buffer, u32 size, u32 objSize);
16 void DestroyImpl(void* buffer, u32 size);
17 int CountImpl() const;
18
19 void* AllocImpl();
20 void FreeImpl(void* ptr);
21
22 private:
23 /* 0x00 */ PoolImpl* mNext;
24 };
25
26 template <typename T>
27 class InstancePool : private PoolImpl {
28 public:
29 u32 Create(void* buffer, u32 size) { return CreateImpl(buffer, size, sizeof(T)); }
30
32
33 int Count() const { return CountImpl(); }
34
35 T* Alloc() {
36 void* ptr = AllocImpl();
37 if (ptr == NULL) {
38 return NULL;
39 }
40
41 return new (ptr) T;
42 }
43
44 void Free(T* obj) {
45 if (obj != NULL) {
46 obj->~T();
47 FreeImpl(obj);
48 }
49 }
50 };
51
52 template <typename T>
53 class MemoryPool : private PoolImpl {
54 public:
55 u32 Create(void* buffer, u32 size) { return CreateImpl(buffer, size, sizeof(T)); }
56
58
59 int Count() const { return CountImpl(); }
60
61 T* Alloc() { return static_cast<T*>(AllocImpl()); }
62
63 void Free(T* obj) { FreeImpl(obj); }
64 };
65 } // namespace detail
66 } // namespace snd
67} // namespace nw4hbm
68
69#endif
Definition InstancePool.h:27
T * Alloc()
Definition InstancePool.h:35
void Free(T *obj)
Definition InstancePool.h:44
int Count() const
Definition InstancePool.h:33
u32 Create(void *buffer, u32 size)
Definition InstancePool.h:29
void Destroy(void *buffer, u32 size)
Definition InstancePool.h:31
Definition InstancePool.h:53
u32 Create(void *buffer, u32 size)
Definition InstancePool.h:55
T * Alloc()
Definition InstancePool.h:61
int Count() const
Definition InstancePool.h:59
void Destroy(void *buffer, u32 size)
Definition InstancePool.h:57
void Free(T *obj)
Definition InstancePool.h:63
Definition InstancePool.h:10
PoolImpl()
Definition InstancePool.h:12
u32 CreateImpl(void *buffer, u32 size, u32 objSize)
PoolImpl * mNext
Definition InstancePool.h:23
void DestroyImpl(void *buffer, u32 size)
static OSTime buffer
Definition ai.c:24
unsigned int size
Definition __os.h:106
unsigned long u32
Definition types.h:12
Definition HBMAnmController.h:6