47 lines
1.7 KiB
C++
47 lines
1.7 KiB
C++
// =====================================================================================================================
|
|
// fennec, a free and open source game engine
|
|
// Copyright (C) 2025 Medusa Slockbower
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//2
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
// =====================================================================================================================
|
|
|
|
#ifndef FENNEC_LANG_POINTERS_H
|
|
#define FENNEC_LANG_POINTERS_H
|
|
|
|
|
|
template<typename TypeT, class DeleteT = >
|
|
class unique_ptr
|
|
{
|
|
public:
|
|
using element_t = TypeT;
|
|
using pointer_t = element_t*;
|
|
|
|
constexpr unique_ptr() : unique_ptr(nullptr) {}
|
|
constexpr unique_ptr(pointer_t ptr) : _handle(ptr) {}
|
|
constexpr unique_ptr(unique_ptr&& other) : _handle(other._handle) { other._handle = nullptr; }
|
|
|
|
constexpr ~unique_ptr() { if(_handle) ::operator delete(_handle); }
|
|
|
|
constexpr unique_ptr& operator=(unique_ptr&& r) noexcept
|
|
{ _handle = r._handle; r._handle = nullptr; return *this; }
|
|
|
|
pointer_t release() { pointer_t retval = _handle; _handle = nullptr; return retval; }
|
|
|
|
|
|
private:
|
|
pointer_t _handle;
|
|
};
|
|
|
|
#endif // FENNEC_LANG_POINTERS_H
|