OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
binary.h
Go to the documentation of this file.
1 
8 #ifndef _UTILS_BINARY_H_
9 #define _UTILS_BINARY_H_
10 
11 #include <fstream>
12 #include <string>
13 
14 class BinaryReader {
15  public:
16  virtual ~BinaryReader();
17 
18  virtual long long tell() = 0;
19  virtual void seek(long long pos = 0) = 0;
20  virtual bool eof() = 0;
21 
22  virtual int8_t read8();
23  virtual uint8_t readU8();
24 
25  virtual int16_t read16();
26  virtual uint16_t readU16();
27 
28  virtual int32_t read32();
29  virtual uint32_t readU32();
30 
31  virtual int64_t read64();
32  virtual uint64_t readU64();
33 
34  virtual float readFloat();
35 
36  private:
37  virtual void read(char* d, int c) = 0;
38 };
39 
40 class BinaryFile : public BinaryReader {
41  public:
42  BinaryFile(std::string f = "");
43  virtual ~BinaryFile();
44 
45  int open(std::string f = "");
46 
47  virtual long long tell();
48  virtual void seek(long long pos = 0);
49  virtual bool eof();
50 
51  private:
52  virtual void read(char* d, int c);
53 
54  std::ifstream file;
55 };
56 
57 class BinaryMemory : public BinaryReader {
58  public:
59  BinaryMemory(const char* d = nullptr, long long max = -1);
60  virtual ~BinaryMemory();
61 
62  int open(const char* d = nullptr, long long max = -1);
63 
64  virtual long long tell();
65  virtual void seek(long long pos = 0);
66  virtual bool eof();
67 
68  private:
69  virtual void read(char* d, int c);
70 
71  const char* data;
72  long long offset;
73  long long max;
74 };
75 
76 #endif
77 
virtual void read(char *d, int c)=0
const char * data
Definition: binary.h:71
virtual uint8_t readU8()
Definition: binary.cpp:14
virtual int8_t read8()
Definition: binary.cpp:70
virtual void seek(long long pos=0)
Definition: binary.cpp:171
virtual ~BinaryMemory()
Definition: binary.cpp:150
virtual ~BinaryReader()
Definition: binary.cpp:11
virtual bool eof()
Definition: binary.cpp:176
virtual void read(char *d, int c)
Definition: binary.cpp:180
virtual long long tell()
Definition: binary.cpp:123
virtual void seek(long long pos=0)
Definition: binary.cpp:128
virtual int16_t read16()
Definition: binary.cpp:77
virtual ~BinaryFile()
Definition: binary.cpp:107
long long max
Definition: binary.h:73
std::ifstream file
Definition: binary.h:54
BinaryMemory(const char *d=nullptr, long long max=-1)
Definition: binary.cpp:146
virtual float readFloat()
Definition: binary.cpp:39
virtual bool eof()=0
virtual uint16_t readU16()
Definition: binary.cpp:21
virtual int64_t read64()
Definition: binary.cpp:93
virtual uint32_t readU32()
Definition: binary.cpp:27
virtual void seek(long long pos=0)=0
virtual int32_t read32()
Definition: binary.cpp:85
virtual bool eof()
Definition: binary.cpp:133
virtual long long tell()=0
long long offset
Definition: binary.h:72
virtual long long tell()
Definition: binary.cpp:166
virtual uint64_t readU64()
Definition: binary.cpp:33
virtual void read(char *d, int c)
Definition: binary.cpp:138
int open(const char *d=nullptr, long long max=-1)
Definition: binary.cpp:153
int open(std::string f="")
Definition: binary.cpp:112
BinaryFile(std::string f="")
Definition: binary.cpp:103