RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
writer.h
1#ifndef WRITER_H
2#define WRITER_H
3
4#include <iostream>
5#include <string>
6#include <vector>
7#include "../common.h"
8
9namespace Linker
10{
14 class Writer
15 {
16 public:
20 EndianType endiantype;
24 std::ostream * out;
25
26 Writer(EndianType endiantype, std::ostream * out = nullptr)
28 {
29 }
30
34 void WriteData(size_t count, const void * data);
35
39 size_t WriteData(size_t max_count, const std::vector<uint8_t>& data, size_t offset = 0);
40
44 size_t WriteData(const std::vector<uint8_t>& data, size_t offset = 0);
45
49 template <class T, std::size_t N>
50 void WriteData(const std::array<T, N>& data, size_t offset = 0)
51 {
52 if(offset >= N)
53 return;
54 WriteData(N - offset, reinterpret_cast<const char *>(data.data()) + offset);
55 }
56
60 void WriteData(size_t count, std::string text, char padding = '\0');
61
65 void WriteData(std::string text);
66
70 void WriteData(size_t count, std::istream& in);
71
75 void WriteWord(size_t bytes, uint64_t value, EndianType endiantype);
76
80 void WriteWord(size_t bytes, uint64_t value);
81
82 protected:
83 void ForceSeek(offset_t offset);
84
85 public:
89 void Seek(offset_t offset);
90
94 void Skip(offset_t offset);
95
99 void SeekEnd(offset_t offset = 0);
100
104 offset_t Tell();
105
109 void FillTo(offset_t position);
110
114 void AlignTo(offset_t align);
115 };
116}
117
118#endif /* WRITER_H */
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15
void Seek(offset_t offset)
Jump to a specific location in the ouput stream.
Definition writer.cc:95
void WriteData(size_t count, const void *data)
Write out a sequence of bytes.
Definition writer.cc:7
EndianType endiantype
The default endianness of the binary format, used for reading multibyte numeric data.
Definition writer.h:20
void Skip(offset_t offset)
Jump to a distance in the output stream.
Definition writer.cc:103
void SeekEnd(offset_t offset=0)
Jump to a specific offset from the end.
Definition writer.cc:112
void FillTo(offset_t position)
Move to a specific offset, fill with zeroes if needed.
Definition writer.cc:125
void AlignTo(offset_t align)
Align the current pointer.
Definition writer.cc:146
std::ostream * out
The input stream.
Definition writer.h:24
void WriteWord(size_t bytes, uint64_t value, EndianType endiantype)
Read a word.
Definition writer.cc:66
void WriteData(const std::array< T, N > &data, size_t offset=0)
Write out a sequence of bytes.
Definition writer.h:50
offset_t Tell()
Retrieve the current location.
Definition writer.cc:120