Mana
DataBuffer.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "../runner/common/Platform.h"
10 #include "../runner/common/Noncopyable.h"
11 #include <cstdlib>
12 #include <memory>
13 #include <string_view>
14 #include <vector>
15 
16 namespace mana
17 {
18  class OutputStream;
19 
20  /*
21  Data Section
22  データセクション
23  */
24  class DataBuffer final : Noncopyable
25  {
26  public:
27  DataBuffer() noexcept;
28  ~DataBuffer() = default;
29 
30  [[nodiscard]] const char* GetBuffer() const noexcept;
31 
32  [[nodiscard]] address_t GetSize() const noexcept;
33 
34  [[nodiscard]] address_t Get(const std::string_view& text) const noexcept;
35 
36  address_t Set(const std::string_view& text);
37 
38  bool Write(OutputStream& stream) const;
39 
40  private:
41  [[nodiscard]] address_t Find(const std::string_view& text) const noexcept;
42 
43  private:
44  std::vector<address_t> mEntities;
45  std::unique_ptr<char, decltype(&std::free)> mBuffer;
46  address_t mAllocatedSize = 0;
47  address_t mUsedSize = 0;
48  };
49 }
Definition: DataBuffer.h:25
address_t Get(const std::string_view &text) const noexcept
Definition: DataBuffer.cpp:30
~DataBuffer()=default
bool Write(OutputStream &stream) const
Definition: DataBuffer.cpp:62
const char * GetBuffer() const noexcept
Definition: DataBuffer.cpp:20
address_t Set(const std::string_view &text)
Definition: DataBuffer.cpp:35
DataBuffer() noexcept
Definition: DataBuffer.cpp:15
address_t GetSize() const noexcept
Definition: DataBuffer.cpp:25
Definition: OutputStream.h:15
Definition: CodeBuffer.cpp:12
std::uint32_t address_t
Definition: Type.h:31
Definition: Noncopyable.h:18