MalachScript/src/Utils/ScopedPtr.hpp

32 lines
645 B
C++

#ifndef MALACHSCRIPT_SCOPEDPTR_HPP
#define MALACHSCRIPT_SCOPEDPTR_HPP
template <class T> class ScopedPtr {
T* _raw;
public:
inline ScopedPtr() { _raw = nullptr; }
inline ScopedPtr(T* ptr) { _raw = ptr; }
inline ScopedPtr& operator=(T* b) {
_raw = b;
return *this;
}
ScopedPtr(const ScopedPtr& b) = delete;
ScopedPtr& operator=(ScopedPtr const&) = delete;
inline ~ScopedPtr() { delete _raw; }
inline T* TakeOwnership() noexcept {
auto b = _raw;
_raw = nullptr;
return b;
}
inline T* operator->() { return _raw; }
};
#endif // MALACHSCRIPT_SCOPEDPTR_HPP