Image Component Library (ICL)
PugiXML.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLUtils/src/ICLUtils/PugiXML.h **
10 ** Module : ICLUtils **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
32 //#include "pugiconfig.hpp" we use everything here
33 
47 #pragma once
48 
49 #ifdef WIN32
50  #ifdef ICLUtils_EXPORTS
51  #define PUGIXML_API __declspec(dllexport)
52  #else
53  #define PUGIXML_CLASS __declspec(dllimport)
54  #endif
55 #endif
56 
57 #ifndef PUGIXML_VERSION
58 // Define version macro; evaluates to major * 100 + minor so that it's safe to use in less-than comparisons
59 # define PUGIXML_VERSION 160
60 #endif
61 
62 // Include stddef.h for size_t and ptrdiff_t
63 #include <stddef.h>
64 
65 // Include exception header for XPath
66 #if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
67 # include <exception>
68 #endif
69 
70 // Include STL headers
71 #ifndef PUGIXML_NO_STL
72 # include <iterator>
73 # include <iosfwd>
74 # include <string>
75 #endif
76 
77 // Macro for deprecated features
78 #ifndef PUGIXML_DEPRECATED
79 # if defined(__GNUC__)
80 # define PUGIXML_DEPRECATED __attribute__((deprecated))
81 # elif defined(_MSC_VER) && _MSC_VER >= 1300
82 # define PUGIXML_DEPRECATED __declspec(deprecated)
83 # else
84 # define PUGIXML_DEPRECATED
85 # endif
86 #endif
87 
88 // If no API is defined, assume default
89 #ifndef PUGIXML_API
90 # define PUGIXML_API
91 #endif
92 
93 // If no API for classes is defined, assume default
94 #ifndef PUGIXML_CLASS
95 # define PUGIXML_CLASS PUGIXML_API
96 #endif
97 
98 // If no API for functions is defined, assume default
99 #ifndef PUGIXML_FUNCTION
100 # define PUGIXML_FUNCTION PUGIXML_API
101 #endif
102 
103 // If the platform is known to have long long support, enable long long functions
104 #ifndef PUGIXML_HAS_LONG_LONG
105 # if __cplusplus >= 201103
106 # define PUGIXML_HAS_LONG_LONG
107 # elif defined(_MSC_VER) && _MSC_VER >= 1400
108 # define PUGIXML_HAS_LONG_LONG
109 # endif
110 #endif
111 
112 // Character interface macros
113 #ifdef PUGIXML_WCHAR_MODE
114 # define PUGIXML_TEXT(t) L ## t
115 # define PUGIXML_CHAR wchar_t
116 #else
117 # define PUGIXML_TEXT(t) t
118 # define PUGIXML_CHAR char
119 #endif
120 
121 namespace pugi
122 {
123  // Character type used for all internal storage and operations; depends on PUGIXML_WCHAR_MODE
124  typedef PUGIXML_CHAR char_t;
125 
126 #ifndef PUGIXML_NO_STL
127  // String type used for operations that work with STL string; depends on PUGIXML_WCHAR_MODE
128  typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
129 #endif
130 }
131 
132 // The PugiXML namespace
133 namespace pugi
134 {
135  // Tree node types
136  enum xml_node_type
137  {
138  node_null, // Empty (null) node handle
139  node_document, // A document tree's absolute root
140  node_element, // Element tag, i.e. '<node/>'
141  node_pcdata, // Plain character data, i.e. 'text'
142  node_cdata, // Character data, i.e. '<![CDATA[text]]>'
143  node_comment, // Comment tag, i.e. '<!-- text -->'
144  node_pi, // Processing instruction, i.e. '<?name?>'
145  node_declaration, // Document declaration, i.e. '<?xml version="1.0"?>'
146  node_doctype // Document type declaration, i.e. '<!DOCTYPE doc>'
147  };
148 
149  // Parsing options
150 
151  // Minimal parsing mode (equivalent to turning all other flags off).
152  // Only elements and PCDATA sections are added to the DOM tree, no text conversions are performed.
153  const unsigned int parse_minimal = 0x0000;
154 
155  // This flag determines if processing instructions (node_pi) are added to the DOM tree. This flag is off by default.
156  const unsigned int parse_pi = 0x0001;
157 
158  // This flag determines if comments (node_comment) are added to the DOM tree. This flag is off by default.
159  const unsigned int parse_comments = 0x0002;
160 
161  // This flag determines if CDATA sections (node_cdata) are added to the DOM tree. This flag is on by default.
162  const unsigned int parse_cdata = 0x0004;
163 
164  // This flag determines if plain character data (node_pcdata) that consist only of whitespace are added to the DOM tree.
165  // This flag is off by default; turning it on usually results in slower parsing and more memory consumption.
166  const unsigned int parse_ws_pcdata = 0x0008;
167 
168  // This flag determines if character and entity references are expanded during parsing. This flag is on by default.
169  const unsigned int parse_escapes = 0x0010;
170 
171  // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default.
172  const unsigned int parse_eol = 0x0020;
173 
174  // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. This flag is on by default.
175  const unsigned int parse_wconv_attribute = 0x0040;
176 
177  // This flag determines if attribute values are normalized using NMTOKENS normalization rules during parsing. This flag is off by default.
178  const unsigned int parse_wnorm_attribute = 0x0080;
179 
180  // This flag determines if document declaration (node_declaration) is added to the DOM tree. This flag is off by default.
181  const unsigned int parse_declaration = 0x0100;
182 
183  // This flag determines if document type declaration (node_doctype) is added to the DOM tree. This flag is off by default.
184  const unsigned int parse_doctype = 0x0200;
185 
186  // This flag determines if plain character data (node_pcdata) that is the only child of the parent node and that consists only
187  // of whitespace is added to the DOM tree.
188  // This flag is off by default; turning it on may result in slower parsing and more memory consumption.
189  const unsigned int parse_ws_pcdata_single = 0x0400;
190 
191  // This flag determines if leading and trailing whitespace is to be removed from plain character data. This flag is off by default.
192  const unsigned int parse_trim_pcdata = 0x0800;
193 
194  // This flag determines if plain character data that does not have a parent node is added to the DOM tree, and if an empty document
195  // is a valid document. This flag is off by default.
196  const unsigned int parse_fragment = 0x1000;
197 
198  // The default parsing mode.
199  // Elements, PCDATA and CDATA sections are added to the DOM tree, character/reference entities are expanded,
200  // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.
201  const unsigned int parse_default = parse_cdata | parse_escapes | parse_wconv_attribute | parse_eol;
202 
203  // The full parsing mode.
204  // Nodes of all types are added to the DOM tree, character/reference entities are expanded,
205  // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.
206  const unsigned int parse_full = parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype;
207 
208  // These flags determine the encoding of input data for XML document
209  enum xml_encoding
210  {
211  encoding_auto, // Auto-detect input encoding using BOM or < / <? detection; use UTF8 if BOM is not found
212  encoding_utf8, // UTF8 encoding
213  encoding_utf16_le, // Little-endian UTF16
214  encoding_utf16_be, // Big-endian UTF16
215  encoding_utf16, // UTF16 with native endianness
216  encoding_utf32_le, // Little-endian UTF32
217  encoding_utf32_be, // Big-endian UTF32
218  encoding_utf32, // UTF32 with native endianness
219  encoding_wchar, // The same encoding wchar_t has (either UTF16 or UTF32)
220  encoding_latin1
221  };
222 
223  // Formatting flags
224 
225  // Indent the nodes that are written to output stream with as many indentation strings as deep the node is in DOM tree. This flag is on by default.
226  const unsigned int format_indent = 0x01;
227 
228  // Write encoding-specific BOM to the output stream. This flag is off by default.
229  const unsigned int format_write_bom = 0x02;
230 
231  // Use raw output mode (no indentation and no line breaks are written). This flag is off by default.
232  const unsigned int format_raw = 0x04;
233 
234  // Omit default XML declaration even if there is no declaration in the document. This flag is off by default.
235  const unsigned int format_no_declaration = 0x08;
236 
237  // Don't escape attribute values and PCDATA contents. This flag is off by default.
238  const unsigned int format_no_escapes = 0x10;
239 
240  // Open file using text mode in xml_document::save_file. This enables special character (i.e. new-line) conversions on some systems. This flag is off by default.
241  const unsigned int format_save_file_text = 0x20;
242 
243  // Write every attribute on a new line with appropriate indentation. This flag is off by default.
244  const unsigned int format_indent_attributes = 0x40;
245 
246  // The default set of formatting flags.
247  // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none.
248  const unsigned int format_default = format_indent;
249 
250  // Forward declarations
251  struct xml_attribute_struct;
252  struct xml_node_struct;
253 
254  class xml_node_iterator;
255  class xml_attribute_iterator;
256  class xml_named_node_iterator;
257 
258  class xml_tree_walker;
259 
260  struct xml_parse_result;
261 
262  class xml_node;
263 
264  class xml_text;
265 
266  #ifndef PUGIXML_NO_XPATH
267  class xpath_node;
268  class xpath_node_set;
269  class xpath_query;
270  class xpath_variable_set;
271  #endif
272 
273  // Range-based for loop support
274  template <typename It> class xml_object_range
275  {
276  public:
277  typedef It const_iterator;
278  typedef It iterator;
279 
280  xml_object_range(It b, It e): _begin(b), _end(e)
281  {
282  }
283 
284  It begin() const { return _begin; }
285  It end() const { return _end; }
286 
287  private:
288  It _begin, _end;
289  };
290 
291  // Writer interface for node printing (see xml_node::print)
292  class PUGIXML_CLASS xml_writer
293  {
294  public:
295  virtual ~xml_writer() {}
296 
297  // Write memory chunk into stream/file/whatever
298  virtual void write(const void* data, size_t size) = 0;
299  };
300 
301  // xml_writer implementation for FILE*
302  class PUGIXML_CLASS xml_writer_file: public xml_writer
303  {
304  public:
305  // Construct writer from a FILE* object; void* is used to avoid header dependencies on stdio
306  xml_writer_file(void* file);
307 
308  virtual void write(const void* data, size_t size);
309 
310  private:
311  void* file;
312  };
313 
314  #ifndef PUGIXML_NO_STL
315  // xml_writer implementation for streams
316  class PUGIXML_CLASS xml_writer_stream: public xml_writer
317  {
318  public:
319  // Construct writer from an output stream object
320  xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
321  xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
322 
323  virtual void write(const void* data, size_t size);
324 
325  private:
326  std::basic_ostream<char, std::char_traits<char> >* narrow_stream;
327  std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream;
328  };
329  #endif
330 
331  // A light-weight handle for manipulating attributes in DOM tree
332  class PUGIXML_CLASS xml_attribute
333  {
334  friend class xml_attribute_iterator;
335  friend class xml_node;
336 
337  private:
338  xml_attribute_struct* _attr;
339 
340  typedef void (*unspecified_bool_type)(xml_attribute***);
341 
342  public:
343  // Default constructor. Constructs an empty attribute.
344  xml_attribute();
345 
346  // Constructs attribute from internal pointer
347  explicit xml_attribute(xml_attribute_struct* attr);
348 
349  // Safe bool conversion operator
350  operator unspecified_bool_type() const;
351 
352  // Borland C++ workaround
353  bool operator!() const;
354 
355  // Comparison operators (compares wrapped attribute pointers)
356  bool operator==(const xml_attribute& r) const;
357  bool operator!=(const xml_attribute& r) const;
358  bool operator<(const xml_attribute& r) const;
359  bool operator>(const xml_attribute& r) const;
360  bool operator<=(const xml_attribute& r) const;
361  bool operator>=(const xml_attribute& r) const;
362 
363  // Check if attribute is empty
364  bool empty() const;
365 
366  // Get attribute name/value, or "" if attribute is empty
367  const char_t* name() const;
368  const char_t* value() const;
369 
370  // Get attribute value, or the default value if attribute is empty
371  const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
372 
373  // Get attribute value as a number, or the default value if conversion did not succeed or attribute is empty
374  int as_int(int def = 0) const;
375  unsigned int as_uint(unsigned int def = 0) const;
376  double as_double(double def = 0) const;
377  float as_float(float def = 0) const;
378 
379  #ifdef PUGIXML_HAS_LONG_LONG
380  long long as_llong(long long def = 0) const;
381  unsigned long long as_ullong(unsigned long long def = 0) const;
382  #endif
383 
384  // Get attribute value as bool (returns true if first character is in '1tTyY' set), or the default value if attribute is empty
385  bool as_bool(bool def = false) const;
386 
387  // Set attribute name/value (returns false if attribute is empty or there is not enough memory)
388  bool set_name(const char_t* rhs);
389  bool set_value(const char_t* rhs);
390 
391  // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
392  bool set_value(int rhs);
393  bool set_value(unsigned int rhs);
394  bool set_value(double rhs);
395  bool set_value(float rhs);
396  bool set_value(bool rhs);
397 
398  #ifdef PUGIXML_HAS_LONG_LONG
399  bool set_value(long long rhs);
400  bool set_value(unsigned long long rhs);
401  #endif
402 
403  // Set attribute value (equivalent to set_value without error checking)
404  xml_attribute& operator=(const char_t* rhs);
405  xml_attribute& operator=(int rhs);
406  xml_attribute& operator=(unsigned int rhs);
407  xml_attribute& operator=(double rhs);
408  xml_attribute& operator=(float rhs);
409  xml_attribute& operator=(bool rhs);
410 
411  #ifdef PUGIXML_HAS_LONG_LONG
412  xml_attribute& operator=(long long rhs);
413  xml_attribute& operator=(unsigned long long rhs);
414  #endif
415 
416  // Get next/previous attribute in the attribute list of the parent node
417  xml_attribute next_attribute() const;
418  xml_attribute previous_attribute() const;
419 
420  // Get hash value (unique for handles to the same object)
421  size_t hash_value() const;
422 
423  // Get internal pointer
424  xml_attribute_struct* internal_object() const;
425  };
426 
427 #ifdef __BORLANDC__
428  // Borland C++ workaround
429  bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs);
430  bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs);
431 #endif
432 
433  // A light-weight handle for manipulating nodes in DOM tree
434  class PUGIXML_CLASS xml_node
435  {
436  friend class xml_attribute_iterator;
437  friend class xml_node_iterator;
438  friend class xml_named_node_iterator;
439 
440  protected:
441  xml_node_struct* _root;
442 
443  typedef void (*unspecified_bool_type)(xml_node***);
444 
445  public:
446  // Default constructor. Constructs an empty node.
447  xml_node();
448 
449  // Constructs node from internal pointer
450  explicit xml_node(xml_node_struct* p);
451 
452  // Safe bool conversion operator
453  operator unspecified_bool_type() const;
454 
455  // Borland C++ workaround
456  bool operator!() const;
457 
458  // Comparison operators (compares wrapped node pointers)
459  bool operator==(const xml_node& r) const;
460  bool operator!=(const xml_node& r) const;
461  bool operator<(const xml_node& r) const;
462  bool operator>(const xml_node& r) const;
463  bool operator<=(const xml_node& r) const;
464  bool operator>=(const xml_node& r) const;
465 
466  // Check if node is empty.
467  bool empty() const;
468 
469  // Get node type
470  xml_node_type type() const;
471 
472  // Get node name, or "" if node is empty or it has no name
473  const char_t* name() const;
474 
475  // Get node value, or "" if node is empty or it has no value
476  // Note: For <node>text</node> node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes.
477  const char_t* value() const;
478 
479  // Get attribute list
480  xml_attribute first_attribute() const;
481  xml_attribute last_attribute() const;
482 
483  // Get children list
484  xml_node first_child() const;
485  xml_node last_child() const;
486 
487  // Get next/previous sibling in the children list of the parent node
488  xml_node next_sibling() const;
489  xml_node previous_sibling() const;
490 
491  // Get parent node
492  xml_node parent() const;
493 
494  // Get root of DOM tree this node belongs to
495  xml_node root() const;
496 
497  // Get text object for the current node
498  xml_text text() const;
499 
500  // Get child, attribute or next/previous sibling with the specified name
501  xml_node child(const char_t* name) const;
502  xml_attribute attribute(const char_t* name) const;
503  xml_node next_sibling(const char_t* name) const;
504  xml_node previous_sibling(const char_t* name) const;
505 
506  // Get attribute, starting the search from a hint (and updating hint so that searching for a sequence of attributes is fast)
507  xml_attribute attribute(const char_t* name, xml_attribute& hint) const;
508 
509  // Get child value of current node; that is, value of the first child node of type PCDATA/CDATA
510  const char_t* child_value() const;
511 
512  // Get child value of child with specified name. Equivalent to child(name).child_value().
513  const char_t* child_value(const char_t* name) const;
514 
515  // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value)
516  bool set_name(const char_t* rhs);
517  bool set_value(const char_t* rhs);
518 
519  // Add attribute with specified name. Returns added attribute, or empty attribute on errors.
520  xml_attribute append_attribute(const char_t* name);
521  xml_attribute prepend_attribute(const char_t* name);
522  xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr);
523  xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr);
524 
525  // Add a copy of the specified attribute. Returns added attribute, or empty attribute on errors.
526  xml_attribute append_copy(const xml_attribute& proto);
527  xml_attribute prepend_copy(const xml_attribute& proto);
528  xml_attribute insert_copy_after(const xml_attribute& proto, const xml_attribute& attr);
529  xml_attribute insert_copy_before(const xml_attribute& proto, const xml_attribute& attr);
530 
531  // Add child node with specified type. Returns added node, or empty node on errors.
532  xml_node append_child(xml_node_type type = node_element);
533  xml_node prepend_child(xml_node_type type = node_element);
534  xml_node insert_child_after(xml_node_type type, const xml_node& node);
535  xml_node insert_child_before(xml_node_type type, const xml_node& node);
536 
537  // Add child element with specified name. Returns added node, or empty node on errors.
538  xml_node append_child(const char_t* name);
539  xml_node prepend_child(const char_t* name);
540  xml_node insert_child_after(const char_t* name, const xml_node& node);
541  xml_node insert_child_before(const char_t* name, const xml_node& node);
542 
543  // Add a copy of the specified node as a child. Returns added node, or empty node on errors.
544  xml_node append_copy(const xml_node& proto);
545  xml_node prepend_copy(const xml_node& proto);
546  xml_node insert_copy_after(const xml_node& proto, const xml_node& node);
547  xml_node insert_copy_before(const xml_node& proto, const xml_node& node);
548 
549  // Move the specified node to become a child of this node. Returns moved node, or empty node on errors.
550  xml_node append_move(const xml_node& moved);
551  xml_node prepend_move(const xml_node& moved);
552  xml_node insert_move_after(const xml_node& moved, const xml_node& node);
553  xml_node insert_move_before(const xml_node& moved, const xml_node& node);
554 
555  // Remove specified attribute
556  bool remove_attribute(const xml_attribute& a);
557  bool remove_attribute(const char_t* name);
558 
559  // Remove specified child
560  bool remove_child(const xml_node& n);
561  bool remove_child(const char_t* name);
562 
563  // Parses buffer as an XML document fragment and appends all nodes as children of the current node.
564  // Copies/converts the buffer, so it may be deleted or changed after the function returns.
565  // Note: append_buffer allocates memory that has the lifetime of the owning document; removing the appended nodes does not immediately reclaim that memory.
566  xml_parse_result append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
567 
568  // Find attribute using predicate. Returns first attribute for which predicate returned true.
569  template <typename Predicate> xml_attribute find_attribute(Predicate pred) const
570  {
571  if (!_root) return xml_attribute();
572 
573  for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
574  if (pred(attrib))
575  return attrib;
576 
577  return xml_attribute();
578  }
579 
580  // Find child node using predicate. Returns first child for which predicate returned true.
581  template <typename Predicate> xml_node find_child(Predicate pred) const
582  {
583  if (!_root) return xml_node();
584 
585  for (xml_node node = first_child(); node; node = node.next_sibling())
586  if (pred(node))
587  return node;
588 
589  return xml_node();
590  }
591 
592  // Find node from subtree using predicate. Returns first node from subtree (depth-first), for which predicate returned true.
593  template <typename Predicate> xml_node find_node(Predicate pred) const
594  {
595  if (!_root) return xml_node();
596 
597  xml_node cur = first_child();
598 
599  while (cur._root && cur._root != _root)
600  {
601  if (pred(cur)) return cur;
602 
603  if (cur.first_child()) cur = cur.first_child();
604  else if (cur.next_sibling()) cur = cur.next_sibling();
605  else
606  {
607  while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
608 
609  if (cur._root != _root) cur = cur.next_sibling();
610  }
611  }
612 
613  return xml_node();
614  }
615 
616  // Find child node by attribute name/value
617  xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
618  xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
619 
620  #ifndef PUGIXML_NO_STL
621  // Get the absolute node path from root as a text string.
622  string_t path(char_t delimiter = '/') const;
623  #endif
624 
625  // Search for a node by path consisting of node names and . or .. elements.
626  xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;
627 
628  // Recursively traverse subtree with xml_tree_walker
629  bool traverse(xml_tree_walker& walker);
630 
631  #ifndef PUGIXML_NO_XPATH
632  // Select single node by evaluating XPath query. Returns first node from the resulting node set.
633  xpath_node select_node(const char_t* query, xpath_variable_set* variables = 0) const;
634  xpath_node select_node(const xpath_query& query) const;
635 
636  // Select node set by evaluating XPath query
637  xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = 0) const;
638  xpath_node_set select_nodes(const xpath_query& query) const;
639 
640  // (deprecated: use select_node instead) Select single node by evaluating XPath query.
641  xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const;
642  xpath_node select_single_node(const xpath_query& query) const;
643 
644  #endif
645 
646  // Print subtree using a writer object
647  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;
648 
649  #ifndef PUGIXML_NO_STL
650  // Print subtree to stream
651  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;
652  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;
653  #endif
654 
655  // Child nodes iterators
656  typedef xml_node_iterator iterator;
657 
658  iterator begin() const;
659  iterator end() const;
660 
661  // Attribute iterators
662  typedef xml_attribute_iterator attribute_iterator;
663 
664  attribute_iterator attributes_begin() const;
665  attribute_iterator attributes_end() const;
666 
667  // Range-based for support
668  xml_object_range<xml_node_iterator> children() const;
669  xml_object_range<xml_named_node_iterator> children(const char_t* name) const;
670  xml_object_range<xml_attribute_iterator> attributes() const;
671 
672  // Get node offset in parsed file/string (in char_t units) for debugging purposes
673  ptrdiff_t offset_debug() const;
674 
675  // Get hash value (unique for handles to the same object)
676  size_t hash_value() const;
677 
678  // Get internal pointer
679  xml_node_struct* internal_object() const;
680  };
681 
682 #ifdef __BORLANDC__
683  // Borland C++ workaround
684  bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);
685  bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);
686 #endif
687 
688  // A helper for working with text inside PCDATA nodes
689  class PUGIXML_CLASS xml_text
690  {
691  friend class xml_node;
692 
693  xml_node_struct* _root;
694 
695  typedef void (*unspecified_bool_type)(xml_text***);
696 
697  explicit xml_text(xml_node_struct* root);
698 
699  xml_node_struct* _data_new();
700  xml_node_struct* _data() const;
701 
702  public:
703  // Default constructor. Constructs an empty object.
704  xml_text();
705 
706  // Safe bool conversion operator
707  operator unspecified_bool_type() const;
708 
709  // Borland C++ workaround
710  bool operator!() const;
711 
712  // Check if text object is empty
713  bool empty() const;
714 
715  // Get text, or "" if object is empty
716  const char_t* get() const;
717 
718  // Get text, or the default value if object is empty
719  const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
720 
721  // Get text as a number, or the default value if conversion did not succeed or object is empty
722  int as_int(int def = 0) const;
723  unsigned int as_uint(unsigned int def = 0) const;
724  double as_double(double def = 0) const;
725  float as_float(float def = 0) const;
726 
727  #ifdef PUGIXML_HAS_LONG_LONG
728  long long as_llong(long long def = 0) const;
729  unsigned long long as_ullong(unsigned long long def = 0) const;
730  #endif
731 
732  // Get text as bool (returns true if first character is in '1tTyY' set), or the default value if object is empty
733  bool as_bool(bool def = false) const;
734 
735  // Set text (returns false if object is empty or there is not enough memory)
736  bool set(const char_t* rhs);
737 
738  // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
739  bool set(int rhs);
740  bool set(unsigned int rhs);
741  bool set(double rhs);
742  bool set(float rhs);
743  bool set(bool rhs);
744 
745  #ifdef PUGIXML_HAS_LONG_LONG
746  bool set(long long rhs);
747  bool set(unsigned long long rhs);
748  #endif
749 
750  // Set text (equivalent to set without error checking)
751  xml_text& operator=(const char_t* rhs);
752  xml_text& operator=(int rhs);
753  xml_text& operator=(unsigned int rhs);
754  xml_text& operator=(double rhs);
755  xml_text& operator=(float rhs);
756  xml_text& operator=(bool rhs);
757 
758  #ifdef PUGIXML_HAS_LONG_LONG
759  xml_text& operator=(long long rhs);
760  xml_text& operator=(unsigned long long rhs);
761  #endif
762 
763  // Get the data node (node_pcdata or node_cdata) for this object
764  xml_node data() const;
765  };
766 
767 #ifdef __BORLANDC__
768  // Borland C++ workaround
769  bool PUGIXML_FUNCTION operator&&(const xml_text& lhs, bool rhs);
770  bool PUGIXML_FUNCTION operator||(const xml_text& lhs, bool rhs);
771 #endif
772 
773  // Child node iterator (a bidirectional iterator over a collection of xml_node)
774  class PUGIXML_CLASS xml_node_iterator
775  {
776  friend class xml_node;
777 
778  private:
779  mutable xml_node _wrap;
780  xml_node _parent;
781 
782  xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent);
783 
784  public:
785  // Iterator traits
786  typedef ptrdiff_t difference_type;
787  typedef xml_node value_type;
788  typedef xml_node* pointer;
789  typedef xml_node& reference;
790 
791  #ifndef PUGIXML_NO_STL
792  typedef std::bidirectional_iterator_tag iterator_category;
793  #endif
794 
795  // Default constructor
796  xml_node_iterator();
797 
798  // Construct an iterator which points to the specified node
799  xml_node_iterator(const xml_node& node);
800 
801  // Iterator operators
802  bool operator==(const xml_node_iterator& rhs) const;
803  bool operator!=(const xml_node_iterator& rhs) const;
804 
805  xml_node& operator*() const;
806  xml_node* operator->() const;
807 
808  const xml_node_iterator& operator++();
809  xml_node_iterator operator++(int);
810 
811  const xml_node_iterator& operator--();
812  xml_node_iterator operator--(int);
813  };
814 
815  // Attribute iterator (a bidirectional iterator over a collection of xml_attribute)
816  class PUGIXML_CLASS xml_attribute_iterator
817  {
818  friend class xml_node;
819 
820  private:
821  mutable xml_attribute _wrap;
822  xml_node _parent;
823 
824  xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent);
825 
826  public:
827  // Iterator traits
828  typedef ptrdiff_t difference_type;
829  typedef xml_attribute value_type;
830  typedef xml_attribute* pointer;
831  typedef xml_attribute& reference;
832 
833  #ifndef PUGIXML_NO_STL
834  typedef std::bidirectional_iterator_tag iterator_category;
835  #endif
836 
837  // Default constructor
838  xml_attribute_iterator();
839 
840  // Construct an iterator which points to the specified attribute
841  xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);
842 
843  // Iterator operators
844  bool operator==(const xml_attribute_iterator& rhs) const;
845  bool operator!=(const xml_attribute_iterator& rhs) const;
846 
847  xml_attribute& operator*() const;
848  xml_attribute* operator->() const;
849 
850  const xml_attribute_iterator& operator++();
851  xml_attribute_iterator operator++(int);
852 
853  const xml_attribute_iterator& operator--();
854  xml_attribute_iterator operator--(int);
855  };
856 
857  // Named node range helper
858  class PUGIXML_CLASS xml_named_node_iterator
859  {
860  friend class xml_node;
861 
862  public:
863  // Iterator traits
864  typedef ptrdiff_t difference_type;
865  typedef xml_node value_type;
866  typedef xml_node* pointer;
867  typedef xml_node& reference;
868 
869  #ifndef PUGIXML_NO_STL
870  typedef std::bidirectional_iterator_tag iterator_category;
871  #endif
872 
873  // Default constructor
874  xml_named_node_iterator();
875 
876  // Construct an iterator which points to the specified node
877  xml_named_node_iterator(const xml_node& node, const char_t* name);
878 
879  // Iterator operators
880  bool operator==(const xml_named_node_iterator& rhs) const;
881  bool operator!=(const xml_named_node_iterator& rhs) const;
882 
883  xml_node& operator*() const;
884  xml_node* operator->() const;
885 
886  const xml_named_node_iterator& operator++();
887  xml_named_node_iterator operator++(int);
888 
889  const xml_named_node_iterator& operator--();
890  xml_named_node_iterator operator--(int);
891 
892  private:
893  mutable xml_node _wrap;
894  xml_node _parent;
895  const char_t* _name;
896 
897  xml_named_node_iterator(xml_node_struct* ref, xml_node_struct* parent, const char_t* name);
898  };
899 
900  // Abstract tree walker class (see xml_node::traverse)
901  class PUGIXML_CLASS xml_tree_walker
902  {
903  friend class xml_node;
904 
905  private:
906  int _depth;
907 
908  protected:
909  // Get current traversal depth
910  int depth() const;
911 
912  public:
913  xml_tree_walker();
914  virtual ~xml_tree_walker();
915 
916  // Callback that is called when traversal begins
917  virtual bool begin(xml_node& node);
918 
919  // Callback that is called for each node traversed
920  virtual bool for_each(xml_node& node) = 0;
921 
922  // Callback that is called when traversal ends
923  virtual bool end(xml_node& node);
924  };
925 
926  // Parsing status, returned as part of xml_parse_result object
927  enum xml_parse_status
928  {
929  status_ok = 0, // No error
930 
931  status_file_not_found, // File was not found during load_file()
932  status_io_error, // Error reading from file/stream
933  status_out_of_memory, // Could not allocate memory
934  status_internal_error, // Internal error occurred
935 
936  status_unrecognized_tag, // Parser could not determine tag type
937 
938  status_bad_pi, // Parsing error occurred while parsing document declaration/processing instruction
939  status_bad_comment, // Parsing error occurred while parsing comment
940  status_bad_cdata, // Parsing error occurred while parsing CDATA section
941  status_bad_doctype, // Parsing error occurred while parsing document type declaration
942  status_bad_pcdata, // Parsing error occurred while parsing PCDATA section
943  status_bad_start_element, // Parsing error occurred while parsing start element tag
944  status_bad_attribute, // Parsing error occurred while parsing element attribute
945  status_bad_end_element, // Parsing error occurred while parsing end element tag
946  status_end_element_mismatch,// There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or there was an excessive closing tag)
947 
948  status_append_invalid_root, // Unable to append nodes since root type is not node_element or node_document (exclusive to xml_node::append_buffer)
949 
950  status_no_document_element // Parsing resulted in a document without element nodes
951  };
952 
953  // Parsing result
954  struct PUGIXML_CLASS xml_parse_result
955  {
956  // Parsing status (see xml_parse_status)
957  xml_parse_status status;
958 
959  // Last parsed offset (in char_t units from start of input data)
960  ptrdiff_t offset;
961 
962  // Source document encoding
963  xml_encoding encoding;
964 
965  // Default constructor, initializes object to failed state
966  xml_parse_result();
967 
968  // Cast to bool operator
969  operator bool() const;
970 
971  // Get error description
972  const char* description() const;
973  };
974 
975  // Document class (DOM tree root)
976  class PUGIXML_CLASS xml_document: public xml_node
977  {
978  private:
979  char_t* _buffer;
980 
981  char _memory[192];
982 
983  // Non-copyable semantics
984  xml_document(const xml_document&);
985  const xml_document& operator=(const xml_document&);
986 
987  void create();
988  void destroy();
989 
990  public:
991  // Default constructor, makes empty document
992  xml_document();
993 
994  // Destructor, invalidates all node/attribute handles to this document
995  ~xml_document();
996 
997  // Removes all nodes, leaving the empty document
998  void reset();
999 
1000  // Removes all nodes, then copies the entire contents of the specified document
1001  void reset(const xml_document& proto);
1002 
1003  #ifndef PUGIXML_NO_STL
1004  // Load document from stream.
1005  xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream,
1006  unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1007  xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream,
1008  unsigned int options = parse_default);
1009  xml_parse_result loadNext(std::basic_istream<char, std::char_traits<char> >& stream,
1010  unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1011 
1012  #endif
1013 
1014  // (deprecated: use load_string instead) Load document from zero-terminated string. No encoding conversions are applied.
1015  xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
1016 
1017  // Load document from zero-terminated string. No encoding conversions are applied.
1018  xml_parse_result load_string(const char_t* contents, unsigned int options = parse_default);
1019 
1020  // Load document from file
1021  xml_parse_result load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1022  xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1023 
1024  // Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns.
1025  xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1026 
1027  // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
1028  // You should ensure that buffer data will persist throughout the document's lifetime, and free the buffer memory manually once document is destroyed.
1029  xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1030 
1031  // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
1032  // You should allocate the buffer with pugixml allocation function; document will free the buffer when it is no longer needed (you can't use it anymore).
1033  xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1034 
1035  // Save XML document to writer (semantics is slightly different from xml_node::print, see documentation for details).
1036  void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1037 
1038  #ifndef PUGIXML_NO_STL
1039  // Save XML document to stream (semantics is slightly different from xml_node::print, see documentation for details).
1040  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;
1041  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;
1042  #endif
1043 
1044  // Save XML to file
1045  bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1046  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;
1047 
1048  // Get document element
1049  xml_node document_element() const;
1050  };
1051 
1052 #ifndef PUGIXML_NO_XPATH
1053  // XPath query return type
1054  enum xpath_value_type
1055  {
1056  xpath_type_none, // Unknown type (query failed to compile)
1057  xpath_type_node_set, // Node set (xpath_node_set)
1058  xpath_type_number, // Number
1059  xpath_type_string, // String
1060  xpath_type_boolean // Boolean
1061  };
1062 
1063  // XPath parsing result
1064  struct PUGIXML_CLASS xpath_parse_result
1065  {
1066  // Error message (0 if no error)
1067  const char* error;
1068 
1069  // Last parsed offset (in char_t units from string start)
1070  ptrdiff_t offset;
1071 
1072  // Default constructor, initializes object to failed state
1073  xpath_parse_result();
1074 
1075  // Cast to bool operator
1076  operator bool() const;
1077 
1078  // Get error description
1079  const char* description() const;
1080  };
1081 
1082  // A single XPath variable
1083  class PUGIXML_CLASS xpath_variable
1084  {
1085  friend class xpath_variable_set;
1086 
1087  protected:
1088  xpath_value_type _type;
1089  xpath_variable* _next;
1090 
1091  xpath_variable(xpath_value_type type);
1092 
1093  // Non-copyable semantics
1094  xpath_variable(const xpath_variable&);
1095  xpath_variable& operator=(const xpath_variable&);
1096 
1097  public:
1098  // Get variable name
1099  const char_t* name() const;
1100 
1101  // Get variable type
1102  xpath_value_type type() const;
1103 
1104  // Get variable value; no type conversion is performed, default value (false, NaN, empty string, empty node set) is returned on type mismatch error
1105  bool get_boolean() const;
1106  double get_number() const;
1107  const char_t* get_string() const;
1108  const xpath_node_set& get_node_set() const;
1109 
1110  // Set variable value; no type conversion is performed, false is returned on type mismatch error
1111  bool set(bool value);
1112  bool set(double value);
1113  bool set(const char_t* value);
1114  bool set(const xpath_node_set& value);
1115  };
1116 
1117  // A set of XPath variables
1118  class PUGIXML_CLASS xpath_variable_set
1119  {
1120  private:
1121  xpath_variable* _data[64];
1122 
1123  void _assign(const xpath_variable_set& rhs);
1124  void _swap(xpath_variable_set& rhs);
1125 
1126  xpath_variable* _find(const char_t* name) const;
1127 
1128  static bool _clone(xpath_variable* var, xpath_variable** out_result);
1129  static void _destroy(xpath_variable* var);
1130 
1131  public:
1132  // Default constructor/destructor
1133  xpath_variable_set();
1134  ~xpath_variable_set();
1135 
1136  // Copy constructor/assignment operator
1137  xpath_variable_set(const xpath_variable_set& rhs);
1138  xpath_variable_set& operator=(const xpath_variable_set& rhs);
1139 
1140  #if __cplusplus >= 201103
1141  // Move semantics support
1142  xpath_variable_set(xpath_variable_set&& rhs);
1143  xpath_variable_set& operator=(xpath_variable_set&& rhs);
1144  #endif
1145 
1146  // Add a new variable or get the existing one, if the types match
1147  xpath_variable* add(const char_t* name, xpath_value_type type);
1148 
1149  // Set value of an existing variable; no type conversion is performed, false is returned if there is no such variable or if types mismatch
1150  bool set(const char_t* name, bool value);
1151  bool set(const char_t* name, double value);
1152  bool set(const char_t* name, const char_t* value);
1153  bool set(const char_t* name, const xpath_node_set& value);
1154 
1155  // Get existing variable by name
1156  xpath_variable* get(const char_t* name);
1157  const xpath_variable* get(const char_t* name) const;
1158  };
1159 
1160  // A compiled XPath query object
1161  class PUGIXML_CLASS xpath_query
1162  {
1163  private:
1164  void* _impl;
1165  xpath_parse_result _result;
1166 
1167  typedef void (*unspecified_bool_type)(xpath_query***);
1168 
1169  // Non-copyable semantics
1170  xpath_query(const xpath_query&);
1171  xpath_query& operator=(const xpath_query&);
1172 
1173  public:
1174  // Construct a compiled object from XPath expression.
1175  // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on compilation errors.
1176  explicit xpath_query(const char_t* query, xpath_variable_set* variables = 0);
1177 
1178  // Constructor
1179  xpath_query();
1180 
1181  // Destructor
1182  ~xpath_query();
1183 
1184  #if __cplusplus >= 201103
1185  // Move semantics support
1186  xpath_query(xpath_query&& rhs);
1187  xpath_query& operator=(xpath_query&& rhs);
1188  #endif
1189 
1190  // Get query expression return type
1191  xpath_value_type return_type() const;
1192 
1193  // Evaluate expression as boolean value in the specified context; performs type conversion if necessary.
1194  // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1195  bool evaluate_boolean(const xpath_node& n) const;
1196 
1197  // Evaluate expression as double value in the specified context; performs type conversion if necessary.
1198  // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1199  double evaluate_number(const xpath_node& n) const;
1200 
1201  #ifndef PUGIXML_NO_STL
1202  // Evaluate expression as string value in the specified context; performs type conversion if necessary.
1203  // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1204  string_t evaluate_string(const xpath_node& n) const;
1205  #endif
1206 
1207  // Evaluate expression as string value in the specified context; performs type conversion if necessary.
1208  // At most capacity characters are written to the destination buffer, full result size is returned (includes terminating zero).
1209  // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1210  // If PUGIXML_NO_EXCEPTIONS is defined, returns empty set instead.
1211  size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const;
1212 
1213  // Evaluate expression as node set in the specified context.
1214  // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on type mismatch and std::bad_alloc on out of memory errors.
1215  // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node set instead.
1216  xpath_node_set evaluate_node_set(const xpath_node& n) const;
1217 
1218  // Evaluate expression as node set in the specified context.
1219  // Return first node in document order, or empty node if node set is empty.
1220  // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on type mismatch and std::bad_alloc on out of memory errors.
1221  // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node instead.
1222  xpath_node evaluate_node(const xpath_node& n) const;
1223 
1224  // Get parsing result (used to get compilation errors in PUGIXML_NO_EXCEPTIONS mode)
1225  const xpath_parse_result& result() const;
1226 
1227  // Safe bool conversion operator
1228  operator unspecified_bool_type() const;
1229 
1230  // Borland C++ workaround
1231  bool operator!() const;
1232  };
1233 
1234  #ifndef PUGIXML_NO_EXCEPTIONS
1235  // XPath exception class
1236  class PUGIXML_CLASS xpath_exception: public std::exception
1237  {
1238  private:
1239  xpath_parse_result _result;
1240 
1241  public:
1242  // Construct exception from parse result
1243  explicit xpath_exception(const xpath_parse_result& result);
1244 
1245  // Get error message
1246  virtual const char* what() const throw();
1247 
1248  // Get parse result
1249  const xpath_parse_result& result() const;
1250  };
1251  #endif
1252 
1253  // XPath node class (either xml_node or xml_attribute)
1254  class PUGIXML_CLASS xpath_node
1255  {
1256  private:
1257  xml_node _node;
1258  xml_attribute _attribute;
1259 
1260  typedef void (*unspecified_bool_type)(xpath_node***);
1261 
1262  public:
1263  // Default constructor; constructs empty XPath node
1264  xpath_node();
1265 
1266  // Construct XPath node from XML node/attribute
1267  xpath_node(const xml_node& node);
1268  xpath_node(const xml_attribute& attribute, const xml_node& parent);
1269 
1270  // Get node/attribute, if any
1271  xml_node node() const;
1272  xml_attribute attribute() const;
1273 
1274  // Get parent of contained node/attribute
1275  xml_node parent() const;
1276 
1277  // Safe bool conversion operator
1278  operator unspecified_bool_type() const;
1279 
1280  // Borland C++ workaround
1281  bool operator!() const;
1282 
1283  // Comparison operators
1284  bool operator==(const xpath_node& n) const;
1285  bool operator!=(const xpath_node& n) const;
1286  };
1287 
1288 #ifdef __BORLANDC__
1289  // Borland C++ workaround
1290  bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);
1291  bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);
1292 #endif
1293 
1294  // A fixed-size collection of XPath nodes
1295  class PUGIXML_CLASS xpath_node_set
1296  {
1297  public:
1298  // Collection type
1299  enum type_t
1300  {
1301  type_unsorted, // Not ordered
1302  type_sorted, // Sorted by document order (ascending)
1303  type_sorted_reverse // Sorted by document order (descending)
1304  };
1305 
1306  // Constant iterator type
1307  typedef const xpath_node* const_iterator;
1308 
1309  // We define non-constant iterator to be the same as constant iterator so that various generic algorithms (i.e. boost foreach) work
1310  typedef const xpath_node* iterator;
1311 
1312  // Default constructor. Constructs empty set.
1313  xpath_node_set();
1314 
1315  // Constructs a set from iterator range; data is not checked for duplicates and is not sorted according to provided type, so be careful
1316  xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted);
1317 
1318  // Destructor
1319  ~xpath_node_set();
1320 
1321  // Copy constructor/assignment operator
1322  xpath_node_set(const xpath_node_set& ns);
1323  xpath_node_set& operator=(const xpath_node_set& ns);
1324 
1325  #if __cplusplus >= 201103
1326  // Move semantics support
1327  xpath_node_set(xpath_node_set&& rhs);
1328  xpath_node_set& operator=(xpath_node_set&& rhs);
1329  #endif
1330 
1331  // Get collection type
1332  type_t type() const;
1333 
1334  // Get collection size
1335  size_t size() const;
1336 
1337  // Indexing operator
1338  const xpath_node& operator[](size_t index) const;
1339 
1340  // Collection iterators
1341  const_iterator begin() const;
1342  const_iterator end() const;
1343 
1344  // Sort the collection in ascending/descending order by document order
1345  void sort(bool reverse = false);
1346 
1347  // Get first node in the collection by document order
1348  xpath_node first() const;
1349 
1350  // Check if collection is empty
1351  bool empty() const;
1352 
1353  private:
1354  type_t _type;
1355 
1356  xpath_node _storage;
1357 
1358  xpath_node* _begin;
1359  xpath_node* _end;
1360 
1361  void _assign(const_iterator begin, const_iterator end, type_t type);
1362  void _move(xpath_node_set& rhs);
1363  };
1364 #endif
1365 
1366 #ifndef PUGIXML_NO_STL
1367  // Convert wide string to UTF8
1368  std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);
1369  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);
1370 
1371  // Convert UTF8 to wide string
1372  std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
1373  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);
1374 #endif
1375 
1376  // Memory allocation function interface; returns pointer to allocated memory or NULL on failure
1377  typedef void* (*allocation_function)(size_t size);
1378 
1379  // Memory deallocation function interface
1380  typedef void (*deallocation_function)(void* ptr);
1381 
1382  // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions.
1383  void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);
1384 
1385  // Get current memory management functions
1386  allocation_function PUGIXML_FUNCTION get_memory_allocation_function();
1387  deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function();
1388 }
1389 
1390 #if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
1391 namespace std
1392 {
1393  // Workarounds for (non-standard) iterator category detection for older versions (MSVC7/IC8 and earlier)
1394  std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_node_iterator&);
1395  std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_attribute_iterator&);
1396  std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_named_node_iterator&);
1397 }
1398 #endif
1399 
1400 #if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
1401 namespace std
1402 {
1403  // Workarounds for (non-standard) iterator category detection
1404  std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_node_iterator&);
1405  std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_attribute_iterator&);
1406  std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_named_node_iterator&);
1407 }
1408 #endif
1409 
1410 // Make sure implementation is included in header-only mode
1411 // Use macro expansion in #include to work around QMake (QTBUG-11923)
1412 #if defined(PUGIXML_HEADER_ONLY) && !defined(PUGIXML_SOURCE)
1413 # define PUGIXML_SOURCE "pugixml.cpp"
1414 # include PUGIXML_SOURCE
1415 #endif
1416 
bool operator||(const ProgArg &a, const ProgArg &b)
this allows to check if either of two progargs are defined
Definition: ProgArg.h:202
ICLQt_API void save(const core::ImgBase &image, const std::string &filename)
write an image to HD
ICLQt_API core::Img< T > create(const std::string &name, core::format fmt=icl::core::formatRGB)
create a test image (converted to destination core::format) (affinity for floats)
ICLQt_API void text(ImgQ &image, int x, int y, const string &text)
renders a text into an image (only available with Qt-Support)
ICLQt_API core::Img< T > load(const std::string &filename)
load an image file read file (affinity for floats)
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
std::string str(const T &t)
convert a data type into a string using an std::ostringstream instance
Definition: StringUtils.h:136
ICLCV_API void error(const char *msg)
Display error message and terminate program.
ICLQt_API ImgQ operator *(const ImgQ &a, const ImgQ &b)
multiplies two images pixel-wise
depth
determines the pixel type of an image (8Bit-int or 32Bit-float)
Definition: Types.h:60
bool operator &&(const ProgArg &a, const ProgArg &b)
this allows to check if two progargs are defined
Definition: ProgArg.h:170
void print(const core::Img< T > &image)
print the images parameters to std::out