summaryrefslogtreecommitdiff
path: root/include/fud_allocator.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2025-01-04 12:02:45 -0600
committerDominick Allen <djallen@librehumanitas.org>2025-01-04 12:02:45 -0600
commit1d357adfa19725ee69fb267a363f1fd217b1272f (patch)
tree8d8710ba8ba7dff0b3da6b073fbb94f1a7b03ec5 /include/fud_allocator.hpp
parent0b400af9519444deef4cc6ad2c43c30e2092ab4f (diff)
Various style fixes.HEADmaster
Diffstat (limited to 'include/fud_allocator.hpp')
-rw-r--r--include/fud_allocator.hpp38
1 files changed, 22 insertions, 16 deletions
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 <cstddef>
-#include <limits>
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<std::byte*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override;
+ Result<std::byte*, FudStatus> 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<std::byte*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override;
+ Result<std::byte*, FudStatus> 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 <size_t Size>
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<std::byte*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override final {
+ Result<std::byte*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) final
+ {
using RetType = Result<std::byte*, FudStatus>;
static_cast<void>(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