NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
snd_InstancePool.h
1#ifndef NW4R_SND_INSTANCE_POOL_H
2#define NW4R_SND_INSTANCE_POOL_H
3
4/*******************************************************************************
5 * headers
6 */
7
8#include <new>
9
10#include <types.h>
11
12/*******************************************************************************
13 * classes and functions
14 */
15
16namespace nw4r { namespace snd { namespace detail
17{
18 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2e96b
19 class PoolImpl
20 {
21 // methods
22 protected:
23 // cdtors
24 PoolImpl() : mNext(nullptr) {}
25
26 // methods
27 ulong CreateImpl(void *buffer, ulong size, ulong objSize);
28 void DestroyImpl(void *buffer, ulong size);
29
30 int CountImpl() const;
31
32 void *AllocImpl();
33 void FreeImpl(void *ptr);
34
35 // members
36 private:
37 PoolImpl *mNext; // size 0x04, offset 0x00
38 }; // size 0x04
39
40 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2f735, 0x31491...
41 template <class T>
42 class InstancePool : private PoolImpl
43 {
44 // methods
45 public:
46 // methods
47 ulong Create(void *buffer, ulong size)
48 {
49 ulong objSize = sizeof(T);
50
51 return CreateImpl(buffer, size, objSize);
52 }
53 void Destroy(void *buffer, ulong size) { DestroyImpl(buffer, size); }
54
55 int Count() const { return CountImpl(); }
56
57 T *Alloc()
58 {
59 void *ptr = AllocImpl();
60 if (!ptr)
61 return nullptr;
62
63 return new (ptr) T;
64 }
65 void Free(T *obj)
66 {
67 if (obj)
68 {
69 obj->~T();
70 FreeImpl(obj);
71 }
72 }
73
74 // members
75 private:
76 /* base PoolImpl */ // size 0x04, offset 0x00
77 }; // size 0x04
78
79 // [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2efa0, 0x309c7...
80 template <class T>
81 class MemoryPool : private PoolImpl
82 {
83 // methods
84 public:
85 // methods
86 ulong Create(void *buffer, ulong size)
87 {
88 ulong objSize = sizeof(T);
89
90 return CreateImpl(buffer, size, objSize);
91 }
92 void Destroy(void *buffer, ulong size) { DestroyImpl(buffer, size); }
93
94 int Count() const { return CountImpl(); } // Presumably
95
96 T *Alloc() { return static_cast<T *>(AllocImpl()); }
97 void Free(T *obj) { FreeImpl(obj); }
98
99 // members
100 private:
101 /* base PoolImpl */ // size 0x04, offset 0x00
102 }; // size 0x04
103}}} // namespace nw4r::snd::detail
104
105#endif // NW4R_SND_INSTANCE_POOL_H