ScummVM API documentation
xml_tag.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_H
23#define QDENGINE_PARSER_XML_TAG_H
24
25#include "qdengine/qdengine.h"
26
27namespace QDEngine {
28
30namespace xml {
31
33class tag {
34public:
37
54 };
55
56 tag(int id = 0, tag_data_format data_fmt = TAG_DATA_VOID, int data_sz = 0, int data_offs = 0) : _ID(id), _data_format(data_fmt), _data_size(data_sz), _data_offset(data_offs), _data(NULL) { }
57 tag(const tag &tg) : _ID(tg._ID), _data_format(tg._data_format), _data_size(tg._data_size), _data_offset(tg._data_offset), _data(tg._data), _subtags(tg._subtags) { }
58 ~tag() { }
59 bool readTag(Common::SeekableReadStream *ff, tag &tg);
60
61 tag &operator = (const tag &tg) {
62 if (this == &tg) return *this;
63
64 _ID = tg._ID;
65 _data_format = tg._data_format;
66 _data_size = tg._data_size;
67 _data_offset = tg._data_offset;
68
69 _subtags = tg._subtags;
70
71 return *this;
72 }
73
75 int ID() const {
76 return g_engine->_tagMap[_ID - 1];
77 }
78
79 int origID() const {
80 return _ID;
81 }
82
85 return _data_format;
86 }
87
89
93 int data_size() const {
94 return _data_size;
95 }
97 int data_element_size() const {
98 switch (_data_format) {
99 case TAG_DATA_VOID:
100 return 0;
101 case TAG_DATA_SHORT:
103 return sizeof(uint16);
104 case TAG_DATA_INT:
105 return sizeof(int32);
107 return sizeof(uint32);
108 case TAG_DATA_FLOAT:
109 return sizeof(float);
110 case TAG_DATA_STRING:
111 return sizeof(byte);
112 }
113 return 0;
114 }
115
117 void set_data_size(int sz) {
118 _data_size = sz;
119 }
120
122 int data_offset() const {
123 return _data_offset;
124 }
126 void set_data_offset(int off) {
127 _data_offset = off;
128 }
129
131 const char *data() const {
132 return &*(_data->begin() + _data_offset);
133 }
134
137 _data = p;
138
139 for (subtags_t::iterator it = _subtags.begin(); it != _subtags.end(); ++it)
140 it->set_data(p);
141 }
142
144 void clear() {
145 _subtags.clear();
146 }
148
151 tag &add_subtag(const tag &tg) {
152 _subtags.push_back(tg);
153 return _subtags.back();
154 }
156 bool has_subtags() const {
157 return !_subtags.empty();
158 }
160 int num_subtags() const {
161 return _subtags.size();
162 }
165 return _subtags.begin();
166 }
169 return _subtags.end();
170 }
172 const tag *search_subtag(int subtag_id) const {
173 for (subtag_iterator it = subtags_begin(); it != subtags_end(); ++it)
174 if (it->ID() == subtag_id) return &*it;
175
176 return NULL;
177 }
178
179private:
180
182 int _ID;
184 tag_data_format _data_format;
186 int _data_size;
188 int _data_offset;
190 const Std::vector<char> *_data;
191
193 subtags_t _subtags;
194};
195
196} /* namespace xml */
197
198} // namespace QDEngine
199
200#endif // QDENGINE_PARSER_XML_TAG_H
iterator begin()
Definition: array.h:375
iterator begin()
Definition: list.h:266
size_type size() const
Definition: list.h:237
void clear()
Definition: list.h:245
t_T & back()
Definition: list.h:206
void push_back(const t_T &element)
Definition: list.h:174
iterator end()
Definition: list.h:279
bool empty() const
Definition: list.h:258
Definition: stream.h:745
XML тег.
Definition: xml_tag.h:33
const tag * search_subtag(int subtag_id) const
Поиск вложенного тега по его идентификатору.
Definition: xml_tag.h:172
void clear()
Очистка вложенных тегов.
Definition: xml_tag.h:144
void set_data_offset(int off)
Устанавливает смещение до данных тега в данных парсера.
Definition: xml_tag.h:126
int data_size() const
Возвращает количество элеметов данных тега.
Definition: xml_tag.h:93
int data_offset() const
Возвращает смещение до данных тега в данных парсера.
Definition: xml_tag.h:122
const char * data() const
Возвращает указатель на данные тега.
Definition: xml_tag.h:131
int num_subtags() const
Возвращает количество вложенных тэгов.
Definition: xml_tag.h:160
subtag_iterator subtags_begin() const
Возвращает итератор начала списка вложенных тегов.
Definition: xml_tag.h:164
int data_element_size() const
Возвращает размер элемента данных тега в байтах.
Definition: xml_tag.h:97
bool has_subtags() const
Возвращает true, если список вложенных тегов не пустой .
Definition: xml_tag.h:156
void set_data(const Std::vector< char > *p)
Устанавливает указатель на общие данные.
Definition: xml_tag.h:136
int ID() const
Возвращает идентификатор тега.
Definition: xml_tag.h:75
tag_data_format data_format() const
Возвращает формат данных тега.
Definition: xml_tag.h:84
tag & add_subtag(const tag &tg)
Добавляет вложенный тег.
Definition: xml_tag.h:151
void set_data_size(int sz)
Устанавливает количество элементов данных тега.
Definition: xml_tag.h:117
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
@ TAG_DATA_STRING
строковые данные
Definition: xml_tag.h:53
subtag_iterator subtags_end() const
Возвращает итератор конца списка вложенных тегов.
Definition: xml_tag.h:168
Базовый класс для игровых ресурсов.
Definition: console.h:28
Definition: list_intern.h:108
Definition: list_intern.h:54