2020-02-15 00:08:27 +00:00
|
|
|
/** @copyright 2020 Sean Kasun */
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2020-02-17 23:58:22 +00:00
|
|
|
#include <vector>
|
2020-02-15 00:08:27 +00:00
|
|
|
|
|
|
|
typedef std::shared_ptr<class TheHandle> Handle;
|
|
|
|
|
|
|
|
class TheHandle {
|
|
|
|
public:
|
|
|
|
static Handle createFromFile(const char *filename);
|
2020-02-17 23:58:22 +00:00
|
|
|
static Handle createFromArray(const std::vector<uint8_t> &data);
|
2020-02-15 00:08:27 +00:00
|
|
|
~TheHandle();
|
|
|
|
bool isOpen() const;
|
|
|
|
bool eof() const;
|
|
|
|
int64_t tell() const;
|
|
|
|
|
|
|
|
uint32_t r32();
|
|
|
|
uint32_t r24();
|
|
|
|
uint16_t r16();
|
|
|
|
uint8_t r8();
|
2020-02-19 00:03:29 +00:00
|
|
|
std::string rs();
|
2020-02-15 00:08:27 +00:00
|
|
|
void seek(int64_t pos);
|
|
|
|
void skip(int64_t length);
|
2020-02-17 23:58:22 +00:00
|
|
|
std::string read(int32_t length);
|
|
|
|
std::vector<uint8_t> readBytes(int32_t length);
|
2020-02-23 07:54:26 +00:00
|
|
|
void dump(int64_t length, std::ostream &f);
|
2020-02-15 00:08:27 +00:00
|
|
|
|
|
|
|
int64_t length;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit TheHandle(const char *filename);
|
2020-02-17 23:58:22 +00:00
|
|
|
explicit TheHandle(const std::vector<uint8_t> &data);
|
2020-02-15 00:08:27 +00:00
|
|
|
uint8_t *data, *pos;
|
|
|
|
};
|