RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
reader.h
1#ifndef READER_H
2#define READER_H
3
4#include <cstring>
5#include <iostream>
6#include <string>
7#include <vector>
8#include "../common.h"
9
10namespace Linker
11{
15 class Reader
16 {
17 public:
21 EndianType endiantype;
25 std::istream * in;
26
27 Reader(EndianType endiantype, std::istream * in = nullptr)
29 {
30 }
31
35 void ReadData(size_t count, void * data);
36
40 void ReadData(size_t count, std::vector<uint8_t>& data, size_t offset = 0);
41
45 void ReadData(std::vector<uint8_t>& data, size_t offset = 0);
46
50 std::string ReadData(size_t count, bool terminate_at_null = false);
51
55 std::string ReadASCIIZ(size_t maximum = (size_t)-1);
56
60 uint64_t ReadUnsigned(size_t bytes, EndianType endiantype);
61
65 uint64_t ReadUnsigned(size_t bytes);
66
70 uint64_t ReadSigned(size_t bytes, EndianType endiantype);
71
75 uint64_t ReadSigned(size_t bytes);
76
80 void Seek(offset_t offset);
81
85 void Skip(offset_t offset);
86
90 void SeekEnd(relative_offset_t offset = 0);
91
95 offset_t Tell();
96 };
97}
98
99#endif /* READER_H */
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
void Skip(offset_t offset)
Jump to a distance in the input stream.
Definition reader.cc:81
void Seek(offset_t offset)
Jump to a specific location in the input stream.
Definition reader.cc:75
uint64_t ReadSigned(size_t bytes, EndianType endiantype)
Read a signed word.
Definition reader.cc:63
void SeekEnd(relative_offset_t offset=0)
Jump to end of the input stream.
Definition reader.cc:87
EndianType endiantype
The default endianness of the binary format, used for reading multibyte numeric data.
Definition reader.h:21
std::istream * in
The input stream.
Definition reader.h:25
void ReadData(size_t count, void *data)
Read in a sequence of bytes.
Definition reader.cc:6
std::string ReadASCIIZ(size_t maximum=(size_t) -1)
Read a zero terminated ASCII string.
Definition reader.cc:40
offset_t Tell()
Retrieve the current location.
Definition reader.cc:93
uint64_t ReadUnsigned(size_t bytes, EndianType endiantype)
Read an unsigned word.
Definition reader.cc:51