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 "../common.h"
7#include "format.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 void WriteData(size_t count, std::string text, char padding = '\0');
50
54 void WriteData(std::string text);
55
59 void WriteData(size_t count, std::istream& in);
60
64 void WriteWord(size_t bytes, uint64_t value, EndianType endiantype);
65
69 void WriteWord(size_t bytes, uint64_t value);
70
71 protected:
72 void ForceSeek(offset_t offset);
73
74 public:
78 void Seek(offset_t offset);
79
83 void Skip(offset_t offset);
84
88 void SeekEnd(offset_t offset = 0);
89
93 offset_t Tell();
94
98 void FillTo(offset_t position);
99
103 void AlignTo(offset_t align);
104 };
105}
106
107#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:94
void WriteData(size_t count, const void *data)
Write out a sequence of bytes.
Definition writer.cc:6
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:102
void SeekEnd(offset_t offset=0)
Jump to a specific offset from the end.
Definition writer.cc:111
void FillTo(offset_t position)
Move to a specific offset, fill with zeroes if needed.
Definition writer.cc:124
void AlignTo(offset_t align)
Align the current pointer.
Definition writer.cc:145
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:65
offset_t Tell()
Retrieve the current location.
Definition writer.cc:119