RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
buffer.h
1#ifndef BUFFER_H
2#define BUFFER_H
3
4#include <algorithm>
5#include <iostream>
6#include <string>
7#include <variant>
8#include <vector>
9#include "../common.h"
10#include "image.h"
11
12namespace Linker
13{
14 class Reader;
15 class Segment;
16 class Writer;
17
21 class Buffer : public Image
22 {
23 protected:
24 std::vector<uint8_t> data;
25
26 public:
27 Buffer() = default;
28
29 Buffer(size_t size)
30 {
31 data.resize(size);
32 }
33
34 Buffer(const std::vector<uint8_t>& data)
35 : data(data)
36 {
37 }
38
39 offset_t ImageSize() const override;
43 void Resize(offset_t new_size);
50 virtual offset_t Expand(offset_t new_size);
56 virtual offset_t WriteData(size_t bytes, offset_t offset, const void * buffer);
66 virtual offset_t WriteWord(size_t bytes, offset_t offset, uint64_t value, EndianType endiantype);
67
73 offset_t WriteWord(size_t bytes, offset_t offset, uint64_t value);
74
80 offset_t WriteWord(size_t bytes, uint64_t value, EndianType endiantype);
81
87 offset_t WriteWord(size_t bytes, uint64_t value);
88
96 virtual offset_t Append(const void * new_data, size_t length);
97
101 offset_t Append(const char * new_data);
102
106 offset_t Append(std::vector<uint8_t>& additional_data);
107
113 virtual void ReadFile(const std::shared_ptr<Reader>& rd);
119 void ReadFileRemaining(const std::shared_ptr<Reader>& rd);
125 void ReadFile(const std::shared_ptr<Reader>& rd, offset_t count);
129 static std::shared_ptr<Buffer> ReadFromFile(const std::shared_ptr<Reader>& rd);
135 static std::shared_ptr<Buffer> ReadFromFile(const std::shared_ptr<Reader>& rd, offset_t count);
137 offset_t WriteFile(const std::shared_ptr<Writer>& wr, offset_t count, offset_t offset = 0) const override;
138 size_t ReadData(size_t bytes, offset_t offset, void * buffer) const override;
139
140 friend class Section;
141 friend class Contents;
142 };
143}
144
145#endif /* BUFFER_H */
A buffer that can be used to read and store data from a file.
Definition buffer.h:22
static std::shared_ptr< Buffer > ReadFromFile(const std::shared_ptr< Reader > &rd)
Creates a buffer containing the remaining data in the reader.
Definition buffer.cc:94
void Resize(offset_t new_size)
Resize buffer.
Definition buffer.cc:14
virtual offset_t WriteData(size_t bytes, offset_t offset, const void *buffer)
Writes data into the buffer image.
Definition buffer.cc:33
virtual void ReadFile(const std::shared_ptr< Reader > &rd)
Overwrites buffer data with contents of reader.
Definition buffer.cc:79
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition buffer.cc:9
virtual offset_t Append(const void *new_data, size_t length)
Appends data at the end of a buffer.
Definition buffer.cc:62
void ReadFileRemaining(const std::shared_ptr< Reader > &rd)
Overwrites buffer data with contents of reader.
Definition buffer.cc:84
size_t ReadData(size_t bytes, offset_t offset, void *buffer) const override
Attempts to fill a buffer with data.
Definition buffer.cc:113
virtual offset_t Expand(offset_t new_size)
Increases the size of the buffer by the specified amount.
Definition buffer.cc:19
virtual offset_t WriteWord(size_t bytes, offset_t offset, uint64_t value, EndianType endiantype)
Append data to buffer.
Definition buffer.cc:40
offset_t WriteFile(const std::shared_ptr< Writer > &wr, offset_t count, offset_t offset=0) const override
Writes data of non-zero filled sections.
Definition buffer.cc:108
Represents abstract data contents whose data can be written to a file.
Definition image.h:17
virtual offset_t WriteFile(const std::shared_ptr< Writer > &wr) const =0
Writes data of non-zero filled sections.
Definition image.h:41
A section of data as read from an object file.
Definition section.h:28