mirror of https://github.com/zeldaret/tmc.git
remove data copy from reader class
This commit is contained in:
parent
9e9dc07d23
commit
9cc2fcf9ea
|
|
@ -1,3 +0,0 @@
|
|||
#include "reader.h"
|
||||
#include "util.h"
|
||||
#include <string>
|
||||
|
|
@ -1,46 +1,36 @@
|
|||
#ifndef READER_H
|
||||
#define READER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
typedef int8_t s8;
|
||||
typedef int16_t s16;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t s64;
|
||||
#include <util/types.h>
|
||||
|
||||
class Reader {
|
||||
public:
|
||||
Reader(const std::vector<char>& baserom, int start, int size) {
|
||||
auto first = baserom.begin() + start;
|
||||
auto last = baserom.begin() + start + size;
|
||||
data = std::vector<char>(first, last);
|
||||
Reader(const std::vector<char>& baserom, int start, int size_) : data(baserom.data() + start), size(size_) {
|
||||
}
|
||||
|
||||
s8 read_s8() {
|
||||
[[nodiscard]] s8 read_s8() {
|
||||
// TODO range check
|
||||
return data[static_cast<unsigned long>(cursor++)];
|
||||
}
|
||||
|
||||
u8 read_u8() {
|
||||
[[nodiscard]] u8 read_u8() {
|
||||
return static_cast<u8>(read_s8());
|
||||
}
|
||||
|
||||
u16 read_u16() {
|
||||
[[nodiscard]] u16 read_u16() {
|
||||
return static_cast<u16>(read_u8() + (read_u8() << 8));
|
||||
}
|
||||
|
||||
u32 read_u32() {
|
||||
[[nodiscard]] u32 read_u32() {
|
||||
return static_cast<u32>(read_u16() + (read_u16() << 16));
|
||||
}
|
||||
|
||||
int cursor = 0;
|
||||
|
||||
private:
|
||||
std::vector<char> data;
|
||||
const char* data;
|
||||
const int size;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -4,20 +4,10 @@
|
|||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
typedef int8_t s8;
|
||||
typedef int16_t s16;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t s64;
|
||||
|
||||
void check_call(const std::vector<std::string>& cmd);
|
||||
|
||||
std::string opt_param(const std::string& format, int defaultVal, int value);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#include "util/types.h"
|
||||
#include "util/file.h"
|
||||
|
||||
int main() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef TOOLS_TYPES_H
|
||||
#define TOOLS_TYPES_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
using s8 = int8_t;
|
||||
using u8 = uint8_t;
|
||||
using s16 = int16_t;
|
||||
using u16 = uint16_t;
|
||||
using s32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using s64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
|
||||
#endif // TOOLS_TYPES_H
|
||||
Loading…
Reference in New Issue