Files
st/include/iterator.hpp
T
Yanis 8d759ee331 Decompile overlay 1 (Part 7) (#106)
* run ninja format

* delink what's left from overlay 1 (except dsprotect)

* fix regressions

* UnkStruct_027e0ce0_1C_001 97%

* UnkStruct_0204a110_001 OK

* UnkStruct_ov024_020d86a0_001 OK

* UnkStruct_ov000_020b50c0_001 OK

* GameModeCreate OK

* AdventureModeManager_001 OK

* GameModeAdventure_001 OK

* AdventureModeManager_001 OKn't because weak issues

* ZeldaCollisionBinary OK

* UnkStruct_027e09c0_001 OK

* UnkStruct_ov000_020b504c_001 OK

* UnkStruct_ov000_02067bc4.hpp -> UnkStruct_ov000_020b504c.hpp

* match overlay 97

* match overlay 100

* run ninja format
2026-07-13 18:41:32 +02:00

112 lines
2.3 KiB
C++

#pragma once
#include "System/SysNew.hpp"
#include "types.h"
// link list?
struct stack_struct1 {
void *param1;
union {
void *param2;
unk32 arg2;
};
};
template <typename T> class Iterator {
public:
/* 00 */ void *begin;
/* 04 */ void *end;
/* 08 */
Iterator() {
this->Clear();
}
~Iterator() {
this->Destroy();
}
// allocate the list and run the constructors for each element
void Init(size_t arrayLength, size_t factor = 4) {
this->Destroy();
this->Set(arrayLength * factor);
if (this->begin != this->end) {
T *it = (T *) this->begin;
do {
new(it) T(); // using placement new to run the ctor
it++;
} while (it != (T *) this->end);
}
}
// same as the other `Init` except this takes a node list
void Init(size_t arrayLength, void *params) {
this->Destroy();
this->Set(arrayLength);
if (this->begin != this->end) {
T *it = (T *) this->begin;
stack_struct1 *p = (stack_struct1 *) params;
do {
new(it) T(*p);
it++;
p++;
} while (it != (T *) this->end);
}
}
// iterate the array and run the destructors for each element
void Destroy() {
if (this->begin != this->end) {
T *it = (T *) this->end;
do {
(--it)->~T();
} while (it != (T *) this->begin);
delete this->begin;
}
}
// allocate and set pointers
void Set(size_t arrayLength) {
void *ptr = ::operator new(arrayLength, HeapIndex_1, 4);
this->begin = ptr;
this->end = (void *) ((u8 *) ptr + arrayLength);
}
// clear pointers
void Clear() {
this->begin = NULL;
this->end = NULL;
}
// destroy and clear
void Reset() {
this->Destroy();
this->Clear();
}
T &Get(int index) {
return ((T *) this->begin)[index];
}
T *GetPtr(int index) {
return ((T *) this->begin) + index;
}
const int GetAllocSize() const {
return (int) this->end - (int) this->begin;
}
const int GetLastIndex() const {
return (this->GetAllocSize() / (int) sizeof(T)) - 1;
}
};