NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
class_arrays.cpp
Go to the documentation of this file.
1#include <types.h>
4
5extern "C" {
6
19void *__construct_new_array(void *pBlock, ctorPtr pCtor, dtorPtr pDtor, u32 size, u32 n) {
20 char *ptr = (char *)pBlock;
21 if (ptr != nullptr) {
22 u32 *p = (u32 *)ptr;
23 p[0] = size;
24 p[1] = n;
25 ptr += 16;
26
27 if (pCtor != nullptr) {
28 __partial_array_destructor pad(ptr, size, n, pDtor);
29
30 char *p = (char *)ptr;
31 for (pad.mCurrNum = 0; pad.mCurrNum < n; p += size) {
32 pCtor(p, 1);
33 pad.mCurrNum++;
34 }
35 }
36 }
37
38 return ptr;
39}
40
51void __construct_array(void *pBlock, ctorPtr pCtor, dtorPtr pDtor, u32 size, u32 n) {
52 __partial_array_destructor pad(pBlock, size, n, pDtor);
53
54 char *p = (char *)pBlock;
55 for (pad.mCurrNum = 0; pad.mCurrNum < n; p += size) {
56 pCtor(p, 1);
57 pad.mCurrNum++;
58 }
59}
60
71void __destroy_arr(void *pBlock, dtorPtr pDtor, u32 size, u32 n) {
72 for (char *p = (char *)pBlock + size * n; n > 0; n--) {
73 p -= size;
74 pDtor(p, -1);
75 }
76}
77
85void __destroy_new_array(void *pBlock, dtorPtr pDtor) {
86 if (pBlock != nullptr) {
87 if (pDtor != nullptr) {
88 u32 i, objects, objectsize;
89 objectsize = ((u32 *) ((char *) pBlock - 16))[0];
90 objects = ((u32 *) ((char *) pBlock - 16))[1];
91
92 char *p = (char *) pBlock + objectsize * objects;
93 for (i = 0; i < objects; i++) {
94 p -= objectsize;
95 pDtor(p, -1);
96 }
97 }
98
99 delete[] ((char *)pBlock - 16);
100 }
101}
102
103} // extern "C"
Guarantees the correct destruction of an array if an exception is thrown during its construction.
u32 mCurrNum
The number of currently constructed array elements.
void __destroy_new_array(void *pBlock, dtorPtr pDtor)
Destroys and deletes an array of objects.
void __destroy_arr(void *pBlock, dtorPtr pDtor, u32 size, u32 n)
Destroys an array of objects.
void __construct_array(void *pBlock, ctorPtr pCtor, dtorPtr pDtor, u32 size, u32 n)
Constructs an array of objects.
void * __construct_new_array(void *pBlock, ctorPtr pCtor, dtorPtr pDtor, u32 size, u32 n)
Allocates and constructs an array of objects.
void(* dtorPtr)(void *, int)
Destructor function pointer.
void(* ctorPtr)(void *, int)
Constructor function pointer.