Files
wc3re/TreFile.hh
Matthias Blankertz 89688c5fba treexplore: Add nested IFF parsing
Use IffFile to add an option to treexplore to show the structure of contained
IFF files
2015-04-22 17:19:42 +02:00

79 lines
1.6 KiB
C++

#ifndef WC3RE_TREFILE_HH__
#define WC3RE_TREFILE_HH__
#include <map>
#include <string>
#include <cstdio>
#include <vector>
#include <tuple>
class TreFile {
public:
TreFile(std::string const& filename);
TreFile(FILE* file, off_t start, off_t length);
~TreFile();
TreFile(TreFile const& copy) = delete;
TreFile& operator=(TreFile const& copy) = delete;
std::vector<std::string> getNames() const;
std::vector<uint32_t> getCRCs() const;
void dumpName(std::string path, std::string const& name);
void dumpCRC(std::string path, uint32_t crc);
void dumpAll(std::string path);
void printStructure();
class File {
public:
char const* data() const {
return data_.data();
}
size_t size() const {
return data_.size();
}
private:
std::vector<char> data_;
File(std::vector<char> data)
: data_(std::move(data)) {
}
friend class TreFile;
};
File openName(std::string const& name) const;
File openCRC(uint32_t crc) const;
struct Stat {
uint32_t size;
uint8_t flags;
};
Stat statName(std::string const& name) const;
Stat statCRC(uint32_t crc) const;
private:
void construct_();
size_t findName_(std::string const& name) const;
size_t findCRC_(uint32_t crc) const;
void dumpIdx_(std::string const& name, size_t table3Idx);
File openIdx_(size_t table3Idx) const;
Stat statIdx_(size_t table3Idx) const;
std::map<uint32_t, size_t> table1_;
std::map<std::string, size_t> table2_;
std::vector<std::tuple<uint32_t, uint32_t, uint8_t> > table3_;
mutable FILE* file_;
off_t start_;
size_t length_;
};
#endif