ScummVM API documentation
xml_tag_buffer.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef QDENGINE_PARSER_XML_TAG_BUFFER_H
23#define QDENGINE_PARSER_XML_TAG_BUFFER_H
24
25#include "common/endian.h"
26#include "qdengine/parser/xml_tag.h"
27
28#ifdef _DEBUG
29#define XML_ASSERT(a) assert(a)
30#else
31#define XML_ASSERT(a)
32#endif
33
34namespace QDEngine {
35
36namespace xml {
37
39public:
40 tag_buffer(const tag &tg);
41 tag_buffer(const char *dp, int len);
42 tag_buffer(const tag_buffer &tb);
44
45 tag_buffer &operator = (const tag_buffer &tb);
46
47 tag_buffer &operator >= (int16 &var);
48 tag_buffer &operator >= (uint16 &var);
49 tag_buffer &operator >= (int &var);
50 tag_buffer &operator >= (uint32 &var);
51 tag_buffer &operator >= (float &var);
52
53 tag_buffer &operator > (int16 &var) {
54 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_SHORT);
55 var = (int16)READ_LE_UINT16(_data + _data_offset);
56 _data_offset += sizeof(int16);
57
58 return *this;
59 }
60 tag_buffer &operator > (uint16 &var) {
61 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_UNSIGNED_SHORT);
62 var = READ_LE_UINT16(_data + _data_offset);
63 _data_offset += sizeof(uint16);
64
65 return *this;
66 }
67 tag_buffer &operator > (int &var) {
68 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_INT);
69 var = (int32)READ_LE_UINT32(_data + _data_offset);
70 _data_offset += sizeof(int32);
71
72 return *this;
73 }
74 tag_buffer &operator > (uint32 &var) {
75 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_UNSIGNED_INT);
76 var = READ_LE_UINT32(_data + _data_offset);
77 _data_offset += sizeof(uint32);
78
79 return *this;
80 }
81 tag_buffer &operator > (float &var) {
82 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_FLOAT);
83 var = READ_LE_FLOAT32(_data + _data_offset);
84 _data_offset += 4;
85
86 return *this;
87 }
88
89 int16 get_short() {
90 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_SHORT);
91 int16 v;
92 *this > v;
93 return v;
94 }
95 uint16 get_ushort() {
96 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_UNSIGNED_SHORT);
97 uint16 v;
98 *this > v;
99 return v;
100 }
101 int get_int() {
102 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_INT);
103 int v;
104 *this > v;
105 return v;
106 }
107 uint32 get_uint() {
108 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_UNSIGNED_INT);
109 uint32 v;
110 *this > v;
111 return v;
112 }
113 float get_float() {
114 XML_ASSERT(data_format_ == tag::TAG_DATA_VOID || data_format_ == tag::TAG_DATA_FLOAT);
115 float v;
116 *this > v;
117 return v;
118 }
119
120 bool end_of_storage() const {
121 return _data_size > _data_offset;
122 }
123 void reset() {
124 _data_offset = 0;
125 }
126
127private:
128 int _data_size;
129 int _data_offset;
130
131#ifdef _DEBUG
132 tag::tag_data_format data_format_;
133#endif
134
135 const char *_data;
136};
137
138} /* namespace xml */
139
140} // namespace QDEngine
141
142#endif // QDENGINE_PARSER_XML_TAG_BUFFER_H
Definition: xml_tag_buffer.h:38
XML тег.
Definition: xml_tag.h:33
tag_data_format
Формат данных тега.
Definition: xml_tag.h:39
@ TAG_DATA_UNSIGNED_INT
данные типа uint32
Definition: xml_tag.h:49
@ TAG_DATA_UNSIGNED_SHORT
данные типа uint16 int
Definition: xml_tag.h:45
@ TAG_DATA_VOID
данные отсутствуют
Definition: xml_tag.h:41
@ TAG_DATA_INT
данные типа int
Definition: xml_tag.h:47
@ TAG_DATA_FLOAT
данные типа float
Definition: xml_tag.h:51
@ TAG_DATA_SHORT
данные типа int16 int
Definition: xml_tag.h:43
Базовый класс для игровых ресурсов.
Definition: console.h:28