Symbol fixes, headers & main progress

Former-commit-id: 6944a14e89
This commit is contained in:
2022-10-01 02:19:09 -04:00
parent f1e383728e
commit adb54a9892
48 changed files with 458 additions and 200 deletions

View File

@@ -9,12 +9,13 @@ namespace rstl {
template < typename T, typename Alloc = rmemory_allocator >
class list {
public:
list() : x4_start(&xc_empty), x8_end(&xc_empty), xc_empty(x8_end, nullptr) {}
list() : x4_start(&xc_empty), x8_end(&xc_empty), xc_empty(&xc_empty, &xc_empty) {}
~list() {
node* cur = x4_start;
while (cur != nullptr) {
delete cur->x8_item;
cur = cur->x4_next;
while (cur != x8_end) {
cur->get_value()->~T();
Alloc::deallocate(cur->get_value());
cur = cur->get_next();
}
}
@@ -28,6 +29,12 @@ private:
};
node(node* prev, node* next) : x0_prev(prev), x4_next(next), x8_count(0) {}
node* get_prev() const { return x0_prev; }
node* get_next() const { return x4_next; }
T* get_value() { return x8_item; }
// todo set_next / set_prev
};
Alloc x0_allocator;

View File

@@ -3,23 +3,36 @@
#include "types.h"
namespace rstl {
class CRefData {
public:
CRefData(void* ptr) : x0_ptr(ptr), x4_refCount(1) {}
CRefData(void* ptr, int refCount) : x0_ptr(ptr), x4_refCount(refCount) {}
CRefData(const void* ptr) : x0_ptr(ptr), x4_refCount(1) {}
CRefData(const void* ptr, int refCount) : x0_ptr(ptr), x4_refCount(refCount) {}
void* x0_ptr;
unsigned int x4_refCount;
void* GetPtr() const { return const_cast< void* >(x0_ptr); }
int GetRefCount() const { return x4_refCount; }
int AddRef() { return ++x4_refCount; }
int DelRef() { return --x4_refCount; }
const void* x0_ptr;
int x4_refCount;
static CRefData sNull;
};
namespace rstl {
template < typename T >
class rc_ptr {
public:
rc_ptr(T* ptr) : x0_refData(new CRefData(ptr)) {}
~rc_ptr();
T* GetPtr() const { return reinterpret_cast< T* >(x0_refData->x0_ptr); }
// TODO ReleaseData__Q24rstl20rc_ptr
rc_ptr(const T* ptr) : x0_refData(new CRefData(ptr)) {}
rc_ptr(const rc_ptr& other) : x0_refData(other.x0_refData) { x0_refData->AddRef(); }
~rc_ptr() { ReleaseData(); }
T* GetPtr() const { return static_cast< T* >(x0_refData->GetPtr()); }
void ReleaseData() {
if (x0_refData->DelRef() <= 0) {
delete GetPtr();
delete x0_refData;
}
}
T* operator->() const { return GetPtr(); }
T& operator*() const { return *GetPtr(); }

View File

@@ -38,7 +38,7 @@ public:
}
void clear() {
for (int i = 0; i < x0_count; ++i) {
rstl::destroy(&reinterpret_cast< T* >(x4_data)[i]);
rstl::destroy(&data()[i]);
}
x0_count = 0;
}

View File

@@ -13,8 +13,9 @@ struct rmemory_allocator {
}
template < typename T >
static void deallocate(T* ptr) {
if (ptr != nullptr)
CMemory::Free(ptr);
if (ptr != nullptr) {
delete[] reinterpret_cast< u8* >(ptr);
}
}
};
} // namespace rstl