Generalized LZ-style decompression; extend MveDecoder to decode in-flight MVEs
This commit is contained in:
27
TreFile.hh
27
TreFile.hh
@@ -6,6 +6,7 @@
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <experimental/optional>
|
||||
|
||||
class TreFile {
|
||||
public:
|
||||
@@ -29,22 +30,28 @@ public:
|
||||
|
||||
Object(Object const& copy) = delete;
|
||||
Object(Object && move)
|
||||
: base_(move.base_), length_(move.length_) {
|
||||
: data_(std::move(move.data_)), base_(move.base_), length_(move.length_) {
|
||||
move.data_ = std::experimental::nullopt;
|
||||
move.base_ = nullptr;
|
||||
move.length_ = 0;
|
||||
}
|
||||
|
||||
Object& operator=(Object const& copy) = delete;
|
||||
Object& operator=(Object && move) {
|
||||
data_ = std::move(move.data_);
|
||||
base_ = move.base_;
|
||||
length_ = move.length_;
|
||||
move.data_ = std::experimental::nullopt;
|
||||
move.base_ = nullptr;
|
||||
move.length_ = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
char const* data() const {
|
||||
return base_;
|
||||
if (data_)
|
||||
return (char const*)(data_->data());
|
||||
else
|
||||
return base_;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
@@ -52,20 +59,32 @@ public:
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return base_;
|
||||
return data_ || base_;
|
||||
}
|
||||
|
||||
private:
|
||||
// Object either owns data (when decompressed) ...
|
||||
std::experimental::optional<std::vector<uint8_t> > data_;
|
||||
// .. or points to area in underlying data (when not compressed)
|
||||
char const* base_;
|
||||
size_t length_;
|
||||
|
||||
Object(char const* base, size_t length)
|
||||
: base_(base), length_(length) {
|
||||
: data_(), base_(base), length_(length) {
|
||||
}
|
||||
|
||||
Object(std::vector<uint8_t> data)
|
||||
: data_(std::move(data)), base_(nullptr), length_(data_->size()) {
|
||||
}
|
||||
|
||||
friend class TreFile;
|
||||
};
|
||||
|
||||
/* Open an object of the TRE file by name or by CRC
|
||||
* The returned object should be destroyed when no longer needed as it may
|
||||
* hold a memory allocation for its data. But it must not be used after the
|
||||
* TreFile object is destroyed.
|
||||
*/
|
||||
Object openName(std::string const& name) const;
|
||||
Object openCRC(uint32_t crc) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user