Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
Stream.hh
1
#pragma once
2
3
#include <
Common.hh
>
4
5
namespace
Kinoko::EGG
{
6
8
class
Stream {
9
public
:
10
Stream();
11
virtual
~Stream();
12
13
virtual
void
read(
void
*output, u32 size) = 0;
14
virtual
void
write(
void
*input, u32 size) = 0;
15
virtual
bool
eof()
const
= 0;
16
virtual
bool
safe(u32 size)
const
= 0;
17
virtual
bool
bad()
const
= 0;
18
19
void
skip(u32 count);
20
void
jump(u32 index);
21
22
void
setEndian(std::endian endian) {
23
m_endian = endian;
24
}
25
26
[[nodiscard]] u32 index()
const
{
27
return
m_index;
28
}
29
30
[[nodiscard]] u8 read_u8();
31
[[nodiscard]] u16 read_u16();
32
[[nodiscard]] u32 read_u32();
33
[[nodiscard]] u64 read_u64();
34
[[nodiscard]] s8 read_s8();
35
[[nodiscard]] s16 read_s16();
36
[[nodiscard]] s32 read_s32();
37
[[nodiscard]] s64 read_s64();
38
[[nodiscard]] f32 read_f32();
39
[[nodiscard]] f64 read_f64();
40
41
void
write_u8(u8 val);
42
void
write_u16(u16 val);
43
void
write_u32(u32 val);
44
void
write_u64(u64 val);
45
void
write_s8(s8 val);
46
void
write_s16(s16 val);
47
void
write_s32(s32 val);
48
void
write_s64(s64 val);
49
void
write_f32(f32 val);
50
void
write_f64(f64 val);
51
52
protected
:
53
std::endian m_endian;
54
u32 m_index;
55
56
private
:
57
template
<ParseableType T>
58
[[nodiscard]] T read() {
59
ASSERT(safe(
sizeof
(T)));
60
T val;
61
read(&val,
sizeof
(val));
62
m_index +=
sizeof
(val);
63
64
return
parse<T>(val, m_endian);
65
}
66
67
template
<ParseableType T>
68
void
write(T val) {
69
ASSERT(safe(
sizeof
(T)));
70
T parsedVal = parse<T>(val, m_endian);
71
write(&parsedVal,
sizeof
(parsedVal));
72
m_index +=
sizeof
(parsedVal);
73
}
74
};
75
81
class
RamStream :
public
Stream {
82
public
:
83
RamStream();
84
RamStream(
const
void
*buffer, u32 size);
85
~RamStream()
override
=
default
;
86
87
void
read(
void
*output, u32 size)
override
;
88
void
write(
void
*input, u32 size)
override
;
89
90
[[nodiscard]]
bool
eof()
const override
{
91
return
m_index == m_size;
92
}
93
94
[[nodiscard]]
bool
safe(u32 size)
const override
{
95
return
m_index + size <= m_size;
96
}
97
98
[[nodiscard]]
bool
bad()
const override
{
99
return
m_index > m_size;
100
}
101
102
[[nodiscard]]
const
char
*read_string();
103
[[nodiscard]] RamStream
split
(u32 size);
104
void
setBufferAndSize(
void
*buffer, u32 size);
105
106
[[nodiscard]] u8 *data() {
107
return
m_buffer;
108
}
109
110
[[nodiscard]] u8 *dataAtIndex() {
111
return
m_buffer + m_index;
112
}
113
114
private
:
115
u8 *m_buffer;
116
u32 m_size;
117
};
118
119
}
// namespace Kinoko::EGG
Common.hh
This header houses common data types such as our integral types and enums.
Kinoko::EGG::RamStream::split
RamStream split(u32 size)
Splits the current stream into two.
Definition
Stream.cc:138
Kinoko::EGG
EGG core library.
Definition
Allocator.hh:5
egg
util
Stream.hh
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0