From d133b0a6fbb3579b0cea7384834d4693aa32238b Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 11 Dec 2020 15:22:21 +0100 Subject: [PATCH] Adds documentation and fixes a couple issues. --- src/Memory/BorrowedPtr.hpp | 3 ++- src/Memory/OptionalBorrowedPtr.hpp | 9 ++++++++- src/Memory/OptionalUniquePtr.hpp | 3 ++- src/Memory/ScopedPtr.hpp | 7 +++++-- src/Memory/UniquePtr.hpp | 3 +++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Memory/BorrowedPtr.hpp b/src/Memory/BorrowedPtr.hpp index f923d69..f4ca895 100644 --- a/src/Memory/BorrowedPtr.hpp +++ b/src/Memory/BorrowedPtr.hpp @@ -32,7 +32,7 @@ namespace ArbUt { _raw = rhs._raw; return *this; } - + /// @brief Assign operator with raw pointer. inline BorrowedPtr& operator=(T* rhs) { if (_raw == &rhs) return *this; @@ -40,6 +40,7 @@ namespace ArbUt { _raw = rhs; return *this; } + /// @brief Don't allow nullptr assignments inline BorrowedPtr& operator=(std::nullptr_t) = delete; /// @brief Operator for access into underlying pointer. diff --git a/src/Memory/OptionalBorrowedPtr.hpp b/src/Memory/OptionalBorrowedPtr.hpp index bad57d6..d7b31e2 100644 --- a/src/Memory/OptionalBorrowedPtr.hpp +++ b/src/Memory/OptionalBorrowedPtr.hpp @@ -26,12 +26,19 @@ namespace ArbUt { ~OptionalBorrowedPtr() noexcept = default; /// @brief Copy operator. - inline OptionalBorrowedPtr& operator=(const BorrowedPtr& rhs) { + inline OptionalBorrowedPtr& operator=(const OptionalBorrowedPtr& rhs) { if (this == &rhs) return *this; _raw = rhs._raw; return *this; } + /// @brief Assign operator with raw pointer. + inline OptionalBorrowedPtr& operator=(T* rhs) { + if (_raw == &rhs) + return *this; + _raw = rhs; + return *this; + } /// @brief Return whether the pointer is null or not. [[nodiscard]] inline bool HasValue() const noexcept { return _raw == nullptr; } diff --git a/src/Memory/OptionalUniquePtr.hpp b/src/Memory/OptionalUniquePtr.hpp index 87ba440..90e510b 100644 --- a/src/Memory/OptionalUniquePtr.hpp +++ b/src/Memory/OptionalUniquePtr.hpp @@ -32,7 +32,8 @@ namespace ArbUt { return *this; } - inline OptionalUniquePtr& operator=(__attribute__((nonnull)) T* rhs) { + /// @brief Assign operator with raw pointer. + inline OptionalUniquePtr& operator=(T* rhs) { if (_raw == &rhs) return *this; _raw = rhs; diff --git a/src/Memory/ScopedPtr.hpp b/src/Memory/ScopedPtr.hpp index 6f69c1c..90188a7 100644 --- a/src/Memory/ScopedPtr.hpp +++ b/src/Memory/ScopedPtr.hpp @@ -30,17 +30,20 @@ namespace ArbUt { return *this; } + /// @brief Assign operator with raw pointer. inline ScopedPtr& operator=(T* rhs) { if (_raw == &rhs) return *this; - AssertNotNull(rhs); _raw = rhs; return *this; } /// @brief Operator for access into underlying pointer. /// @warning Note that this asserts that the underlying pointer is not null first, to prevent segfaults. - inline T* operator->() const noexcept { return _raw; } + inline T* operator->() const noexcept { + AssertNotNull(_raw); + return _raw; + } /// @brief Get the raw underlying pointer. inline T* TakeOwnership() const noexcept { diff --git a/src/Memory/UniquePtr.hpp b/src/Memory/UniquePtr.hpp index 08376b4..1888021 100644 --- a/src/Memory/UniquePtr.hpp +++ b/src/Memory/UniquePtr.hpp @@ -34,6 +34,7 @@ namespace ArbUt { return *this; } + /// @brief Assign operator with raw pointer. inline UniquePtr& operator=(T* rhs) { if (_raw == &rhs) { return *this; @@ -43,6 +44,8 @@ namespace ArbUt { _raw = rhs; return *this; } + + /// @brief Don't allow nullptr assignments inline UniquePtr& operator=(std::nullptr_t) = delete; /// @brief Operator for access into underlying pointer.