libassetmap  1.0.0
Hash-table based archive format containing compressed data
MemMappedBucketEntry.h
1 #ifndef LIBASSETMAP_MEMMAPPEDBUCKETENTRY_H
2 #define LIBASSETMAP_MEMMAPPEDBUCKETENTRY_H
3 
4 #include "ICompress.h"
5 #include "IDecompress.h"
6 
7 #include "MemOps.h"
8 
9 #include <cstdint>
10 #include <memory>
11 #include <string_view>
12 #include <utility>
13 
14 namespace AssetMap {
16  uint8_t* data = nullptr;
17  ICompress* comp = nullptr;
18  IDecompress* decomp = nullptr;
19 
20  void Name(std::string_view name) noexcept;
21 
22  [[nodiscard]] uint8_t* FileData() noexcept;
23 
24  [[nodiscard]] const uint8_t* FileData() const noexcept;
25 
26  void FileSize(lam_size_t size);
27 
28  public:
32  MemMappedBucketEntry(uint8_t* data, ICompress& comp);
33 
37  MemMappedBucketEntry(uint8_t* data, IDecompress& decomp);
38 
43  explicit MemMappedBucketEntry(std::nullptr_t);
44 
47  [[nodiscard]] lam_size_t FileSize() const noexcept;
48 
51  [[nodiscard]] lam_size_t DecompressedSize() const noexcept;
52 
56  [[nodiscard]] size_t InMemorySize() const noexcept;
57 
60  [[nodiscard]] std::string_view Name() const noexcept;
61 
70  [[nodiscard]] size_t Populate(std::string_view name,
71  const uint8_t* ptr,
72  size_t len) noexcept;
73 
76  [[nodiscard]] size_t MakeNull() noexcept;
77 
80  [[nodiscard]] std::pair<std::unique_ptr<uint8_t[]>, size_t> Retrieve();
81 
84  [[nodiscard]] size_t Retrieve(uint8_t* buf, size_t len);
85 
89  MemMappedBucketEntry& operator++() noexcept;
90 
96  [[nodiscard]] bool
97  operator==(const MemMappedBucketEntry& rhs) const noexcept;
98 
104  [[nodiscard]] bool
105  operator!=(const MemMappedBucketEntry& rhs) const noexcept;
106 
112  explicit operator bool() const noexcept;
113  };
114 } // namespace AssetMap
115 #endif // LIBASSETMAP_MEMMAPPEDBUCKETENTRY_H
AssetMap::MemMappedBucketEntry::InMemorySize
size_t InMemorySize() const noexcept
AssetMap::IDecompress
Definition: IDecompress.h:10
AssetMap::ICompress
Definition: ICompress.h:10
AssetMap::MemMappedBucketEntry::Populate
size_t Populate(std::string_view name, const uint8_t *ptr, size_t len) noexcept
Initialises this entry by compressing and writing the input data to ptr.
AssetMap::MemMappedBucketEntry::MemMappedBucketEntry
MemMappedBucketEntry(std::nullptr_t)
Constructs an instance not pointing to any data.
AssetMap::MemMappedBucketEntry::MemMappedBucketEntry
MemMappedBucketEntry(uint8_t *data, IDecompress &decomp)
Constructor to reference an existing entry for reading.
AssetMap::MemMappedBucketEntry::Retrieve
std::pair< std::unique_ptr< uint8_t[]>, size_t > Retrieve()
Allocates and returns the decompressed data and its size.
AssetMap::MemMappedBucketEntry::DecompressedSize
lam_size_t DecompressedSize() const noexcept
Obtains the size that would be required to fully decompress.
AssetMap::MemMappedBucketEntry::MakeNull
size_t MakeNull() noexcept
Initializes this entry to a size of zero and an empty name.
AssetMap::MemMappedBucketEntry
Definition: MemMappedBucketEntry.h:15
AssetMap::MemMappedBucketEntry::Name
std::string_view Name() const noexcept
Obtains the name of this entry.
AssetMap
Definition: DirectoryMetadata.h:65
AssetMap::MemMappedBucketEntry::FileSize
lam_size_t FileSize() const noexcept
Obtains the (compressed) size of this entry's file.
AssetMap::MemMappedBucketEntry::MemMappedBucketEntry
MemMappedBucketEntry(uint8_t *data, ICompress &comp)
Constructor to reference available space for writing.