From 1d357adfa19725ee69fb267a363f1fd217b1272f Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sat, 4 Jan 2025 12:02:45 -0600 Subject: Various style fixes. --- include/fud_allocator.hpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'include/fud_allocator.hpp') diff --git a/include/fud_allocator.hpp b/include/fud_allocator.hpp index 95e1d5a..99b33ce 100644 --- a/include/fud_allocator.hpp +++ b/include/fud_allocator.hpp @@ -22,7 +22,6 @@ #include "fud_status.hpp" #include -#include namespace fud { @@ -32,6 +31,7 @@ extern std::byte* fudAlloc(size_t size); /** \brief The default deallocation function for globalFudAllocator. */ extern void fudFree(std::byte* ptr); +// NOLINTBEGIN(cppcoreguidelines-special-member-functions) class alignas(std::max_align_t) Allocator { public: virtual ~Allocator() = default; @@ -40,7 +40,7 @@ class alignas(std::max_align_t) Allocator { virtual void deallocate(std::byte* pointer, size_t bytes) = 0; - virtual bool isEqual(const Allocator& rhs) const = 0; + [[nodiscard]] virtual bool isEqual(const Allocator& rhs) const = 0; }; constexpr bool operator==(const Allocator& lhs, const Allocator& rhs) @@ -50,40 +50,44 @@ constexpr bool operator==(const Allocator& lhs, const Allocator& rhs) class FudAllocator : public Allocator { public: - virtual ~FudAllocator() override = default; + ~FudAllocator() override = default; - virtual Result allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override; + Result allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override; - virtual void deallocate(std::byte* pointer, size_t bytes) override; + void deallocate(std::byte* pointer, size_t bytes) override; - virtual bool isEqual(const Allocator& rhs) const override; + [[nodiscard]] bool isEqual(const Allocator& rhs) const override; }; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) extern FudAllocator globalFudAllocator; class NullAllocator : public Allocator { public: - virtual ~NullAllocator() override = default; + ~NullAllocator() override = default; - virtual Result allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override; + Result allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override; - virtual void deallocate(std::byte* pointer, size_t bytes) override; + void deallocate(std::byte* pointer, size_t bytes) override; - virtual bool isEqual(const Allocator& rhs) const override; + [[nodiscard]] bool isEqual(const Allocator& rhs) const override; }; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) extern NullAllocator globalNullAllocator; template class SimpleStackAllocator final : public Allocator { -private: + private: + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) std::byte m_memory[Size]{}; size_t m_allocated{0}; -public: - virtual ~SimpleStackAllocator() override final = default; + public: + ~SimpleStackAllocator() final = default; - virtual Result allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override final { + Result allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) final + { using RetType = Result; static_cast(alignment); if (bytes > Size - m_allocated) { @@ -96,7 +100,7 @@ public: return RetType::okay(data); } - virtual void deallocate(std::byte* pointer, size_t bytes) override final + void deallocate(std::byte* pointer, size_t bytes) final { if (pointer + bytes != m_memory + m_allocated) { m_allocated = Size; @@ -105,11 +109,13 @@ public: m_allocated -= bytes; } - virtual bool isEqual(const Allocator& rhs) const override final { + [[nodiscard]] bool isEqual(const Allocator& rhs) const final + { return &rhs == this; } }; } // namespace fud +// NOLINTEND(cppcoreguidelines-special-member-functions) #endif -- cgit v1.2.3