CARLA
 
载入中...
搜索中...
未找到
pugixml.hpp
浏览该文件的文档.
1/**
2 * pugixml parser - version 1.9
3 * --------------------------------------------------------
4 * Copyright (C) 2006-2018, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
5 * Report bugs and download new versions at http://pugixml.org/
6 *
7 * This library is distributed under the MIT License. See notice at the end
8 * of this file.
9 *
10 * This work is based on the pugxml parser, which is:
11 * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
12 */
13
14#ifndef PUGIXML_VERSION
15// 定义版本宏;计算结果为主要版本 * 100 + 次要版本,以便在小于比较中安全使用。
16# define PUGIXML_VERSION 190
17#endif
18
19// 包含用户配置文件(这可以定义各种配置宏)
20#include "pugiconfig.hpp"
21
22#ifndef HEADER_PUGIXML_HPP
23#define HEADER_PUGIXML_HPP
24
25// 包含 stddef.h 以便使用 size_t 和 ptrdiff_t
26#include <stddef.h>
27
28// 包括XPath的异常头部
29#if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
30# include <exception>
31#endif
32
33// 包含STL头文件
34#ifndef PUGIXML_NO_STL
35# include <iterator>
36# include <iosfwd>
37# include <string>
38#endif
39
40// 已弃用功能的宏
41#ifndef PUGIXML_DEPRECATED
42# if defined(__GNUC__)
43# define PUGIXML_DEPRECATED __attribute__((deprecated))
44# elif defined(_MSC_VER) && _MSC_VER >= 1300
45# define PUGIXML_DEPRECATED __declspec(deprecated)
46# else
47# define PUGIXML_DEPRECATED
48# endif
49#endif
50
51// 如果没有定义API,则假定为默认值
52#ifndef PUGIXML_API
53# define PUGIXML_API
54#endif
55
56// 如果没有定义类的 API,则假定为默认值
57#ifndef PUGIXML_CLASS
58# define PUGIXML_CLASS PUGIXML_API
59#endif
60
61// 如果没有定义函数的API,则假设为默认值。
62#ifndef PUGIXML_FUNCTION
63# define PUGIXML_FUNCTION PUGIXML_API
64#endif
65
66//如果该平台已知具有长整型支持,请启用长整型功能。
67#ifndef PUGIXML_HAS_LONG_LONG
68# if __cplusplus >= 201103
69# define PUGIXML_HAS_LONG_LONG
70# elif defined(_MSC_VER) && _MSC_VER >= 1400
71# define PUGIXML_HAS_LONG_LONG
72# endif
73#endif
74
75// 如果已知该平台支持移动语义,则编译移动构造函数/操作符的实现。
76#ifndef PUGIXML_HAS_MOVE
77# if __cplusplus >= 201103
78# define PUGIXML_HAS_MOVE
79# elif defined(_MSC_VER) && _MSC_VER >= 1600
80# define PUGIXML_HAS_MOVE
81# endif
82#endif
83
84// HACK(安德烈):禁用异常,因为它们在虚幻引擎中不可用
85#define PUGIXML_NOEXCEPT
86
87//如果C++是2011或更高版本,添加'noexcept'说明符
88#ifndef PUGIXML_NOEXCEPT
89# if __cplusplus >= 201103
90# define PUGIXML_NOEXCEPT noexcept
91# elif defined(_MSC_VER) && _MSC_VER >= 1900
92# define PUGIXML_NOEXCEPT noexcept
93# else
94# define PUGIXML_NOEXCEPT
95# endif
96#endif
97
98// 某些函数在紧凑模式下不能是 noexcept。
99#ifdef PUGIXML_COMPACT
100# define PUGIXML_NOEXCEPT_IF_NOT_COMPACT
101#else
102# define PUGIXML_NOEXCEPT_IF_NOT_COMPACT PUGIXML_NOEXCEPT
103#endif
104
105// 如果C++是2011或更高版本,请添加'override'限定符。
106#ifndef PUGIXML_OVERRIDE
107# if __cplusplus >= 201103
108# define PUGIXML_OVERRIDE override
109# elif defined(_MSC_VER) && _MSC_VER >= 1700
110# define PUGIXML_OVERRIDE override
111# else
112# define PUGIXML_OVERRIDE
113# endif
114#endif
115
116// 字符接口宏
117#ifdef PUGIXML_WCHAR_MODE
118# define PUGIXML_TEXT(t) L ## t
119# define PUGIXML_CHAR wchar_t
120#else
121# define PUGIXML_TEXT(t) t
122# define PUGIXML_CHAR char
123#endif
124
125namespace pugi
126{
127 //用于所有内部存储和操作的字符类型;取决于 PUGIXML_WCHAR_MODE
129
130#ifndef PUGIXML_NO_STL
131 // String 类型,用于使用 STL 字符串的操作;取决于 PUGIXML_WCHAR_MODE
132 typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
133#endif
134}
135
136// PugiXML命名空间
137namespace pugi
138{
139 // 树节点类型
141 {
142 node_null, // 空(null)节点句柄
143 node_document, //文档树的绝对根
144 node_element, //元素标签,即 '<node/>'
145 node_pcdata, // 普通字符数据,即'text'
146 node_cdata, //字符数据,即 '<![CDATA[text]]>'
147 node_comment, // 评论标签,即 '<!-- text -->'
148 node_pi, // 处理指令,即 '<?name?>'
149 node_declaration, // 文档声明,即 '<?xml version="1.0"?>'
150 node_doctype // 文档类型声明,即 '<!DOCTYPE doc>'
151 };
152
153 // 解析选项
154
155 // 最小解析模式(相当于关闭所有其他标志)。
156 //仅元素和PCDATA部分被添加到DOM树中,未执行文本转换。
157 const unsigned int parse_minimal = 0x0000;
158
159 // 此标志用于确定是否将处理指令(节点_pi)添加到 DOM 树中。该标志默认处于关闭状态。
160 const unsigned int parse_pi = 0x0001;
161
162 // 此标志用于确定是否将注释(节点_注释)添加到 DOM 树中。该标志默认处于关闭状态。
163 const unsigned int parse_comments = 0x0002;
164
165 // 此标志用于确定是否将 CDATA(字符数据)段(节点_cdata)添加到 DOM 树中。该标志默认处于开启状态
166 const unsigned int parse_cdata = 0x0004;
167
168 // 此标志用于确定仅由空白字符组成的纯文本字符数据(节点_pcdata)是否被添加到 DOM 树中。
169 // 该标志默认处于关闭状态;将其开启通常会导致解析速度变慢以及内存消耗增加。
170 const unsigned int parse_ws_pcdata = 0x0008;
171
172 const unsigned int parse_escapes = 0x0010;
173
174 // 此标志用于确定在行结束(EOL)字符在解析过程中是否被规范化(转换为十六进制的 #xA)。该标志默认处于开启状态。
175 const unsigned int parse_eol = 0x0020;
176
177 // 此标志用于确定在解析期间是否依据 CDATA(字符数据)规范化规则对属性值进行规范化处理。该标志默认处于开启状态。
178 const unsigned int parse_wconv_attribute = 0x0040;
179
180 // 此标志用于确定在解析期间是否依据名称标记(NMTOKENS)规范化规则对属性值进行规范化处理。该标志默认处于关闭状态。
181 const unsigned int parse_wnorm_attribute = 0x0080;
182
183 // 此标志用于确定文档声明(节点_声明)是否被添加到 DOM 树中。该标志默认处于关闭状态。
184 const unsigned int parse_declaration = 0x0100;
185
186 // 此标志用于确定文档类型声明(节点_文档类型)是否被添加到 DOM 树中。该标志默认处于关闭状态。
187 const unsigned int parse_doctype = 0x0200;
188
189 //此标志用于确定纯文本字符数据(节点_pcdata)是否被添加到 DOM 树中,这类纯文本字符数据需满足是其父节点的唯一子节点,并且仅(由…… 组成,句子未完整,原句后面应该还有相关描述内容)。
190 // 仅由空白字符组成且为其父节点唯一子节点的纯文本字符数据(节点_pcdata)是否被添加到 DOM 树中。
191 // 该标志默认处于关闭状态;将其开启可能会导致解析速度变慢以及内存消耗增加。
192 const unsigned int parse_ws_pcdata_single = 0x0400;
193
194 //此标志用于确定是否要从纯文本字符数据中去除开头和结尾处的空白字符。该标志默认处于关闭状态。
195 const unsigned int parse_trim_pcdata = 0x0800;
196
197 //此标志用于确定没有父节点的纯文本字符数据是否被添加到 DOM 树中,以及空文档(句子似乎未表述完整,后面应该还有相关内容,比如空文档会怎样等进一步的说明)。
198 // 是否为空文档也算作有效文档。该标志默认处于关闭状态。
199 const unsigned int parse_fragment = 0x1000;
200
201 // 此标志用于确定纯文本字符数据是否存储在父元素的值中。这会极大地改变(句子似乎未表述完整,后面应该还有如 “改变什么的结构” 等相关内容)。
202 // 文档的结构;仅建议在内存受限的环境中解析包含大量纯文本字符数据(PCDATA)节点的文档时使用该标志。
203 //该标志默认是关闭的。
204 const unsigned int parse_embed_pcdata = 0x2000;
205
206 // 默认解析模式。
207 // 元素、可解析字符数据(PCDATA)以及字符数据(CDATA)部分会被添加到文档对象模型(DOM)树中,字符 / 引用实体将被展开,
208 //行结束符会被规范化,属性值会依据字符数据规范化规则进行规范化处理。
210
211 //完整解析模式。
212 //所有类型的节点都会被添加到文档对象模型(DOM)树中,字符 / 引用实体将被展开,
213 // 行结束符会被规范化,属性值会使用字符数据规范化规则进行规范化处理。
215
216 // 这些标志确定 XML 文档的输入数据的编码
218 {
219 encoding_auto, //使用 BOM 或 < / < 自动检测输入编码?检波;如果未找到 BOM,请使用 UTF8
220 encoding_utf8, // UTF8 编码
221 encoding_utf16_le, // 小端序 UTF16
222 encoding_utf16_be, // 大端序 UTF16
223 encoding_utf16, // 采用本机字节序的 UTF16
224 encoding_utf32_le, // 小端序 UTF32
225 encoding_utf32_be, //大端序 UTF32
226 encoding_utf32, // 采用本机字节序的 UTF32
227 encoding_wchar, // 与 wchar_t 相同的编码(UTF16 或 UTF32)
229 };
230
231 // 格式化标志
232
233 // 根据节点在 DOM 树中的深度,使用相应数量的缩进字符串对写入输出流的节点进行缩进。此标志默认处于开启状态。
234 const unsigned int format_indent = 0x01;
235
236 //将特定编码的字节顺序标记(BOM)写入输出流。此标志默认处于关闭状态。
237 const unsigned int format_write_bom = 0x02;
238
239 //使用原始输出模式(不进行缩进,也不写入换行符)。此标志默认处于关闭状态。
240 const unsigned int format_raw = 0x04;
241
242 // 即便文档中没有 XML 声明,也省略默认的 XML 声明。此标志默认处于关闭状态。
243 const unsigned int format_no_declaration = 0x08;
244
245 // 不对属性值和 PCDATA 内容进行转义。此标志默认处于关闭状态。
246 const unsigned int format_no_escapes = 0x10;
247
248 //在 xml_document::save_file 中使用文本模式打开文件。这会在某些系统上启用特殊字符(例如换行符)的转换。此标志默认处于关闭状态。
249 const unsigned int format_save_file_text = 0x20;
250
251 // 将每个属性写在新的一行,并带有适当的缩进。此标志默认处于关闭状态。
252 const unsigned int format_indent_attributes = 0x40;
253
254 // 不输出空元素标签,而是即便没有子元素,也显式地写出开始标签和结束标签。此标志默认处于关闭状态。
255 const unsigned int format_no_empty_element_tags = 0x80;
256
257 // 默认的格式化标志集。
258 //根据节点在 DOM 树中的深度对其进行缩进,如果文档没有默认声明则输出该声明。
259 const unsigned int format_default = format_indent;
260
261 //前置声明
263 struct xml_node_struct;
264
265 class xml_node_iterator;
268
269 class xml_tree_walker;
270
271 struct xml_parse_result;
272
273 class xml_node;
274
275 class xml_text;
276
277 #ifndef PUGIXML_NO_XPATH
278 class xpath_node;
279 class xpath_node_set;
280 class xpath_query;
281 class xpath_variable_set;
282 #endif
283
284 //基于范围的 for 循环支持
285 template <typename It> class xml_object_range
286 {
287 public:
288// 定义常量迭代器的类型别名
289 typedef It const_iterator;
290// 定义迭代器的类型别名
291 typedef It iterator;
292// 构造函数,通过传入起始迭代器和结束迭代器来初始化对象
293 xml_object_range(It b, It e): _begin(b), _end(e)
294 {
295 }
296// 返回起始迭代器(该函数为常量成员函数,返回值为常量迭代器类型)
297 It begin() const { return _begin; }
298// 返回结束迭代器(同样是常量成员函数,返回值为常量迭代器类型)
299 It end() const { return _end; }
300
301 private:
302// 用于存储起始迭代器和结束迭代器的私有成员变量
304 };
305
306 // 用于节点打印的写入器接口(可参考 xml_node::print 相关内容)
308 {
309 public:
310 virtual ~xml_writer() {}
311
312 //将内存块写入流 / 文件或其他对象中
313 virtual void write(const void* data, size_t size) = 0;
314 };
315
316 //针对 FILE的 xml_writer 实现类
318 {
319 public:
320 // 通过一个 FILE对象构造写入器;使用 void * 是为了避免头文件对 stdio 的依赖
321 xml_writer_file(void* file);
322
323 virtual void write(const void* data, size_t size) PUGIXML_OVERRIDE;
324
325 private:
326 void* file;
327 };
328
329 #ifndef PUGIXML_NO_STL
330 // 用于流的 xml_writer(XML 写入器)实现。
332 {
333 public:
334 //从一个输出流对象构造写入器。例如在相关代码中
335 xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
336 xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
337
338 virtual void write(const void* data, size_t size) PUGIXML_OVERRIDE;
339
340 private:
341 std::basic_ostream<char, std::char_traits<char> >* narrow_stream;
342 std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream;
343 };
344 #endif
345
346 // 一个用于操作文档对象模型(DOM)树中属性的轻量级句柄。
348 {
350 friend class xml_node;
351
352 private:
354
355 typedef void (*unspecified_bool_type)(xml_attribute***);
356
357 public:
358 //默认构造函数。构造一个空的属性。
360
361 // 从内部指针构造属性
362 explicit xml_attribute(xml_attribute_struct* attr);
363
364 // 安全布尔转换操作符
365 operator unspecified_bool_type() const;
366
367 //Borland C++ 解决办法
368 bool operator!() const;
369
370 // 比较操作符(比较所包装的属性指针)
371 bool operator==(const xml_attribute& r) const;
372 bool operator!=(const xml_attribute& r) const;
373 bool operator<(const xml_attribute& r) const;
374 bool operator>(const xml_attribute& r) const;
375 bool operator<=(const xml_attribute& r) const;
376 bool operator>=(const xml_attribute& r) const;
377
378 // 检查属性是否为空
379 bool empty() const;
380
381 // 获取属性名称 / 值,如果属性为空则返回 ""(空字符串)
382 const char_t* name() const;
383 const char_t* value() const;
384
385 // 获取属性值,如果属性为空则返回默认值
386 const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
387
388 //将属性值作为数字获取,如果转换不成功或者属性为空则返回默认值
389 int as_int(int def = 0) const;// 该函数用于将对象所代表的数据转换为unsigned int类型并返回
390// 参数def是默认值,默认值为0,调用函数时若没有传入参数则使用该默认值,函数声明为常成员函数,不会改变对象状态
391 unsigned int as_uint(unsigned int def = 0) const;// 该函数用于将对象所代表的数据转换为double类型并返回
392// 参数def是默认值,默认值为0,调用函数时若没有传入参数则使用该默认值,同样是常成员函数,不会对对象本身做修改
393 double as_double(double def = 0) const;// 该函数用于将对象所代表的数据转换为float类型并返回
394// 参数def是默认值,默认值为0,也是常成员函数,调用时若不传参就使用默认值,保证不改变对象的状态
395 float as_float(float def = 0) const;
396
397 #ifdef PUGIXML_HAS_LONG_LONG
398 long long as_llong(long long def = 0) const;
399 unsigned long long as_ullong(unsigned long long def = 0) const;
400 #endif
401
402 //将属性值作为布尔值获取(如果第一个字符在 '1tTyY' 集合中则返回 true,如果属性为空则返回默认值)
403 bool as_bool(bool def = false) const;
404
405 // 设置属性名称 / 值(如果属性为空或者内存不足则返回 false)
406 bool set_name(const char_t* rhs);
407 bool set_value(const char_t* rhs);
408
409 // 通过类型转换来设置属性值(数字会被转换为字符串,布尔值会被转换为 "true" 或 "false")
410 bool set_value(int rhs);
411 bool set_value(unsigned int rhs);
412 bool set_value(long rhs);
413 bool set_value(unsigned long rhs);
414 bool set_value(double rhs);
415 bool set_value(float rhs);
416 bool set_value(bool rhs);
417
418 #ifdef PUGIXML_HAS_LONG_LONG
419 bool set_value(long long rhs);
420 bool set_value(unsigned long long rhs);
421 #endif
422
423 //设置属性值(等同于不进行错误检查的 set_value 操作)
424 xml_attribute& operator=(const char_t* rhs);
425 xml_attribute& operator=(int rhs);
426 xml_attribute& operator=(unsigned int rhs);
427 xml_attribute& operator=(long rhs);
428 xml_attribute& operator=(unsigned long rhs);
429 xml_attribute& operator=(double rhs);
430 xml_attribute& operator=(float rhs);
431 xml_attribute& operator=(bool rhs);
432
433 #ifdef PUGIXML_HAS_LONG_LONG
434 xml_attribute& operator=(long long rhs);
435 xml_attribute& operator=(unsigned long long rhs);
436 #endif
437
438 // 获取父节点的属性列表中的下一个 / 上一个属性
439 xml_attribute next_attribute() const;
440 xml_attribute previous_attribute() const;
441
442 //获取哈希值(对于指向同一个对象的句柄来说是唯一的)
443 size_t hash_value() const;
444
445 // 获取内部指针
446 xml_attribute_struct* internal_object() const;
447 };
448
449#ifdef __BORLANDC__
450 //Borland C++ 解决办法
451 bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs);
452 bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs);
453#endif
454
455 //一个用于操作 DOM(文档对象模型)树中节点的轻量级句柄
456 class PUGIXML_CLASS xml_node// 定义名为xml_node的类,可能处于PUGIXML_CLASS相关的作用域下(具体取决于完整代码,可能是命名空间或类嵌套等情况)
457 {
458 friend class xml_attribute_iterator;// 声明xml_attribute_iterator类为xml_node类的友元类,意味着它可以访问xml_node类的私有和保护成员
459 friend class xml_node_iterator;// 声明xml_node_iterator类为xml_node类的友元类
460 friend class xml_named_node_iterator;// 声明xml_named_node_iterator类为xml_node类的友元类
461
462 protected:
463 xml_node_struct* _root;// 定义一个指向xml_node_struct类型的指针,xml_node_struct大概率是在别处定义的、与XML节点表示相关的结构体
464
465 typedef void (*unspecified_bool_type)(xml_node***);// 定义一个函数指针类型unspecified_bool_type,它指向的函数接收一个指向xml_node类型的三级指针作为参数,且函数无返回值
466 // 具体用途可能和xml_node类相关的布尔判断、回调等机制有关,需结合更多代码上下文才能明确其确切作用
467
468 public:
469 // 默认构造函数。构造一个空节点。
470 xml_node();
471
472 // 从内部指针构造节点
473 explicit xml_node(xml_node_struct* p);
474
475 // 安全布尔转换操作符
476 operator unspecified_bool_type() const;
477
478 // Borland C++ 解决办法
479 bool operator!() const;
480
481 // 比较操作符(比较所包装的节点指针)
482 bool operator==(const xml_node& r) const;
483 bool operator!=(const xml_node& r) const;
484 bool operator<(const xml_node& r) const;
485 bool operator>(const xml_node& r) const;
486 bool operator<=(const xml_node& r) const;
487 bool operator>=(const xml_node& r) const;
488
489 //检查节点是否为空。
490 bool empty() const;
491
492 // 获取节点类型
493 xml_node_type type() const;
494
495 // 获取节点名称,如果节点为空或者没有名称则返回 ""(空字符串)
496 const char_t* name() const;
497
498 // 获取节点名称,如果节点为空或者没有名称则返回 ""(空字符串)
499 // 注意:对于 <node>文本</node> 这样的形式,node.value () 并不会返回 "文本"!请使用 child_value () 或 text () 方法来访问节点内部的文本。
500 const char_t* value() const;
501
502 // 获取属性列表
503 xml_attribute first_attribute() const;
504 xml_attribute last_attribute() const;
505
506 // 获取子节点列表
507 xml_node first_child() const;
508 xml_node last_child() const;
509
510 //获取父节点的子节点列表中的下一个 / 上一个兄弟节点
511 xml_node next_sibling() const;
512 xml_node previous_sibling() const;
513
514 //获取父节点
515 xml_node parent() const;
516
517 // 获取此节点所属的 DOM(文档对象模型)树的根节点
518 xml_node root() const;
519
520 // 获取当前节点的文本对象
521 xml_text text() const;
522
523 // 获取具有指定名称的子节点、属性或下一个 / 上一个兄弟节点
524 xml_node child(const char_t* name) const;
525 xml_attribute attribute(const char_t* name) const;
526 xml_node next_sibling(const char_t* name) const;
527 xml_node previous_sibling(const char_t* name) const;
528
529 //从提示位置开始获取属性(并更新提示,以便快速搜索一系列属性)
530 xml_attribute attribute(const char_t* name, xml_attribute& hint) const;
531
532 // 获取当前节点的子节点值;也就是类型为 PCDATA(已解析字符数据)/CDATA(字符数据)的第一个子节点的值
533 const char_t* child_value() const;
534
535 // 获取具有指定名称的子节点的子节点值。等同于 child (name).child_value ()。
536 const char_t* child_value(const char_t* name) const;
537
538 //设置节点名称 / 值(如果节点为空、内存不足或者节点不能有名称 / 值,则返回 false)
539 bool set_name(const char_t* rhs);
540 bool set_value(const char_t* rhs);
541
542 //添加具有指定名称的属性。返回添加后的属性,若出错则返回空属性。
547
548 // 添加指定属性的副本。返回添加后的属性,若出错则返回空属性。
549 xml_attribute append_copy(const xml_attribute& proto);
550 xml_attribute prepend_copy(const xml_attribute& proto);
551 xml_attribute insert_copy_after(const xml_attribute& proto, const xml_attribute& attr);
552 xml_attribute insert_copy_before(const xml_attribute& proto, const xml_attribute& attr);
553
554 // 添加具有指定类型的子节点。返回添加后的节点,若出错则返回空节点。
555 xml_node append_child(xml_node_type type = node_element);
556 xml_node prepend_child(xml_node_type type = node_element);
557 xml_node insert_child_after(xml_node_type type, const xml_node& node);
558 xml_node insert_child_before(xml_node_type type, const xml_node& node);
559
560 // 添加具有指定名称的子元素。返回添加后的节点,若出错则返回空节点。
561 xml_node append_child(const char_t* name);
562 xml_node prepend_child(const char_t* name);
563 xml_node insert_child_after(const char_t* name, const xml_node& node);
564 xml_node insert_child_before(const char_t* name, const xml_node& node);
565
566 // 将指定节点的副本作为子节点添加。返回添加后的节点,若出错则返回空节点。
567 xml_node append_copy(const xml_node& proto);
568 xml_node prepend_copy(const xml_node& proto);
569 xml_node insert_copy_after(const xml_node& proto, const xml_node& node);
570 xml_node insert_copy_before(const xml_node& proto, const xml_node& node);
571
572 // 将指定节点移动使其成为此节点的子节点。返回移动后的节点,若出错则返回空节点。
573 xml_node append_move(const xml_node& moved);
574 xml_node prepend_move(const xml_node& moved);
575 xml_node insert_move_after(const xml_node& moved, const xml_node& node);
576 xml_node insert_move_before(const xml_node& moved, const xml_node& node);
577
578 //删除指定属性
579 bool remove_attribute(const xml_attribute& a);
580 bool remove_attribute(const char_t* name);
581
582 //删除指定子节点
583 bool remove_child(const xml_node& n);
584 bool remove_child(const char_t* name);
585
586 // 将缓冲区解析为一个 XML 文档片段,并将所有节点作为当前节点的子节点进行追加。
587 // 会复制 / 转换缓冲区内容,所以在函数返回后,该缓冲区可以被删除或更改。
588 //注意:append_buffer 会分配内存,其生命周期与所属文档相同;移除已追加的节点并不会立即回收该内存
589 xml_parse_result append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
590
591 // 使用谓词查找属性。返回使谓词返回为真的第一个属性。
592 template <typename Predicate> xml_attribute find_attribute(Predicate pred) const
593 {
594 if (!_root) return xml_attribute();
595
596 for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
597 if (pred(attrib))
598 return attrib;
599
600 return xml_attribute();
601 }
602
603 // 使用谓词查找子节点。返回使谓词返回值为真的第一个子节点。
604 template <typename Predicate> xml_node find_child(Predicate pred) const
605 {
606 if (!_root) return xml_node();
607
608 for (xml_node node = first_child(); node; node = node.next_sibling())
609 if (pred(node))
610 return node;
611
612 return xml_node();
613 }
614
615 //使用谓词从子树中查找节点。返回子树中(深度优先遍历的情况下)使谓词返回值为真的第一个节点。
616 template <typename Predicate> xml_node find_node(Predicate pred) const
617 {
618 if (!_root) return xml_node();
619
620 xml_node cur = first_child();
621
622 while (cur._root && cur._root != _root)
623 {
624 if (pred(cur)) return cur;
625
626 if (cur.first_child()) cur = cur.first_child();
627 else if (cur.next_sibling()) cur = cur.next_sibling();
628 else
629 {
630 while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
631
632 if (cur._root != _root) cur = cur.next_sibling();
633 }
634 }
635
636 return xml_node();
637 }
638
639 // 通过属性名称 / 值查找子节点
640 xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
641 xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
642
643 #ifndef PUGIXML_NO_STL
644 // 将从根节点开始的绝对节点路径作为文本字符串获取。
645 string_t path(char_t delimiter = '/') const;
646 #endif
647
648 //通过由节点名称以及 “.” 或 “..” 元素组成的路径来搜索节点。
649 xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;
650
651 // 使用 xml_tree_walker 递归遍历子树
652 bool traverse(xml_tree_walker& walker);
653
654 #ifndef PUGIXML_NO_XPATH
655 // 通过计算 XPath 查询来选择单个节点。返回结果节点集中的第一个节点。
656 xpath_node select_node(const char_t* query, xpath_variable_set* variables = 0) const;
657 xpath_node select_node(const xpath_query& query) const;
658
659 // 通过计算 XPath 查询来选择节点集
660 xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = 0) const;
661 xpath_node_set select_nodes(const xpath_query& query) const;
662
663 //已弃用:请改用 select_node)通过计算 XPath 查询来选择单个节点。
664 PUGIXML_DEPRECATED xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const;
665 PUGIXML_DEPRECATED xpath_node select_single_node(const xpath_query& query) const;
666
667 #endif
668
669 // 使用写入器对象打印子树
670 void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
671
672 #ifndef PUGIXML_NO_STL
673 //将子树打印到流中
674 void print(std::basic_ostream<char, std::char_traits<char> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
675 void print(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const;
676 #endif
677
678 // 子节点迭代器
680
681 iterator begin() const;
682 iterator end() const;
683
684 // 属性迭代器
686
687 attribute_iterator attributes_begin() const;
688 attribute_iterator attributes_end() const;
689
690 // 基于范围的 for 循环支持
692 xml_object_range<xml_named_node_iterator> children(const char_t* name) const;
694
695 //出于调试目的,获取节点在已解析文件 / 字符串中的偏移量(以 char_t 为单位)
696 ptrdiff_t offset_debug() const;
697
698 // 获取哈希值(对于指向同一个对象的句柄来说是唯一的)
699 size_t hash_value() const;
700
701 //获取内部指针
702 xml_node_struct* internal_object() const;
703 };
704
705#ifdef __BORLANDC__
706 //Borland C++ 解决办法
707 bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);
708 bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);
709#endif
710
711 //一个用于处理已解析字符数据(PCDATA)节点内文本的辅助工具
713 {
714 friend class xml_node;
715
717
718 typedef void (*unspecified_bool_type)(xml_text***);
719
720 explicit xml_text(xml_node_struct* root);
721
722 xml_node_struct* _data_new();
723 xml_node_struct* _data() const;
724
725 public:
726 //默认构造函数。构造一个空对象。
727 xml_text();
728
729 //安全布尔转换操作符
730 operator unspecified_bool_type() const;
731
732 // Borland C++ 解决办法
733 bool operator!() const;
734
735 //检查文本对象是否为空
736 bool empty() const;
737
738 // 获取文本内容,如果对象为空则返回 ""(空字符串)
739 const char_t* get() const;
740
741 //获取文本内容,如果对象为空则返回默认值
742 const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
743
744 // 将文本内容作为数字获取,如果转换不成功或者对象为空则返回默认值
745 int as_int(int def = 0) const;
746 unsigned int as_uint(unsigned int def = 0) const;
747 double as_double(double def = 0) const;
748 float as_float(float def = 0) const;
749
750 #ifdef PUGIXML_HAS_LONG_LONG
751 long long as_llong(long long def = 0) const;
752 unsigned long long as_ullong(unsigned long long def = 0) const;
753 #endif
754
755 // 将文本内容作为布尔值获取(如果第一个字符在 '1tTyY' 集合中则返回 true,如果对象为空则返回默认值)
756 bool as_bool(bool def = false) const;
757
758 //设置文本(如果对象为空或者内存不足则返回 false)
759 bool set(const char_t* rhs);
760
761 //通过类型转换来设置文本(数字会被转换为字符串,布尔值会被转换为 "true" 或 "false")
762 bool set(int rhs);
763 bool set(unsigned int rhs);
764 bool set(long rhs);
765 bool set(unsigned long rhs);
766 bool set(double rhs);
767 bool set(float rhs);
768 bool set(bool rhs);
769
770 #ifdef PUGIXML_HAS_LONG_LONG
771 bool set(long long rhs);
772 bool set(unsigned long long rhs);
773 #endif
774
775 // 设置文本(等同于不进行错误检查的设置操作)
776 xml_text& operator=(const char_t* rhs);
777 xml_text& operator=(int rhs);
778 xml_text& operator=(unsigned int rhs);
779 xml_text& operator=(long rhs);
780 xml_text& operator=(unsigned long rhs);
781 xml_text& operator=(double rhs);
782 xml_text& operator=(float rhs);
783 xml_text& operator=(bool rhs);
784
785 #ifdef PUGIXML_HAS_LONG_LONG
786 xml_text& operator=(long long rhs);
787 xml_text& operator=(unsigned long long rhs);
788 #endif
789
790 // 获取此对象的数据节点(已解析字符数据节点 node_pcdata 或者字符数据节点 node_cdata)
791 xml_node data() const;
792 };
793
794#ifdef __BORLANDC__
795 //Borland C++ 解决办法
796 bool PUGIXML_FUNCTION operator&&(const xml_text& lhs, bool rhs);
797 bool PUGIXML_FUNCTION operator||(const xml_text& lhs, bool rhs);
798#endif
799
800 // 子节点迭代器(一个针对 xml_node 集合的双向迭代器)
802 {
803 friend class xml_node;
804
805 private:
808
810
811 public:
812 // 迭代器特性
813 typedef ptrdiff_t difference_type;
817
818 #ifndef PUGIXML_NO_STL
819 typedef std::bidirectional_iterator_tag iterator_category;
820 #endif
821
822 // 默认构造函数
824
825 //构造一个指向指定节点的迭代器
826 xml_node_iterator(const xml_node& node);
827
828 // 迭代器运算符
829 bool operator==(const xml_node_iterator& rhs) const;
830 bool operator!=(const xml_node_iterator& rhs) const;
831
832 xml_node& operator*() const;
833 xml_node* operator->() const;
834
835 const xml_node_iterator& operator++();
836 xml_node_iterator operator++(int);
837
838 const xml_node_iterator& operator--();
839 xml_node_iterator operator--(int);
840 };
841
842 // 属性迭代器(一个针对 xml_attribute 集合的双向迭代器)
844 {
845 friend class xml_node;
846
847 private:
850
852
853 public:
854 // 迭代器特性
855 typedef ptrdiff_t difference_type;
859
860 #ifndef PUGIXML_NO_STL
861 typedef std::bidirectional_iterator_tag iterator_category;
862 #endif
863
864 //默认构造函数
866
867 //构造一个指向指定属性的迭代器
868 xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);
869
870 // 迭代器运算符
871 bool operator==(const xml_attribute_iterator& rhs) const;
872 bool operator!=(const xml_attribute_iterator& rhs) const;
873
874 xml_attribute& operator*() const;
875 xml_attribute* operator->() const;
876
877 const xml_attribute_iterator& operator++();
878 xml_attribute_iterator operator++(int);
879
880 const xml_attribute_iterator& operator--();
881 xml_attribute_iterator operator--(int);
882 };
883
884 // 命名节点范围辅助类
886 {
887 friend class xml_node;
888
889 public:
890 // 迭代器特性
891 typedef ptrdiff_t difference_type;
895
896 #ifndef PUGIXML_NO_STL
897 typedef std::bidirectional_iterator_tag iterator_category;
898 #endif
899
900 // 默认构造函数
902
903 // 构造一个指向指定节点的迭代器
904 xml_named_node_iterator(const xml_node& node, const char_t* name);
905
906 // 迭代器运算符
907 bool operator==(const xml_named_node_iterator& rhs) const;
908 bool operator!=(const xml_named_node_iterator& rhs) const;
909
910 xml_node& operator*() const;
911 xml_node* operator->() const;
912
913 const xml_named_node_iterator& operator++();
914 xml_named_node_iterator operator++(int);
915
916 const xml_named_node_iterator& operator--();
917 xml_named_node_iterator operator--(int);
918
919 private:
922 const char_t* _name;
923
925 };
926
927 // 抽象树遍历器类(详见 xml_node::traverse 方法)
929 {
930 friend class xml_node;
931
932 private:
934
935 protected:
936 //获取当前遍历深度
937 int depth() const;
938
939 public:
941 virtual ~xml_tree_walker();
942
943 // 遍历开始时调用的回调函数
944 virtual bool begin(xml_node& node);
945
946 // 遍历每个节点时调用的回调函数
947 virtual bool for_each(xml_node& node) = 0;
948
949 // 遍历结束时调用的回调函数
950 virtual bool end(xml_node& node);
951 };
952
953 // 解析状态,作为 xml_parse_result 对象的一部分返回
955 {
956 status_ok = 0, // 无错误
957
958 status_file_not_found, //在 load_file () 方法执行期间文件未找到
959 status_io_error, // 从文件 / 流读取时出错
960 status_out_of_memory, // 无法分配内存
961 status_internal_error, // 发生内部错误
962 status_unrecognized_tag, // 解析器无法确定标签类型
963
964 status_bad_pi, // 在解析文档声明 / 处理指令时发生解析错误
965 status_bad_comment, // 在解析注释时发生解析错误
966 status_bad_pi, //在解析 CDATA(字符数据)区段时发生解析错误
967 status_bad_cdata, // P在解析文档类型声明时发生解析错误
968 status_bad_doctype, // 在解析 PCDATA(已解析字符数据)区段时发生解析错误
969 status_bad_pcdata, // 在解析起始元素标签时发生解析错误
970 status_bad_start_element, // 在解析结束元素标签时发生解析错误
971 status_bad_attribute, // 在解析结束元素标签时发生解析错误
972 status_bad_end_element, // Parsing error occurred while parsing end element tag
973 status_end_element_mismatch,// 存在起始 - 结束标签不匹配的情况(结束标签名称不正确、某些标签未关闭或者存在多余的结束标签)
974 status_append_invalid_root, // 由于根节点类型不是 node_element(元素节点)或 node_document(文档节点),所以无法追加节点(这是 xml_node::append_buffer 方法特有的情况)
975
976 status_no_document_element //解析后得到的文档中没有元素节点
977 };
978
979 // 解析结果
981 {
982 // 解析状态(参见 xml_parse_status)
984
985 // 最后解析的偏移量(以 char_t 为单位,从输入数据起始处开始计算)
986 ptrdiff_t offset;
987
988 // 源文档编码
990
991 // 默认构造函数,将对象初始化为失败状态
993
994 // 转换为布尔类型的运算符
995 operator bool() const;
996
997 // 获取错误描述
998 const char* description() const;
999 };
1000
1001 // 文档类(DOM 树的根节点)
1003 {
1004 private:
1006
1007 char _memory[192];
1008
1009 // 不可复制语义
1012
1013 void _create();
1014 void _destroy();
1016
1017 public:
1018 // 默认构造函数,创建一个空文档
1019 xml_document();
1020
1021 //析构函数,使指向此文档的所有节点 / 属性句柄失效
1022 ~xml_document();
1023
1024 #ifdef PUGIXML_HAS_MOVE
1025 //移动语义支持
1028 #endif
1029
1030 // 移除所有节点,留下一个空文档
1031 void reset();
1032
1033 //移除所有节点,然后复制指定文档的全部内容
1034 void reset(const xml_document& proto);
1035
1036 #ifndef PUGIXML_NO_STL
1037 //从流中加载文档。
1038 xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1039 xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream, unsigned int options = parse_default);
1040 #endif
1041
1042 // (已弃用:请改用 load_string)从以零结尾的字符串中加载文档。不应用编码转换。
1043 PUGIXML_DEPRECATED xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
1044
1045 //从以零结尾的字符串中加载文档。不应用编码转换。
1046 xml_parse_result load_string(const char_t* contents, unsigned int options = parse_default);
1047
1048 // 从文件中加载文档
1049 xml_parse_result load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1050 xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1051
1052 // 从缓冲区加载文档。会复制 / 转换缓冲区内容,所以在函数返回后,该缓冲区可以被删除或更改。
1053 xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1054
1055 // 从缓冲区加载文档,使用该缓冲区进行原地解析(缓冲区会被修改并用于存储文档数据)。
1056 //你应当确保缓冲区数据在文档的整个生命周期内都持续存在,并且在文档销毁后手动释放缓冲区内存。
1057 xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1058
1059 // 从缓冲区加载文档,使用该缓冲区进行原地解析(缓冲区会被修改并用于存储文档数据)。
1060 //你应当使用 pugixml 分配函数来分配缓冲区;文档在不再需要该缓冲区时会自动释放它(之后你不能再使用该缓冲区了)。
1061 xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1062
1063 // 将 XML 文档保存到写入器(其语义与 xml_node::print 稍有不同,详见相关文档)。
1064 void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1065
1066 #ifndef PUGIXML_NO_STL
1067 //将 XML 文档保存到流中(其语义与 xml_node::print 稍有不同,详见相关文档)。
1068 void save(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1069 void save(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const;
1070 #endif
1071
1072 //将 XML 保存到文件
1073 bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1074 bool save_file(const wchar_t* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1075
1076 // 获取文档元素
1077 xml_node document_element() const;
1078 };
1079
1080#ifndef PUGIXML_NO_XPATH
1081 // XPath 查询返回类型
1083 {
1084 xpath_type_none, // 未知类型(查询未能编译成功)
1085 xpath_type_node_set, //节点集(xpath_node_set 类型)
1087 xpath_type_string, // 字符串
1088 xpath_type_boolean // 布尔值
1090
1091 // XPath 解析结果
1093 {
1094 // 错误消息(若无错误则为 0)
1095 const char* error;
1096
1097 // 最后解析的偏移量(以 char_t 为单位,从字符串起始处开始计算)
1098 ptrdiff_t offset;
1099
1100 // 默认构造函数,将对象初始化为失败状态
1102
1103 //转换为布尔类型的运算符
1104 operator bool() const;
1105
1106 // 获取错误描述
1107 const char* description() const;
1108 };
1109
1110 //单个 XPath 变量
1112 {
1114
1115 protected:
1118
1120
1121 // 不可复制语义
1124
1125 public:
1126 // 获取变量名称
1127 const char_t* name() const;
1128
1129 // 获取变量类型
1130 xpath_value_type type() const;
1131
1132 // 获取变量值;不进行类型转换,若出现类型不匹配错误则返回默认值(false、非数字、空字符串、空节点集)
1133 bool get_boolean() const;
1134 double get_number() const;
1135 const char_t* get_string() const;
1136 const xpath_node_set& get_node_set() const;
1137
1138 //设置变量值;不进行类型转换,若出现类型不匹配错误则返回 false
1139 bool set(bool value);
1140 bool set(double value);
1141 bool set(const char_t* value);
1142 bool set(const xpath_node_set& value);
1143 };
1144
1145 // 一组 XPath 变量
1147 {
1148 private:
1149 xpath_variable* _data[64];
1150
1151 void _assign(const xpath_variable_set& rhs);
1152 void _swap(xpath_variable_set& rhs);
1153
1154 xpath_variable* _find(const char_t* name) const;
1155
1156 static bool _clone(xpath_variable* var, xpath_variable** out_result);
1157 static void _destroy(xpath_variable* var);
1158
1159 public:
1160 // 默认构造函数/析构函数
1163
1164 // 复制构造函数/赋值运算符
1167
1168 #ifdef PUGIXML_HAS_MOVE
1169 //移动语义支持
1172 #endif
1173
1174 //添加新变量或获取现有变量(如果类型匹配)
1175 xpath_variable* add(const char_t* name, xpath_value_type type);
1176
1177 //设置现有变量的值;不执行类型转换,如果没有此类变量或类型不匹配,则返回 false
1178 bool set(const char_t* name, bool value);
1179 bool set(const char_t* name, double value);
1180 bool set(const char_t* name, const char_t* value);
1181 bool set(const char_t* name, const xpath_node_set& value);
1182
1183 //按名称获取现有变量
1184 xpath_variable* get(const char_t* name);
1185 const xpath_variable* get(const char_t* name) const;
1186 };
1187
1188 // 已编译的 XPath 查询对象
1190 {
1191 private:
1192 void* _impl;
1194
1195 typedef void (*unspecified_bool_type)(xpath_query***);
1196
1197 //不可复制的语义
1200
1201 public:
1202 //从 XPath 表达式构造一个编译的对象。
1203 // 如果未定义 PUGIXML_NO_EXCEPTIONS,则在编译错误时引发xpath_exception。
1204 explicit xpath_query(const char_t* query, xpath_variable_set* variables = 0);
1205
1206 // 构造 函数
1207 xpath_query();
1208
1209 //破坏者
1210 ~xpath_query();
1211
1212 #ifdef PUGIXML_HAS_MOVE
1213 // 移动语义支持
1216 #endif
1217
1218 //获取查询表达式返回类型
1219 xpath_value_type return_type() const;
1220
1221 // 在指定上下文中将表达式计算为布尔值;如有必要,执行类型转换。
1222 //如果未定义 PUGIXML_NO_EXCEPTIONS,则引发 std::bad_alloc on 内存不足错误。
1223 bool evaluate_boolean(const xpath_node& n) const;
1224
1225 //在指定上下文中将 expression 评估为 double 值;如有必要,执行类型转换。
1226 //如果未定义 PUGIXML_NO_EXCEPTIONS,则引发 std::bad_alloc on 内存不足错误。
1227 double evaluate_number(const xpath_node& n) const;
1228
1229 #ifndef PUGIXML_NO_STL
1230 // 在指定上下文中将表达式评估为字符串值;如有必要,执行类型转换。
1231 // 如果未定义 PUGIXML_NO_EXCEPTIONS,则引发 std::bad_alloc on 内存不足错误。
1232 string_t evaluate_string(const xpath_node& n) const;
1233 #endif
1234
1235 //在指定上下文中将表达式评估为字符串值;如有必要,执行类型转换。
1236 // 大多数容量字符都会写入目标缓冲区,并返回完整的结果大小(包括终止零)。
1237 // 如果未定义 PUGIXML_NO_EXCEPTIONS,则引发 std::bad_alloc on 内存不足错误。
1238 //如果定义了 PUGIXML_NO_EXCEPTIONS,则返回空集。
1239 size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const;
1240
1241 // 将表达式评估为指定上下文中的节点集。
1242 //如果未定义 PUGIXML_NO_EXCEPTIONS,则引发 xpath_exception 类型 mismatch 和 std::bad_alloc 内存不足错误。
1243 // 如果定义了 PUGIXML_NO_EXCEPTIONS,则返回空节点集。
1244 xpath_node_set evaluate_node_set(const xpath_node& n) const;
1245
1246 // 将表达式评估为指定上下文中的节点集。
1247 // 按文档顺序返回第一个节点,如果节点集为空,则返回空节点。
1248 //如果未定义 PUGIXML_NO_EXCEPTIONS,则引发 xpath_exception 类型 mismatch 和 std::bad_alloc 内存不足错误。
1249 //如果定义了 PUGIXML_NO_EXCEPTIONS,则返回空节点。
1250 xpath_node evaluate_node(const xpath_node& n) const;
1251
1252 // 获取解析结果(用于在 PUGIXML_NO_EXCEPTIONS 模式下获取编译错误)
1253 const xpath_parse_result& result() const;
1254
1255 //安全的 bool 转换运算符
1256 operator unspecified_bool_type() const;
1257
1258 //Borland C++ 解决方法
1259 bool operator!() const;
1260 };
1261
1262 #ifndef PUGIXML_NO_EXCEPTIONS
1263 // XPath 异常类
1264 class PUGIXML_CLASS xpath_exception: public std::exception
1265 {
1266 private:
1268
1269 public:
1270 // 根据解析结果构造异常
1271 explicit xpath_exception(const xpath_parse_result& result);
1272
1273 // 获取错误消息
1274 virtual const char* what() const noexcept PUGIXML_OVERRIDE;
1275
1276 // 获取解析结果
1277 const xpath_parse_result& result() const;
1278 };
1279 #endif
1280
1281 // XPath 节点类(要么是 xml_node,要么是 xml_attribute)
1283 {
1284 private:
1287
1288 typedef void (*unspecified_bool_type)(xpath_node***);
1289
1290 public:
1291 // 默认构造函数;用于构造空的 XPath 节点
1292 xpath_node();
1293
1294 //从 XML 节点 / 属性构造 XPath 节点
1295 xpath_node(const xml_node& node);
1296 xpath_node(const xml_attribute& attribute, const xml_node& parent);
1297
1298 // 获取节点 / 属性(如果有的话)
1299 xml_node node() const;
1300 xml_attribute attribute() const;
1301
1302 // 获取所包含节点 / 属性的父节点
1303 xml_node parent() const;
1304
1305 // Safe bool 转换运算符
1306 operator unspecified_bool_type() const;
1307
1308 // Borland C++ 解决方法
1309 bool operator!() const;
1310
1311 // 比较运算符
1312 bool operator==(const xpath_node& n) const;
1313 bool operator!=(const xpath_node& n) const;
1314 };
1315
1316#ifdef __BORLANDC__
1317 // Borland C++ 解决方法
1318 bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);
1319 bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);
1320#endif
1321
1322 // A fixed-size collection of XPath nodes
1324 {
1325 public:
1326 // 一个固定大小的 XPath 节点集合
1328 {
1329 type_unsorted, // 未排序的
1330 type_sorted, // 按照文档顺序(升序)排序
1331 type_sorted_reverse // 按照文档顺序(降序)排序
1333
1334 // Constant iterator type
1336
1337 // 我们将非常量迭代器定义为与常量迭代器相同,以便各种泛型算法(例如 Boost 库中的foreach)能够正常工作
1338 typedef const xpath_node* iterator;
1339
1340 // 默认构造函数。构造空集合。
1342
1343 // 通过迭代器范围构造一个集合;不会检查数据是否存在重复项,并且不会根据所提供的类型对数据进行排序,所以要多加小心
1345
1346 //析构函数
1348
1349 // 拷贝构造函数 / 赋值运算符
1350 xpath_node_set(const xpath_node_set& ns);
1352
1353 #ifdef PUGIXML_HAS_MOVE
1354 // Move semantics support
1357 #endif
1358
1359 // Get collection type
1360 type_t type() const;
1361
1362 // Get collection size
1363 size_t size() const;
1364
1365 // Indexing operator
1366 const xpath_node& operator[](size_t index) const;
1367
1368 // Collection iterators
1369 const_iterator begin() const;
1370 const_iterator end() const;
1371
1372 // Sort the collection in ascending/descending order by document order
1373 void sort(bool reverse = false);
1374
1375 // Get first node in the collection by document order
1376 xpath_node first() const;
1377
1378 // Check if collection is empty
1379 bool empty() const;
1380
1381 private:
1383
1385
1388
1389 void _assign(const_iterator begin, const_iterator end, type_t type);
1391 };
1392#endif
1393
1394#ifndef PUGIXML_NO_STL
1395 // Convert wide string to UTF8
1396 std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);
1397 std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >& str);
1398
1399 // Convert UTF8 to wide string
1400 std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
1401 std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >& str);
1402#endif
1403
1404 // Memory allocation function interface; returns pointer to allocated memory or NULL on failure
1405 typedef void* (*allocation_function)(size_t size);
1406
1407 // Memory deallocation function interface
1408 typedef void (*deallocation_function)(void* ptr);
1409
1410 // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions.
1411 void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);
1412
1413 // Get current memory management functions
1416}
1417
1418#if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
1419namespace std
1420{
1421 // Workarounds for (non-standard) iterator category detection for older versions (MSVC7/IC8 and earlier)
1422 std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_node_iterator&);
1423 std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_attribute_iterator&);
1424 std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_named_node_iterator&);
1425}
1426#endif
1427
1428#if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
1429namespace std
1430{
1431 // Workarounds for (non-standard) iterator category detection
1432 std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_node_iterator&);
1433 std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_attribute_iterator&);
1434 std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_named_node_iterator&);
1435}
1436#endif
1437
1438#endif
1439
1440// Make sure implementation is included in header-only mode
1441// Use macro expansion in #include to work around QMake (QTBUG-11923)
1442#if defined(PUGIXML_HEADER_ONLY) && !defined(PUGIXML_SOURCE)
1443# define PUGIXML_SOURCE "pugixml.cpp"
1444# include PUGIXML_SOURCE
1445#endif
1446
1447/**
1448 * Copyright (c) 2006-2018 Arseny Kapoulkine
1449 *
1450 * Permission is hereby granted, free of charge, to any person
1451 * obtaining a copy of this software and associated documentation
1452 * files (the "Software"), to deal in the Software without
1453 * restriction, including without limitation the rights to use,
1454 * copy, modify, merge, publish, distribute, sublicense, and/or sell
1455 * copies of the Software, and to permit persons to whom the
1456 * Software is furnished to do so, subject to the following
1457 * conditions:
1458 *
1459 * The above copyright notice and this permission notice shall be
1460 * included in all copies or substantial portions of the Software.
1461 *
1462 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1463 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
1464 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1465 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
1466 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
1467 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1468 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1469 * OTHER DEALINGS IN THE SOFTWARE.
1470 */
auto end() const noexcept
auto begin() const noexcept
名称范围迭代支持
ConcurrentQueue & operator=(ConcurrentQueue const &) MOODYCAMEL_DELETE_FUNCTION
static bool operator<=(EVehicleInputPriority Lhs, EVehicleInputPriority Rhs)
std::bidirectional_iterator_tag iterator_category
Definition pugixml.hpp:861
xml_attribute & reference
Definition pugixml.hpp:858
xml_attribute_struct * _attr
Definition pugixml.hpp:353
xml_attribute next_attribute() const
Definition pugixml.cpp:5348
xml_document(const xml_document &)
xml_document & operator=(const xml_document &)
void _move(xml_document &rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT
std::bidirectional_iterator_tag iterator_category
Definition pugixml.hpp:897
std::bidirectional_iterator_tag iterator_category
Definition pugixml.hpp:819
xml_node first_child() const
Definition pugixml.cpp:5817
xml_node next_sibling() const
Definition pugixml.cpp:5716
xml_attribute find_attribute(Predicate pred) const
Definition pugixml.hpp:592
xml_node_struct * _root
Definition pugixml.hpp:463
xml_node parent() const
Definition pugixml.cpp:5772
xml_node find_node(Predicate pred) const
Definition pugixml.hpp:616
xml_attribute_iterator attribute_iterator
Definition pugixml.hpp:685
xml_node find_child(Predicate pred) const
Definition pugixml.hpp:604
xml_node_iterator iterator
Definition pugixml.hpp:679
xml_object_range(It b, It e)
Definition pugixml.hpp:293
xml_node_struct * _root
Definition pugixml.hpp:716
virtual bool for_each(xml_node &node)=0
std::basic_ostream< wchar_t, std::char_traits< wchar_t > > * wide_stream
Definition pugixml.hpp:342
std::basic_ostream< char, std::char_traits< char > > * narrow_stream
Definition pugixml.hpp:341
virtual ~xml_writer()
Definition pugixml.hpp:310
virtual void write(const void *data, size_t size)=0
xpath_parse_result _result
Definition pugixml.hpp:1267
const xpath_node * const_iterator
Definition pugixml.hpp:1335
const xpath_node * iterator
Definition pugixml.hpp:1338
xpath_node * _begin
Definition pugixml.hpp:1386
xpath_node * _end
Definition pugixml.hpp:1387
void _move(xpath_node_set &rhs) PUGIXML_NOEXCEPT
xml_attribute _attribute
Definition pugixml.hpp:1286
xpath_parse_result _result
Definition pugixml.hpp:1193
xpath_query & operator=(const xpath_query &)
xpath_query(const xpath_query &)
xpath_variable * _next
Definition pugixml.hpp:1117
xpath_variable(const xpath_variable &)
xpath_variable & operator=(const xpath_variable &)
xpath_value_type _type
Definition pugixml.hpp:1116
pugi XMLռ
const unsigned int format_no_empty_element_tags
Definition pugixml.hpp:255
xml_encoding
Definition pugixml.hpp:218
@ encoding_utf32
Definition pugixml.hpp:226
@ encoding_utf16_le
Definition pugixml.hpp:221
@ encoding_utf32_be
Definition pugixml.hpp:225
@ encoding_utf16_be
Definition pugixml.hpp:222
@ encoding_utf8
Definition pugixml.hpp:220
@ encoding_latin1
Definition pugixml.hpp:228
@ encoding_utf16
Definition pugixml.hpp:223
@ encoding_utf32_le
Definition pugixml.hpp:224
@ encoding_auto
Definition pugixml.hpp:219
@ encoding_wchar
Definition pugixml.hpp:227
std::basic_string< PUGIXML_CHAR, std::char_traits< PUGIXML_CHAR >, std::allocator< PUGIXML_CHAR > > string_t
Definition pugixml.hpp:132
PUGI__FN deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function()
Definition pugixml.cpp:7452
PUGI__FN allocation_function PUGIXML_FUNCTION get_memory_allocation_function()
Definition pugixml.cpp:7447
const unsigned int format_no_declaration
Definition pugixml.hpp:243
xml_node_type
Definition pugixml.hpp:141
@ node_comment
Definition pugixml.hpp:147
@ node_pcdata
Definition pugixml.hpp:145
@ node_element
Definition pugixml.hpp:144
@ node_doctype
Definition pugixml.hpp:150
@ node_document
Definition pugixml.hpp:143
@ node_declaration
Definition pugixml.hpp:149
@ node_pi
Definition pugixml.hpp:148
@ node_null
Definition pugixml.hpp:142
@ node_cdata
Definition pugixml.hpp:146
const unsigned int parse_trim_pcdata
Definition pugixml.hpp:195
const unsigned int parse_wconv_attribute
Definition pugixml.hpp:178
const unsigned int format_raw
Definition pugixml.hpp:240
const unsigned int format_default
Definition pugixml.hpp:259
void(* deallocation_function)(void *ptr)
Definition pugixml.hpp:1408
const unsigned int parse_cdata
Definition pugixml.hpp:166
void *(* allocation_function)(size_t size)
Definition pugixml.hpp:1405
PUGI__FN std::string PUGIXML_FUNCTION as_utf8(const wchar_t *str)
Definition pugixml.cpp:7416
const unsigned int parse_fragment
Definition pugixml.hpp:199
const unsigned int parse_full
Definition pugixml.hpp:214
const unsigned int parse_embed_pcdata
Definition pugixml.hpp:204
const unsigned int parse_wnorm_attribute
Definition pugixml.hpp:181
const unsigned int format_indent_attributes
Definition pugixml.hpp:252
const unsigned int parse_pi
Definition pugixml.hpp:160
xml_parse_status
Definition pugixml.hpp:955
@ status_append_invalid_root
Definition pugixml.hpp:974
@ status_end_element_mismatch
Definition pugixml.hpp:973
@ status_bad_end_element
Definition pugixml.hpp:972
@ status_io_error
Definition pugixml.hpp:959
@ status_bad_attribute
Definition pugixml.hpp:971
@ status_file_not_found
Definition pugixml.hpp:958
@ status_internal_error
Definition pugixml.hpp:961
@ status_bad_start_element
Definition pugixml.hpp:970
@ status_ok
Definition pugixml.hpp:956
@ status_bad_comment
Definition pugixml.hpp:965
@ status_bad_doctype
Definition pugixml.hpp:968
@ status_out_of_memory
Definition pugixml.hpp:960
@ status_unrecognized_tag
Definition pugixml.hpp:962
@ status_bad_cdata
Definition pugixml.hpp:967
@ status_bad_pi
Definition pugixml.hpp:964
@ status_bad_pcdata
Definition pugixml.hpp:969
@ status_no_document_element
Definition pugixml.hpp:976
const unsigned int format_save_file_text
Definition pugixml.hpp:249
const unsigned int parse_escapes
Definition pugixml.hpp:172
const unsigned int format_write_bom
Definition pugixml.hpp:237
PUGI__FN void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate)
Definition pugixml.cpp:7441
const unsigned int format_indent
Definition pugixml.hpp:234
const unsigned int parse_eol
Definition pugixml.hpp:175
const unsigned int parse_default
Definition pugixml.hpp:209
const unsigned int parse_declaration
Definition pugixml.hpp:184
const unsigned int parse_comments
Definition pugixml.hpp:163
PUGI__FN std::basic_string< wchar_t > PUGIXML_FUNCTION as_wide(const char *str)
Definition pugixml.cpp:7428
xpath_value_type
Definition pugixml.hpp:1083
@ xpath_type_number
Definition pugixml.hpp:1086
@ xpath_type_boolean
Definition pugixml.hpp:1088
@ xpath_type_none
Definition pugixml.hpp:1084
@ xpath_type_string
Definition pugixml.hpp:1087
@ xpath_type_node_set
Definition pugixml.hpp:1085
const unsigned int parse_ws_pcdata
Definition pugixml.hpp:170
const unsigned int parse_minimal
Definition pugixml.hpp:157
const unsigned int parse_ws_pcdata_single
Definition pugixml.hpp:192
const unsigned int format_no_escapes
Definition pugixml.hpp:246
PUGIXML_CHAR char_t
Definition pugixml.hpp:128
const unsigned int parse_doctype
Definition pugixml.hpp:187
void sort(I begin, I end, const Pred &pred)
Definition pugixml.cpp:7639
void remove_attribute(xml_attribute_struct *attr, xml_node_struct *node)
Definition pugixml.cpp:1577
void reverse(I begin, I end)
Definition pugixml.cpp:7553
void insert_attribute_before(xml_attribute_struct *attr, xml_attribute_struct *place, xml_node_struct *node)
Definition pugixml.cpp:1565
void append_attribute(xml_attribute_struct *attr, xml_node_struct *node)
Definition pugixml.cpp:1518
void prepend_attribute(xml_attribute_struct *attr, xml_node_struct *node)
Definition pugixml.cpp:1537
void insert_attribute_after(xml_attribute_struct *attr, xml_attribute_struct *place, xml_node_struct *node)
Definition pugixml.cpp:1553
#define PUGIXML_DEPRECATED
Definition pugixml.hpp:47
#define PUGIXML_NOEXCEPT_IF_NOT_COMPACT
Definition pugixml.hpp:102
#define PUGIXML_FUNCTION
Definition pugixml.hpp:63
#define PUGIXML_NOEXCEPT
Definition pugixml.hpp:85
#define PUGIXML_OVERRIDE
Definition pugixml.hpp:112
#define PUGIXML_CLASS
Definition pugixml.hpp:58
#define PUGIXML_TEXT(t)
Definition pugixml.hpp:121
#define PUGIXML_CHAR
Definition pugixml.hpp:122
xml_encoding encoding
Definition pugixml.hpp:989
xml_parse_status status
Definition pugixml.hpp:983