Mana
Buffer.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "common/Platform.h"
10 
11 namespace mana
12 {
16  class Buffer final : Noncopyable
17  {
18  public:
19  Buffer();
20  Buffer(const Buffer&) = delete;
21  Buffer(Buffer&&) noexcept = delete;
22  Buffer& operator=(const Buffer&) = delete;
23  Buffer& operator=(Buffer&&) noexcept = delete;
24  explicit Buffer(const address_t size);
25  ~Buffer() = default;
26 
30  void Clear();
31 
35  void Reset();
36 
41  void Allocate(const address_t size);
42 
47  void Release(const address_t size);
48 
55  template<typename T>
56  [[nodiscard]] T* GetAddressFromTop(const address_t index) const;
57 
64  template<typename T>
65  [[nodiscard]] T* GetAddressFromBottom(const address_t index) const;
66 
71  [[nodiscard]] address_t GetSize() const;
72 
77  void SetSize(const address_t size);
78 
84  bool operator==(const Buffer& other) const noexcept;
85 
91  bool operator!=(const Buffer& other) const noexcept;
92 
93  private:
94  std::unique_ptr<void, decltype(&std::free)> mBuffer;
95  address_t mAllocatedSize = 0;
96  address_t mUsedSize = 0;
97  };
98 }
99 
100 #include "Buffer.inl"
Definition: Buffer.h:17
T * GetAddressFromBottom(const address_t index) const
Definition: Buffer.inl:73
void Release(const address_t size)
Definition: Buffer.inl:59
T * GetAddressFromTop(const address_t index) const
Definition: Buffer.inl:65
void SetSize(const address_t size)
Definition: Buffer.inl:85
Buffer(const Buffer &)=delete
Buffer(Buffer &&) noexcept=delete
void Reset()
Definition: Buffer.inl:28
address_t GetSize() const
Definition: Buffer.inl:80
void Allocate(const address_t size)
Definition: Buffer.inl:34
void Clear()
Definition: Buffer.inl:23
Buffer()
Definition: Buffer.inl:12
Definition: CodeBuffer.cpp:12
std::uint32_t address_t
Definition: Type.h:31
Definition: Noncopyable.h:18