libassetmap  1.0.0
Hash-table based archive format containing compressed data
Classes | Public Member Functions | List of all members
AssetMap::MemMappedArchive Class Reference

Public Member Functions

 MemMappedArchive (IMemMapper &file, IDecompress &comp, const IHasher &hasher)
 Constructs a MemMappedArchive for reading from an archive You should construct a separate instance of this class along with a separate IDecompress for each thread. More...
 
 MemMappedArchive (const std::filesystem::directory_entry &ent, const IHasher &hasher, IMemMapper &file, ICompress &comp, IDecompress *decomp=nullptr)
 Constructs an instance for creating (optionally, reading) an archive. More...
 
lam_size_t BucketCount () const noexcept
 Obtains the total number of buckets in the archive. More...
 
lam_size_t EmptyBuckets () const noexcept
 Obtains the number of empty (unused) buckets in the archive. More...
 
lam_size_t DictionarySize () const noexcept
 Obtains the size (in bytes) of the ICompressor's dictionary. More...
 
MemMappedBucketEntry operator[] (std::string_view name) const noexcept
 Obtains the entry matching the specified name. More...
 
MemMappedBucket operator[] (lam_size_t idx) const noexcept
 Obtains the bucket for the given index. More...
 
Iterator begin () const noexcept
 Obtains an iterator to the first bucket in the archive. More...
 
Iterator end () const noexcept
 Obtains an iterator to one-past-the-end as for C++ iterators. More...
 

Constructor & Destructor Documentation

◆ MemMappedArchive() [1/2]

AssetMap::MemMappedArchive::MemMappedArchive ( IMemMapper &  file,
IDecompress &  comp,
const IHasher &  hasher 
)
explicit

Constructs a MemMappedArchive for reading from an archive You should construct a separate instance of this class along with a separate IDecompress for each thread.

Postcondition
Anything that causes a change to the archive may result in undefined behaviour. This should usually fail at the point of trying to write to the IMemMapper as it should have been opened in read-only mode.
Parameters
filean instance of an existing, readable IMemMapper instance consisting of an entire complete archive.
compan instance of the compatible decompressor for the implementation used to compress the instance
hasheran instance of the hash implementation used to create the archive.

◆ MemMappedArchive() [2/2]

AssetMap::MemMappedArchive::MemMappedArchive ( const std::filesystem::directory_entry &  ent,
const IHasher &  hasher,
IMemMapper &  file,
ICompress &  comp,
IDecompress *  decomp = nullptr 
)

Constructs an instance for creating (optionally, reading) an archive.

Postcondition
If no decompressor or a decompressor incompatible with the compressor is provided, the behaviour of any archive read functions is undefined. All interface refs must remain valid for the duration of this instance's lifetime and any objects retrieved through this instance. file will be altered. Existing data will be destroyed.
Parameters
entA directory which will be recursed to create the archive.
hasherA hasher which will be used to determine bucketing.
fileAn IMemMapper which can (and will) be resized.
compAn implementation used to compress files.
decompAn optional decompressor should you wish to immediately read data back.

Member Function Documentation

◆ begin()

Iterator AssetMap::MemMappedArchive::begin ( ) const
noexcept

Obtains an iterator to the first bucket in the archive.

Returns
Iterator to the first bucket. Will compare equal to end() if no buckets are present.

◆ BucketCount()

lam_size_t AssetMap::MemMappedArchive::BucketCount ( ) const
noexcept

Obtains the total number of buckets in the archive.

Returns
The number of buckets in the archive.

◆ DictionarySize()

lam_size_t AssetMap::MemMappedArchive::DictionarySize ( ) const
noexcept

Obtains the size (in bytes) of the ICompressor's dictionary.

Returns
The size of the dictionary or 0 if no dictionary is in use. A 0-size dictionary should never be present, but it will also return 0 in such a situation.

◆ EmptyBuckets()

lam_size_t AssetMap::MemMappedArchive::EmptyBuckets ( ) const
noexcept

Obtains the number of empty (unused) buckets in the archive.

Returns
the number of empty (unused) buckets.

◆ end()

Iterator AssetMap::MemMappedArchive::end ( ) const
noexcept

Obtains an iterator to one-past-the-end as for C++ iterators.

Returns
The one-past-the-end iterator.

◆ operator[]() [1/2]

MemMappedBucket AssetMap::MemMappedArchive::operator[] ( lam_size_t  idx) const
noexcept

Obtains the bucket for the given index.

Precondition
idx must be in the range 0 <= idx < BucketCount(). If there are no buckets, the behaviour is undefined.
Parameters
idxThe bucket index to retrieve.
Returns
A bucket object

◆ operator[]() [2/2]

MemMappedBucketEntry AssetMap::MemMappedArchive::operator[] ( std::string_view  name) const
noexcept

Obtains the entry matching the specified name.

Precondition
the instance must have been constructed with a valid and compatible IDecompress, IHasher and IMemMapper.
Postcondition
If the entry does not exist, the implementation may return either an object explicitly convertible to bool false or a valid object with a non-matching name. You must test both cases if you do not know in advance that the entry exists.
Parameters
nameThe name of the item to retrieve
Returns
a MemMappedBucketEntry object.

The documentation for this class was generated from the following file: