2022-04-11 22:42:08 +00:00
|
|
|
#ifndef _RSTL_AUTO_PTR_HPP
|
|
|
|
#define _RSTL_AUTO_PTR_HPP
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
namespace rstl {
|
|
|
|
template < typename T >
|
|
|
|
class auto_ptr {
|
2022-07-14 16:24:26 +00:00
|
|
|
mutable bool x0_has;
|
|
|
|
mutable T* x4_item;
|
2022-04-11 22:42:08 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
auto_ptr() : x0_has(false), x4_item(nullptr) {}
|
2022-07-14 16:24:26 +00:00
|
|
|
auto_ptr(T* ptr) : x0_has(ptr != nullptr), x4_item(ptr) {}
|
|
|
|
~auto_ptr() {
|
|
|
|
if (x0_has) {
|
|
|
|
delete x4_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO check
|
|
|
|
// auto_ptr(const auto_ptr& other) : x0_has(other.x0_has), x4_item(other.x4_item) {
|
|
|
|
// other.x0_has = false;
|
|
|
|
// }
|
|
|
|
// TODO check
|
|
|
|
// auto_ptr& operator=(const auto_ptr& other) {
|
|
|
|
// x0_has = other.x4_item != nullptr;
|
|
|
|
// x4_item = other.x4_item;
|
|
|
|
// other.x0_has = false;
|
|
|
|
// }
|
2022-04-11 22:42:08 +00:00
|
|
|
T* get() { return x4_item; }
|
2022-08-14 18:38:41 +00:00
|
|
|
/* const*/ T* get() const { return x4_item; }
|
2022-04-11 22:42:08 +00:00
|
|
|
T* operator->() { return get(); }
|
2022-08-13 01:26:00 +00:00
|
|
|
const T* operator->() const { return get(); }
|
2022-07-14 16:24:26 +00:00
|
|
|
T* release() const {
|
|
|
|
x0_has = false;
|
|
|
|
return x4_item;
|
|
|
|
}
|
2022-08-13 01:26:00 +00:00
|
|
|
operator bool() const { return x0_has; }
|
2022-04-11 22:42:08 +00:00
|
|
|
};
|
|
|
|
} // namespace rstl
|
|
|
|
|
|
|
|
#endif
|