This repository was archived by the owner on Dec 10, 2022. It is now read-only.
forked from ataulien/ZenLib
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathparserImpl.h
97 lines (85 loc) · 4.02 KB
/
parserImpl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "zenParser.h"
namespace ZenLoad
{
class ParserImpl {
public:
/**
* @brief Type of data in front of the chunks of the binSave-format
*/
enum EZenValueType
{
ZVT_0 = 0,
ZVT_STRING = 0x1,
ZVT_INT = 0x2,
ZVT_FLOAT = 0x3,
ZVT_BYTE = 0x4,
ZVT_WORD = 0x5,
ZVT_BOOL = 0x6,
ZVT_VEC3 = 0x7,
ZVT_COLOR = 0x8,
ZVT_RAW = 0x9,
ZVT_HASH = 0x12,
ZVT_10,
ZVT_11,
ZVT_12,
ZVT_13,
ZVT_14,
ZVT_15,
ZVT_RAW_FLOAT = 0x10,
ZVT_ENUM = 0x11,
};
ParserImpl(ZenParser* parser);
virtual ~ParserImpl() = default;
/**
* @brief Read the implementation specific header and stores it in the parsers main-header struct
*/
virtual void readImplHeader() = 0;
/**
* @brief Read the start of a chunk. [...] Returns true if there actually was a start.
* Otherwise it will leave m_Seek untouched and return false.
*/
virtual bool readChunkStart(ZenParser::ChunkHeader& header) = 0;
/**
* @brief Reads the end of a chunk. Returns true if there actually was an end.
* Otherwise it will leave m_Seek untouched and return false.
*/
virtual bool readChunkEnd() = 0;
/**
* @brief Reads a string
*/
virtual std::string readString() = 0;
virtual bool readString(char* buf, size_t size) = 0;
void readEntry(const char* name, std::string& target) { readEntryImpl(name, &target, 0, ZVT_STRING ); }
void readEntry(const char* name, uint8_t& target) { readEntryImpl(name, &target, sizeof(target), ZVT_BYTE ); }
void readEntry(const char* name, bool& target) { readEntryImpl(name, &target, sizeof(target), ZVT_BOOL ); }
void readEntry(const char* name, uint16_t& target) { readEntryImpl(name, &target, sizeof(target), ZVT_WORD ); }
void readEntry(const char* name, int16_t& target) { readEntryImpl(name, &target, sizeof(target), ZVT_WORD ); }
void readEntry(const char* name, uint32_t& target) { readEntryImpl(name, &target, sizeof(target), ZVT_INT ); }
void readColor(const char* name, uint32_t& target) { readEntryImpl(name, &target, sizeof(target), ZVT_COLOR ); }
void readEntry(const char* name, int32_t& target) { readEntryImpl(name, &target, sizeof(target), ZVT_INT ); }
void readEntry(const char* name, float& target) { readEntryImpl(name, &target, sizeof(target), ZVT_FLOAT ); }
void readEntry(const char* name, ZMath::float2& target) { readEntryImpl(name, &target, sizeof(target), ZVT_RAW_FLOAT); }
void readEntry(const char* name, ZMath::float3& target) { readEntryImpl(name, &target, sizeof(target), ZVT_VEC3 ); }
void readEntry(const char* name, ZMath::float4& target) { readEntryImpl(name, &target, sizeof(target), ZVT_RAW_FLOAT); }
void readEntry(const char* name, ZMath::Matrix& target) { readEntryImpl(name, &target, sizeof(target), ZVT_RAW_FLOAT); }
void readEntry(const char* name, Daedalus::ZString& tg) { std::string s; this->readEntry(name,s); tg = Daedalus::ZString(std::move(s)); }
void readEntry(const char* name, void* target, size_t size) { readEntryImpl(name, target, size, ZVT_RAW); }
/**
* @brief Reads the type of a single entry
*/
virtual void readEntryType(EZenValueType& type, size_t& size) = 0;
protected:
/**
* @brief Reads data of the expected type. Throws if the read type is not the same as specified and not 0
*/
virtual void readEntryImpl(const char* name, void* target, size_t targetSize, EZenValueType expectedType) = 0;
bool parseHeader(ZenParser::ChunkHeader& header, const char* vobDescriptor, size_t vobDescriptorLen);
ZenParser::ZenClass parseClassName(const char* name, size_t len);
static size_t valueTypeSize(EZenValueType t);
/**
* @brief Parser-Object this operates on
*/
ZenParser* m_pParser;
};
} // namespace ZenLoad