48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
#ifndef WC3RE_UTIL_HH__
|
|
#define WC3RE_UTIL_HH__
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
#include "common.hh"
|
|
|
|
class MmapFile {
|
|
public:
|
|
MmapFile(std::string fileName);
|
|
MmapFile(MmapFile const& copy) = delete;
|
|
MmapFile(MmapFile && move);
|
|
|
|
~MmapFile();
|
|
|
|
MmapFile& operator=(MmapFile const& copy) = delete;
|
|
MmapFile& operator=(MmapFile && move);
|
|
|
|
std::string const& name() const;
|
|
size_t size() const;
|
|
uint8_t const* data() const;
|
|
|
|
operator bool() const;
|
|
private:
|
|
std::string name_;
|
|
FILEUPtr fd_;
|
|
size_t size_;
|
|
void *base_;
|
|
};
|
|
|
|
// Helper functions to read big endian numbers
|
|
uint16_t readU16BE(uint8_t const* data);
|
|
uint32_t readU24BE(uint8_t const* data);
|
|
uint32_t readU32BE(uint8_t const* data);
|
|
|
|
// Helper functions to read little endian numbers
|
|
uint16_t readU16LE(uint8_t const* data);
|
|
uint32_t readU24LE(uint8_t const* data);
|
|
uint32_t readU32LE(uint8_t const* data);
|
|
|
|
// Sign-extend b starting at msb
|
|
int sextend(unsigned b, unsigned msb);
|
|
|
|
// Load simple resource from file
|
|
std::string fileToString(std::string const& name);
|
|
#endif
|