More functionality for memory classes.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
872c275bc7
commit
74ac2dbbc3
|
@ -2,8 +2,7 @@
|
||||||
#define ARBUTILS_BORROWEDPTR_HPP
|
#define ARBUTILS_BORROWEDPTR_HPP
|
||||||
|
|
||||||
namespace Arbutils::Memory {
|
namespace Arbutils::Memory {
|
||||||
template <class T>
|
template <class T> class BorrowedPtr {
|
||||||
class BorrowedPtr{
|
|
||||||
T* _ptr;
|
T* _ptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -11,10 +10,15 @@ namespace Arbutils::Memory{
|
||||||
|
|
||||||
inline constexpr T* GetUnsafe() noexcept { return _ptr; }
|
inline constexpr T* GetUnsafe() noexcept { return _ptr; }
|
||||||
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
||||||
|
inline constexpr bool IsNull() const noexcept { return _ptr == nullptr; }
|
||||||
|
|
||||||
T* operator->() noexcept { return _ptr; }
|
T* operator->() noexcept { return _ptr; }
|
||||||
const T* operator->() const noexcept { return _ptr; }
|
const T* operator->() const noexcept { return _ptr; }
|
||||||
|
|
||||||
|
inline bool operator==(const BorrowedPtr& rhs) const noexcept { return _ptr == rhs._ptr; }
|
||||||
|
inline bool operator!=(const BorrowedPtr& rhs) const noexcept { return _ptr != rhs._ptr; }
|
||||||
|
inline bool operator==(const T* rhs) const noexcept { return _ptr == rhs; }
|
||||||
|
inline bool operator!=(const T* rhs) const noexcept { return _ptr != rhs; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,11 @@ namespace Arbutils::Memory {
|
||||||
|
|
||||||
T* operator->() noexcept { return _ptr; }
|
T* operator->() noexcept { return _ptr; }
|
||||||
const T* operator->() const noexcept { return _ptr; }
|
const T* operator->() const noexcept { return _ptr; }
|
||||||
|
|
||||||
|
inline bool operator==(const NonNullBorrowedPtr& rhs) const noexcept { return _ptr == rhs._ptr; }
|
||||||
|
inline bool operator!=(const NonNullBorrowedPtr& rhs) const noexcept { return _ptr != rhs._ptr; }
|
||||||
|
inline bool operator==(const T* rhs) const noexcept { return _ptr == rhs; }
|
||||||
|
inline bool operator!=(const T* rhs) const noexcept { return _ptr != rhs; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
#ifndef ARBUTILS_NONNULLOWNPTR_HPP
|
#ifndef ARBUTILS_NONNULLOWNPTR_HPP
|
||||||
#define ARBUTILS_NONNULLOWNPTR_HPP
|
#define ARBUTILS_NONNULLOWNPTR_HPP
|
||||||
|
|
||||||
#include "OwnPtr.hpp"
|
|
||||||
#include "../Assert.hpp"
|
#include "../Assert.hpp"
|
||||||
#include "NonNullBorrowedPtr.hpp"
|
#include "NonNullBorrowedPtr.hpp"
|
||||||
|
#include "OwnPtr.hpp"
|
||||||
|
|
||||||
namespace Arbutils::Memory {
|
namespace Arbutils::Memory {
|
||||||
template <class T> class NonNullOwnPtr {
|
template <class T> class NonNullOwnPtr {
|
||||||
T* _ptr;
|
T* _ptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline explicit NonNullOwnPtr(T* ptr) : _ptr(ptr){
|
inline explicit NonNullOwnPtr(T* ptr) : _ptr(ptr) { AssertNotNull(ptr); };
|
||||||
AssertNotNull(ptr);
|
|
||||||
};
|
|
||||||
|
|
||||||
NonNullOwnPtr<T>(const NonNullOwnPtr<T>&) = delete;
|
NonNullOwnPtr<T>(const NonNullOwnPtr<T>&) = delete;
|
||||||
NonNullOwnPtr<T>& operator=(OwnPtr<T> const&) = delete;
|
NonNullOwnPtr<T>& operator=(OwnPtr<T> const&) = delete;
|
||||||
|
@ -22,12 +20,15 @@ namespace Arbutils::Memory {
|
||||||
inline constexpr T* GetUnsafe() noexcept { return _ptr; }
|
inline constexpr T* GetUnsafe() noexcept { return _ptr; }
|
||||||
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
||||||
|
|
||||||
inline NonNullBorrowedPtr<T> Borrow(){
|
inline NonNullBorrowedPtr<T> Borrow() { return NonNullBorrowedPtr<T>(_ptr); }
|
||||||
return NonNullBorrowedPtr<T>(_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
T* operator->() noexcept { return _ptr; }
|
T* operator->() noexcept { return _ptr; }
|
||||||
const T* operator->() const noexcept { return _ptr; }
|
const T* operator->() const noexcept { return _ptr; }
|
||||||
|
|
||||||
|
inline bool operator==(const NonNullOwnPtr& rhs) const noexcept { return _ptr == rhs._ptr; }
|
||||||
|
inline bool operator!=(const NonNullOwnPtr& rhs) const noexcept { return _ptr != rhs._ptr; }
|
||||||
|
inline bool operator==(const T* rhs) const noexcept { return _ptr == rhs; }
|
||||||
|
inline bool operator!=(const T* rhs) const noexcept { return _ptr != rhs; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@ namespace Arbutils::Memory {
|
||||||
|
|
||||||
inline constexpr T* GetUnsafe() noexcept { return _ptr; }
|
inline constexpr T* GetUnsafe() noexcept { return _ptr; }
|
||||||
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
||||||
|
inline constexpr const T* IsNull() const noexcept {
|
||||||
|
return _ptr == nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
inline BorrowedPtr<T> Borrow(){
|
inline BorrowedPtr<T> Borrow(){
|
||||||
return BorrowedPtr<T>(_ptr);
|
return BorrowedPtr<T>(_ptr);
|
||||||
|
@ -25,6 +28,11 @@ namespace Arbutils::Memory {
|
||||||
|
|
||||||
T* operator->() noexcept { return _ptr; }
|
T* operator->() noexcept { return _ptr; }
|
||||||
const T* operator->() const noexcept { return _ptr; }
|
const T* operator->() const noexcept { return _ptr; }
|
||||||
|
|
||||||
|
inline bool operator==(const OwnPtr& rhs) const noexcept { return _ptr == rhs._ptr; }
|
||||||
|
inline bool operator!=(const OwnPtr& rhs) const noexcept { return _ptr != rhs._ptr; }
|
||||||
|
inline bool operator==(const T* rhs) const noexcept { return _ptr == rhs; }
|
||||||
|
inline bool operator!=(const T* rhs) const noexcept { return _ptr != rhs; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue