Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
binary.h
Go to the documentation of this file.
1#ifndef BINARY_H
2#define BINARY_H
3
4#include "dolphin/types.h"
5
6namespace JGadget {
7namespace binary {
8
9struct TEBit {
11};
12
14 TEBit* tebit);
15
17 return (arg0 + uAlign - 1) & ~(uAlign - 1);
18}
19
20struct TParseData {
21 TParseData(const void* pContent) : raw(pContent) {}
22
23 const void* getRaw() const { return raw; }
24 void setRaw(const void* p) { raw = p; }
25
26 /* 0x0 */ const void* raw;
27};
28
29template <int T>
31 TParseData_aligned(const void* pContent) : TParseData(pContent) {}
32 void setRaw(const void* p) {
33 /* if ((u32)p % T != 0) {
34 JUTWarn w;
35 w << "misaligned : " << (u32)p;
36 } */
37 static_cast<TParseData*>(this)->setRaw(p);
38 }
39};
40
41// Base for header and/or block parsing
43 virtual ~TParse_header_block();
44
45 virtual bool parseHeader_next(const void** ppData_inout, u32* puBlock_out, u32 arg2) = 0;
46 virtual bool parseBlock_next(const void** ppData_inout, u32* puData_out, u32 arg2) = 0;
47
48 bool parse_next(const void** ppData_inout, u32 a2);
49
50 bool parse(const void* ppData_inout, u32 a2) {
51 return parse_next(&ppData_inout, a2);
52 }
53
54 bool checkNext(const void** ptrLocation, u32* headerEnd, u32 idx) {
55 bool checkNext = false;
57 checkNext = true;
58 }
59 return checkNext;
60 }
61};
62
63template <typename T>
65 typedef T ParseType;
66 static T parse(const void* data) { return *(T*)data; }
67};
68
69template <typename T>
71 static T parse(const void* data) { return TParseValue_raw_::parse(data); }
72};
73
74template <typename T, template <class> class Parser>
75struct TParseValue : public Parser<T> {
76 static T parse(const void* data) { return Parser<T>::parse(data); }
77
78 static T parse(const void* data, s32 advanceNum) {
79 return Parser<T>::parse(advance(data, advanceNum));
80 }
81
82 static const void* advance(const void* data, s32 advanceNum) {
83 return (char*)data + (advanceNum * sizeof(T));
84 }
85};
86
87template<class Parser, int size>
89 TValueIterator(const void* begin) {
90 mBegin = begin;
91 }
92
93 const void* get() const { return mBegin; }
94
95 typename Parser::ParseType operator*() {
96 return *(typename Parser::ParseType*)get();
97 }
98
100 const_cast<u32*>(mBegin)++;
101 return *this;
102 }
103
105 TValueIterator old(*this);
106 ++(*this);
107 return old;
108 }
109
111 const_cast<u32*>(mBegin) += v;
112 return *this;
113 }
114
115 const void* mBegin;
116};
117
118template<typename T>
119struct TValueIterator_raw : public TValueIterator<TParseValue_raw_<u8>, 1> {
120 TValueIterator_raw(const void* begin) : TValueIterator<TParseValue_raw_<u8>, 1>(begin) {}
121};
122
123template <typename T>
125 static T parse(const void* data) { return TParseValue_raw_::parse(data); }
126};
127
128template<typename T>
133
134
136
137} // namespace binary
138} // namespace JGadget
139
140#endif /* BINARY_H */
T cLib_calcTimer(T *value)
Definition c_lib.h:74
static u16 data[4]
Definition d_vibration.cpp:114
p
Definition e_acos.c:98
double v
Definition e_pow.c:163
a
Definition k_cos.c:89
static const double T[]
Definition k_tan.c:106
u32 align_roundUp(u32 arg0, u32 uAlign)
Definition binary.h:16
bool operator==(TValueIterator< TParseValue_misaligned< u32 >, 4 > a, TValueIterator< TParseValue_misaligned< u32 >, 4 > b)
Definition binary.h:135
const void * parseVariableUInt_16_32_following(const void *pu16, u32 *pu32First, u32 *pu32Second, TEBit *tebit)
Definition binary.cpp:11
Definition std-vector.cpp:14
Definition binary.h:9
u32 value
Definition binary.h:10
TParseData_aligned(const void *pContent)
Definition binary.h:31
void setRaw(const void *p)
Definition binary.h:32
Definition binary.h:20
TParseData(const void *pContent)
Definition binary.h:21
void setRaw(const void *p)
Definition binary.h:24
const void * getRaw() const
Definition binary.h:23
const void * raw
Definition binary.h:26
static T parse(const void *data)
Definition binary.h:71
static T parse(const void *data)
Definition binary.h:125
Definition binary.h:64
static T parse(const void *data)
Definition binary.h:66
T ParseType
Definition binary.h:65
Definition binary.h:75
static T parse(const void *data)
Definition binary.h:76
static const void * advance(const void *data, s32 advanceNum)
Definition binary.h:82
static T parse(const void *data, s32 advanceNum)
Definition binary.h:78
virtual ~TParse_header_block()
Definition binary.cpp:39
virtual bool parseHeader_next(const void **ppData_inout, u32 *puBlock_out, u32 arg2)=0
bool parse(const void *ppData_inout, u32 a2)
Definition binary.h:50
bool parse_next(const void **ppData_inout, u32 a2)
Definition binary.cpp:44
bool checkNext(const void **ptrLocation, u32 *headerEnd, u32 idx)
Definition binary.h:54
virtual bool parseBlock_next(const void **ppData_inout, u32 *puData_out, u32 arg2)=0
TValueIterator_misaligned(const void *begin)
Definition binary.h:131
TValueIterator_misaligned(const TValueIterator_misaligned< T > &other)
Definition binary.h:130
TValueIterator_raw(const void *begin)
Definition binary.h:120
Definition binary.h:88
TValueIterator(const void *begin)
Definition binary.h:89
const void * get() const
Definition binary.h:93
const void * mBegin
Definition binary.h:115
const TValueIterator operator++(int)
Definition binary.h:104
Parser::ParseType operator*()
Definition binary.h:95
TValueIterator & operator++()
Definition binary.h:99
TValueIterator & operator+=(s32 v)
Definition binary.h:110
unsigned long u32
Definition types.h:10
signed long s32
Definition types.h:6
unsigned char u8
Definition types.h:8