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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
|
#ifndef HEADER_PUGIXML_HPP
#define HEADER_PUGIXML_HPP
#ifndef PUGIXML_NO_STL
# include <string>
# include <istream>
#endif
#include <cstddef>
#include <cstring>
namespace pugi
{
enum xml_node_type
{
node_null,
node_document,
node_element,
node_pcdata,
node_cdata,
node_comment,
node_pi
};
const size_t memory_block_size = 32768;
const unsigned int parse_minimal = 0x00000000;
const unsigned int parse_pi = 0x00000001;
const unsigned int parse_comments = 0x00000002;
const unsigned int parse_cdata = 0x00000004;
const unsigned int parse_ws_pcdata = 0x00000008;
const unsigned int parse_ext_pcdata = 0x00000010;
const unsigned int parse_trim_pcdata = 0x00000020;
const unsigned int parse_trim_attribute = 0x00000040;
const unsigned int parse_escapes_pcdata = 0x00000080;
const unsigned int parse_escapes_attribute = 0x00000100;
const unsigned int parse_wnorm_pcdata = 0x00000200;
const unsigned int parse_wnorm_attribute = 0x00000400;
const unsigned int parse_wconv_attribute = 0x00000800;
const unsigned int parse_eol_pcdata = 0x00001000;
const unsigned int parse_eol_attribute = 0x00002000;
const unsigned int parse_eol_cdata = 0x00004000;
const unsigned int parse_check_end_tags = 0x00010000;
const unsigned int parse_match_end_tags = 0x00020000;
const unsigned int parse_default = 0x00FFFFFF & ~parse_ws_pcdata & ~parse_trim_attribute & ~parse_pi & ~parse_comments;
const unsigned int parse_noset = 0x80000000;
const unsigned int parse_w3c = parse_pi | parse_comments | parse_cdata |
parse_escapes_pcdata | parse_escapes_attribute |
parse_wconv_attribute | parse_check_end_tags |
parse_ws_pcdata | parse_eol_cdata;
struct xml_attribute_struct;
struct xml_node_struct;
class xml_node_iterator;
class xml_attribute_iterator;
class xml_tree_walker;
class xml_attribute
{
friend class xml_attribute_iterator;
friend class xml_node;
private:
const xml_attribute_struct* _attr;
typedef const xml_attribute_struct* xml_attribute::*unspecified_bool_type;
explicit xml_attribute(const xml_attribute_struct* attr);
public:
xml_attribute();
public:
bool operator==(const xml_attribute& r) const;
bool operator!=(const xml_attribute& r) const;
bool operator<(const xml_attribute& r) const;
bool operator>(const xml_attribute& r) const;
bool operator<=(const xml_attribute& r) const;
bool operator>=(const xml_attribute& r) const;
operator unspecified_bool_type() const;
xml_attribute next_attribute() const;
xml_attribute previous_attribute() const;
int as_int() const;
double as_double() const;
float as_float() const;
bool as_bool() const;
public:
bool empty() const;
public:
const char* name() const;
const char* value() const;
};
class xml_node
{
friend class xml_node_iterator;
friend class xml_parser;
private:
const xml_node_struct* _root;
typedef const xml_node_struct* xml_node::*unspecified_bool_type;
private:
bool type_document() const;
public:
xml_node();
explicit xml_node(const xml_node_struct* p);
public:
typedef xml_node_iterator iterator;
typedef xml_attribute_iterator attribute_iterator;
iterator begin() const;
iterator end() const;
iterator children_begin() const;
iterator children_end() const;
attribute_iterator attributes_begin() const;
attribute_iterator attributes_end() const;
iterator siblings_begin() const;
iterator siblings_end() const;
public:
operator unspecified_bool_type() const;
bool operator==(const xml_node& r) const;
bool operator!=(const xml_node& r) const;
bool operator<(const xml_node& r) const;
bool operator>(const xml_node& r) const;
bool operator<=(const xml_node& r) const;
bool operator>=(const xml_node& r) const;
public:
bool empty() const;
public:
xml_node_type type() const;
const char* name() const;
const char* value() const;
xml_node child(const char* name) const;
xml_node child_w(const char* name) const;
xml_attribute attribute(const char* name) const;
xml_attribute attribute_w(const char* name) const;
xml_node sibling(const char* name) const;
xml_node sibling_w(const char* name) const;
xml_node next_sibling(const char* name) const;
xml_node next_sibling_w(const char* name) const;
xml_node next_sibling() const;
xml_node previous_sibling(const char* name) const;
xml_node previous_sibling_w(const char* name) const;
xml_node previous_sibling() const;
xml_node parent() const;
const char* child_value() const;
const char* child_value(const char* name) const;
const char* child_value_w(const char* name) const;
public:
xml_attribute first_attribute() const;
xml_attribute last_attribute() const;
template <typename OutputIterator> void all_elements_by_name(const char* name, OutputIterator it) const;
template <typename OutputIterator> void all_elements_by_name_w(const char* name, OutputIterator it) const;
xml_node first_child() const;
xml_node last_child() const;
template <typename Predicate> xml_attribute find_attribute(Predicate pred) const;
template <typename Predicate> xml_node find_child(Predicate pred) const;
template <typename Predicate> xml_node find_element(Predicate pred) const;
xml_node first_element(const char* name) const;
xml_node first_element_w(const char* name) const;
xml_node first_element_by_value(const char* name, const char* value) const;
xml_node first_element_by_value_w(const char* name, const char* value) const;
xml_node first_element_by_attribute(const char* name, const char* attr_name, const char* attr_value) const;
xml_node first_element_by_attribute_w(const char* name, const char* attr_name, const char* attr_value) const;
xml_node first_element_by_attribute(const char* attr_name, const char* attr_value) const;
xml_node first_element_by_attribute_w(const char* attr_name, const char* attr_value) const;
xml_node first_node(xml_node_type type) const;
#ifndef PUGIXML_NO_STL
std::string path(char delimiter = '/') const;
#endif
xml_node first_element_by_path(const char* path, char delimiter = '/') const;
bool traverse(xml_tree_walker& walker) const;
};
class xml_node_iterator
#ifndef PUGIXML_NO_STL
: public std::iterator<std::bidirectional_iterator_tag, const xml_node>
#endif
{
friend class xml_node;
private:
xml_node _prev;
xml_node _wrap;
explicit xml_node_iterator(const xml_node_struct* ref);
public:
xml_node_iterator();
xml_node_iterator(const xml_node& node);
xml_node_iterator(const xml_node_struct* ref, const xml_node_struct* prev);
bool operator==(const xml_node_iterator& rhs) const;
bool operator!=(const xml_node_iterator& rhs) const;
const xml_node& operator*() const;
const xml_node* operator->() const;
const xml_node_iterator& operator++();
xml_node_iterator operator++(int);
const xml_node_iterator& operator--();
xml_node_iterator operator--(int);
};
class xml_attribute_iterator
#ifndef PUGIXML_NO_STL
: public std::iterator<std::bidirectional_iterator_tag, const xml_attribute>
#endif
{
friend class xml_node;
private:
xml_attribute _prev;
xml_attribute _wrap;
explicit xml_attribute_iterator(const xml_attribute_struct* ref);
public:
xml_attribute_iterator();
xml_attribute_iterator(const xml_attribute& attr);
xml_attribute_iterator(const xml_attribute_struct* ref, const xml_attribute_struct* prev);
bool operator==(const xml_attribute_iterator& rhs) const;
bool operator!=(const xml_attribute_iterator& rhs) const;
const xml_attribute& operator*() const;
const xml_attribute* operator->() const;
const xml_attribute_iterator& operator++();
xml_attribute_iterator operator++(int);
const xml_attribute_iterator& operator--();
xml_attribute_iterator operator--(int);
};
class xml_tree_walker
{
private:
int _deep;
public:
xml_tree_walker();
virtual ~xml_tree_walker();
public:
virtual void push();
virtual void pop();
virtual int depth() const;
public:
virtual bool begin(const xml_node&);
virtual bool end(const xml_node&);
};
struct xml_memory_block
{
xml_memory_block();
xml_memory_block* next;
size_t size;
char data[memory_block_size];
};
struct transfer_ownership_tag {};
class xml_parser
{
private:
char* _buffer;
xml_memory_block _memory;
xml_node_struct* _xmldoc;
unsigned int _optmsk;
xml_parser(const xml_parser&);
const xml_parser& operator=(const xml_parser&);
void free();
public:
xml_parser(unsigned int optmsk = parse_default);
xml_parser(char* xmlstr, unsigned int optmsk = parse_default);
xml_parser(const transfer_ownership_tag&, char* xmlstr, unsigned int optmsk = parse_default);
#ifndef PUGIXML_NO_STL
xml_parser(std::istream& stream, unsigned int optmsk = parse_default);
#endif
~xml_parser();
public:
operator xml_node() const;
xml_node document() const;
public:
unsigned int options() const;
unsigned int options(unsigned int optmsk);
public:
#ifndef PUGIXML_NO_STL
void parse(std::istream& stream, unsigned int optmsk = parse_noset);
#endif
char* parse(char* xmlstr, unsigned int optmsk = parse_noset);
char* parse(const transfer_ownership_tag&, char* xmlstr, unsigned int optmsk = parse_noset);
};
#ifndef PUGIXML_NO_STL
std::string utf8(const wchar_t* str);
std::wstring utf16(const char* str);
#endif
}
namespace pugi
{
namespace impl
{
int strcmpwild(const char*, const char*);
}
template <typename OutputIterator> void xml_node::all_elements_by_name(const char* name, OutputIterator it) const
{
if (empty()) return;
for (xml_node node = first_child(); node; node = node.next_sibling())
{
if (!strcmp(name, node.name()))
{
*it = node;
++it;
}
if (node.first_child()) node.all_elements_by_name(name, it);
}
}
template <typename OutputIterator> void xml_node::all_elements_by_name_w(const char* name, OutputIterator it) const
{
if (empty()) return;
for (xml_node node = first_child(); node; node = node.next_sibling())
{
if (!impl::strcmpwild(name, node.name()))
{
*it = node;
++it;
}
if (node.first_child()) node.all_elements_by_name_w(name, it);
}
}
template <typename Predicate> inline xml_attribute xml_node::find_attribute(Predicate pred) const
{
if (!empty())
for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
if (pred(attrib))
return attrib;
return xml_attribute();
}
template <typename Predicate> inline xml_node xml_node::find_child(Predicate pred) const
{
if (!empty())
for (xml_node node = first_child(); node; node = node.next_sibling())
if (pred(node))
return node;
return xml_node();
}
template <typename Predicate> inline xml_node xml_node::find_element(Predicate pred) const
{
if (!empty())
for (xml_node node = first_child(); node; node = node.next_sibling())
{
if (pred(node))
return node;
if (node.first_child())
{
xml_node found = node.find_element(pred);
if (found) return found;
}
}
return xml_node();
}
}
#endif
|