2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _RSTL_SINGLE_PTR
|
|
|
|
#define _RSTL_SINGLE_PTR
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
namespace rstl {
|
|
|
|
template < typename T >
|
|
|
|
class single_ptr {
|
2022-09-18 17:51:07 +00:00
|
|
|
mutable T* x0_ptr;
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
single_ptr() : x0_ptr(nullptr) {}
|
|
|
|
single_ptr(T* ptr) : x0_ptr(ptr) {}
|
|
|
|
~single_ptr() { delete x0_ptr; }
|
2022-08-15 04:51:06 +00:00
|
|
|
T* get() const { return x0_ptr; }
|
|
|
|
// const T* get() const { return x0_ptr; }
|
2022-04-10 00:17:06 +00:00
|
|
|
T* operator->() { return x0_ptr; }
|
2022-08-14 18:38:41 +00:00
|
|
|
const T* operator->() const { return x0_ptr; }
|
2022-10-09 05:13:17 +00:00
|
|
|
single_ptr(const single_ptr& other) : x0_ptr(other.x0_ptr) { other.x0_ptr = nullptr; }
|
2022-09-13 04:26:54 +00:00
|
|
|
single_ptr& operator=(T* ptr) {
|
2022-04-10 00:17:06 +00:00
|
|
|
delete x0_ptr;
|
|
|
|
x0_ptr = ptr;
|
2022-09-13 04:26:54 +00:00
|
|
|
return *this;
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
2022-08-16 02:14:28 +00:00
|
|
|
bool null() const { return x0_ptr == nullptr; }
|
2022-08-13 01:26:00 +00:00
|
|
|
T& operator*() { return *x0_ptr; }
|
|
|
|
const T& operator*() const { return *x0_ptr; }
|
2022-09-18 05:55:13 +00:00
|
|
|
T* release() {
|
|
|
|
T* ptr = x0_ptr;
|
|
|
|
x0_ptr = nullptr;
|
|
|
|
return ptr;
|
|
|
|
}
|
2023-07-31 13:35:09 +00:00
|
|
|
|
|
|
|
// This is certainly not real, but handy to force not-inline
|
|
|
|
single_ptr& Set(T* ptr);
|
2022-04-10 00:17:06 +00:00
|
|
|
};
|
2022-08-13 01:26:00 +00:00
|
|
|
|
2023-07-31 13:35:09 +00:00
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
single_ptr< T >& single_ptr< T >::Set(T* ptr) {
|
|
|
|
return *this = ptr;
|
|
|
|
}
|
|
|
|
|
2022-09-18 05:55:13 +00:00
|
|
|
typedef single_ptr< void > unk_singleptr;
|
2022-08-13 01:26:00 +00:00
|
|
|
CHECK_SIZEOF(unk_singleptr, 0x4);
|
2022-04-10 00:17:06 +00:00
|
|
|
} // namespace rstl
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _RSTL_SINGLE_PTR
|