Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PugiXML.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLUtils/src/ICLUtils/PugiXML.h                        **
00010 ** Module : ICLUtils                                               **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 /************************************************************************
00032 * pugixml parser - version 1.0
00033 * --------------------------------------------------------
00034 * Copyright (C) 2006-2010, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
00035 * Report bugs and download new versions at http://pugixml.org/
00036 *
00037 * This library (PugiXML) is distributed under the MIT License.
00038 * See notice at the end
00039 * of this file.
00040 *
00041 * This work is based on the pugxml parser, which is:
00042 * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
00043 *
00044 * The ICL developers applied only minor changes to this files
00045 *************************************************************************/
00046 
00047 #pragma once
00048 
00049 #ifdef WIN32
00050   #ifdef ICLUtils_EXPORTS
00051     #define PUGIXML_API __declspec(dllexport)
00052   #else
00053     #define PUGIXML_CLASS __declspec(dllimport)
00054   #endif
00055 #endif
00056 
00058 //#include "pugiconfig.hpp" we use everything here
00059 
00060 #ifndef PUGIXML_NO_STL
00061 namespace std
00062 {
00063   struct bidirectional_iterator_tag;
00064 
00065 #ifdef __SUNPRO_CC
00066   // Sun C++ compiler has a bug which forces template argument names in forward declarations to be the same as in actual definitions
00067   template <class _T> class allocator;
00068   template <class _charT> struct char_traits;
00069   template <class _charT, class _Traits> class basic_istream;
00070   template <class _charT, class _Traits> class basic_ostream;
00071   template <class _charT, class _Traits, class _Allocator> class basic_string;
00072 #else
00073   // Borland C++ compiler has a bug which forces template argument names in forward declarations to be the same as in actual definitions
00074   template <class _Ty> class allocator;
00075   template <class _Ty> struct char_traits;
00076   template <class _Elem, class _Traits> class basic_istream;
00077   template <class _Elem, class _Traits> class basic_ostream;
00078   template <class _Elem, class _Traits, class _Ax> class basic_string;
00079 #endif
00080 
00081   // Digital Mars compiler has a bug which requires a forward declaration for explicit instantiation (otherwise type selection is messed up later, producing link errors)
00082   // Also note that we have to declare char_traits as a class here, since it's defined that way
00083 #ifdef __DMC__
00084   template <> class char_traits<char>;
00085 #endif
00086 }
00087 #endif
00088 
00089 // Macro for deprecated features
00090 #ifndef PUGIXML_DEPRECATED
00091 #       if defined(__GNUC__)
00092 #               define PUGIXML_DEPRECATED __attribute__((deprecated))
00093 #       elif defined(_MSC_VER) && _MSC_VER >= 1300
00094 #               define PUGIXML_DEPRECATED __declspec(deprecated)
00095 #       else
00096 #               define PUGIXML_DEPRECATED
00097 #       endif
00098 #endif
00099 
00100 // Include exception header for XPath
00101 #if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
00102 #       include <exception>
00103 #endif
00104 
00105 // If no API is defined, assume default
00106 #ifndef PUGIXML_API
00107 #   define PUGIXML_API
00108 #endif
00109 
00110 // If no API for classes is defined, assume default
00111 #ifndef PUGIXML_CLASS
00112 #   define PUGIXML_CLASS PUGIXML_API
00113 #endif
00114 
00115 // If no API for functions is defined, assume default
00116 #ifndef PUGIXML_FUNCTION
00117 #   define PUGIXML_FUNCTION PUGIXML_API
00118 #endif
00119 
00120 #include <stddef.h>
00121 
00122 // Character interface macros
00123 #ifdef PUGIXML_WCHAR_MODE
00124 #       define PUGIXML_TEXT(t) L ## t
00125 #       define PUGIXML_CHAR wchar_t
00126 #else
00127 #       define PUGIXML_TEXT(t) t
00128 #       define PUGIXML_CHAR char
00129 #endif
00130 
00136 
00137 namespace pugi{
00139   typedef PUGIXML_CHAR char_t;
00140 
00141 #ifndef PUGIXML_NO_STL
00142 
00143   typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
00144 #endif
00145 
00147 
00148   enum xml_node_type{
00149     node_null,          
00150     node_document,      
00151     node_element,       
00152     node_pcdata,        
00153     node_cdata,         
00154     node_comment,       
00155     node_pi,            
00156     node_declaration,   
00157     node_doctype        
00158   };
00159 
00160 
00162 
00164   const unsigned int parse_minimal = 0x0000;
00165 
00167 
00168   const unsigned int parse_pi = 0x0001;
00169 
00171 
00172   const unsigned int parse_comments = 0x0002;
00173 
00175 
00176   const unsigned int parse_cdata = 0x0004;
00177 
00179 
00180   const unsigned int parse_ws_pcdata = 0x0008;
00181 
00183 
00184   const unsigned int parse_escapes = 0x0010;
00185 
00187 
00188   const unsigned int parse_eol = 0x0020;
00189 
00190   // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. 
00192   const unsigned int parse_wconv_attribute = 0x0040;
00193 
00195 
00196   const unsigned int parse_wnorm_attribute = 0x0080;
00197 
00199 
00200   const unsigned int parse_declaration = 0x0100;
00201 
00203 
00204   const unsigned int parse_doctype = 0x0200;
00205 
00207 
00209   const unsigned int parse_default = parse_cdata | parse_escapes | parse_wconv_attribute | parse_eol;
00210 
00211   // The full parsing mode.
00214   const unsigned int parse_full = parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype;
00215 
00217   enum xml_encoding{
00218     encoding_auto,      
00219     encoding_utf8,      
00220     encoding_utf16_le,  
00221     encoding_utf16_be,  
00222     encoding_utf16,     
00223     encoding_utf32_le,  
00224     encoding_utf32_be,  
00225     encoding_utf32,     
00226     encoding_wchar      
00227   };
00228 
00229 
00231 
00232   const unsigned int format_indent = 0x01;
00233 
00235 
00236   const unsigned int format_write_bom = 0x02;
00237 
00239 
00240   const unsigned int format_raw = 0x04;
00241 
00243 
00244   const unsigned int format_no_declaration = 0x08;
00245 
00247 
00248   const unsigned int format_default = format_indent;
00249 
00251   // Forward declarations
00252   struct xml_attribute_struct;
00253   struct xml_node_struct;
00254 
00255   class xml_node_iterator;
00256   class xml_attribute_iterator;
00257 
00258   class xml_tree_walker;
00259 
00260   class xml_node;
00261 
00262 #ifndef PUGIXML_NO_XPATH
00263   class xpath_node;
00264   class xpath_node_set;
00265   class xpath_query;
00266   class xpath_variable_set;
00267 #endif
00268 
00271 
00272   class PUGIXML_CLASS xml_writer{
00273   public:
00274     virtual ~xml_writer() {}
00275 
00276     // Write memory chunk into stream/file/whatever
00277     virtual void write(const void* data, size_t size) = 0;
00278   };
00279 
00280 
00282   class PUGIXML_CLASS xml_writer_file : public xml_writer{
00283   public:
00285     xml_writer_file(void* file);
00286     virtual void write(const void* data, size_t size);
00287 
00288   private:
00289     void* file;
00290   };
00291 
00292 
00293 #ifndef PUGIXML_NO_STL
00294 
00295   class PUGIXML_CLASS xml_writer_stream : public xml_writer{
00296   public:
00298     xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
00299     xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
00300 
00301     virtual void write(const void* data, size_t size);
00302 
00303   private:
00304     std::basic_ostream<char, std::char_traits<char> >* narrow_stream;
00305     std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream;
00306   };
00307 #endif
00308 
00310   class PUGIXML_CLASS xml_attribute{
00311     friend class xml_attribute_iterator;
00312     friend class xml_node;
00313 
00314   private:
00315     xml_attribute_struct* _attr;
00316 
00317     typedef xml_attribute_struct* xml_attribute::*unspecified_bool_type;
00318 
00319   public:
00321     xml_attribute();
00322 
00324     explicit xml_attribute(xml_attribute_struct* attr);
00325 
00327     operator unspecified_bool_type() const;
00328 
00330     bool operator!() const;
00331 
00333     bool operator==(const xml_attribute& r) const;
00334     bool operator!=(const xml_attribute& r) const;
00335     bool operator<(const xml_attribute& r) const;
00336     bool operator>(const xml_attribute& r) const;
00337     bool operator<=(const xml_attribute& r) const;
00338     bool operator>=(const xml_attribute& r) const;
00339 
00341     bool empty() const;
00342 
00344     const char_t* name() const;
00345     const char_t* value() const;
00346 
00348     int as_int() const;
00349     unsigned int as_uint() const;
00350     double as_double() const;
00351     float as_float() const;
00352 
00354     bool as_bool() const;
00355 
00357     bool set_name(const char_t* rhs);
00358     bool set_value(const char_t* rhs);
00359 
00361     bool set_value(int rhs);
00362     bool set_value(unsigned int rhs);
00363     bool set_value(double rhs);
00364     bool set_value(bool rhs);
00365 
00367     xml_attribute& operator=(const char_t* rhs);
00368     xml_attribute& operator=(int rhs);
00369     xml_attribute& operator=(unsigned int rhs);
00370     xml_attribute& operator=(double rhs);
00371     xml_attribute& operator=(bool rhs);
00372 
00374     xml_attribute next_attribute() const;
00375     xml_attribute previous_attribute() const;
00376 
00378     size_t hash_value() const;
00379 
00381     xml_attribute_struct* internal_object() const;
00382   };
00383 
00384 
00385 
00387 #ifdef __BORLANDC__
00388 
00389   bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs);
00390   bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs);
00391 #endif
00392 
00394 
00395   class PUGIXML_CLASS xml_node{
00396     friend class xml_attribute_iterator;
00397     friend class xml_node_iterator;
00398 
00399   protected:
00400     xml_node_struct* _root;
00401 
00402     typedef xml_node_struct* xml_node::*unspecified_bool_type;
00403 
00404   public:
00406     xml_node();
00407 
00409     explicit xml_node(xml_node_struct* p);
00410 
00412     operator unspecified_bool_type() const;
00413 
00415     bool operator!() const;
00416 
00418     bool operator==(const xml_node& r) const;
00419     bool operator!=(const xml_node& r) const;
00420     bool operator<(const xml_node& r) const;
00421     bool operator>(const xml_node& r) const;
00422     bool operator<=(const xml_node& r) const;
00423     bool operator>=(const xml_node& r) const;
00424 
00426     bool empty() const;
00427 
00429     xml_node_type type() const;
00430 
00432     const char_t* name() const;
00433     const char_t* value() const;
00434 
00436     xml_attribute first_attribute() const;
00437     xml_attribute last_attribute() const;
00438 
00440     xml_node first_child() const;
00441     xml_node last_child() const;
00442 
00444     xml_node next_sibling() const;
00445     xml_node previous_sibling() const;
00446 
00448     xml_node parent() const;
00449 
00451     xml_node root() const;
00452 
00454     xml_node child(const char_t* name) const;
00455     xml_attribute attribute(const char_t* name) const;
00456     xml_node next_sibling(const char_t* name) const;
00457     xml_node previous_sibling(const char_t* name) const;
00458 
00460     const char_t* child_value() const;
00461 
00463     const char_t* child_value(const char_t* name) const;
00464 
00466     bool set_name(const char_t* rhs);
00467     bool set_value(const char_t* rhs);
00468 
00470     xml_attribute append_attribute(const char_t* name);
00471     xml_attribute prepend_attribute(const char_t* name);
00472     xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr);
00473     xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr);
00474 
00476     xml_attribute append_copy(const xml_attribute& proto);
00477     xml_attribute prepend_copy(const xml_attribute& proto);
00478     xml_attribute insert_copy_after(const xml_attribute& proto, const xml_attribute& attr);
00479     xml_attribute insert_copy_before(const xml_attribute& proto, const xml_attribute& attr);
00480 
00482     xml_node append_child(xml_node_type type = node_element);
00483     xml_node prepend_child(xml_node_type type = node_element);
00484     xml_node insert_child_after(xml_node_type type, const xml_node& node);
00485     xml_node insert_child_before(xml_node_type type, const xml_node& node);
00486 
00488     xml_node append_child(const char_t* name);
00489     xml_node prepend_child(const char_t* name);
00490     xml_node insert_child_after(const char_t* name, const xml_node& node);
00491     xml_node insert_child_before(const char_t* name, const xml_node& node);
00492 
00494     xml_node append_copy(const xml_node& proto);
00495     xml_node prepend_copy(const xml_node& proto);
00496     xml_node insert_copy_after(const xml_node& proto, const xml_node& node);
00497     xml_node insert_copy_before(const xml_node& proto, const xml_node& node);
00498 
00500     bool remove_attribute(const xml_attribute& a);
00501     bool remove_attribute(const char_t* name);
00502 
00504     bool remove_child(const xml_node& n);
00505     bool remove_child(const char_t* name);
00506 
00508     template <typename Predicate> xml_attribute find_attribute(Predicate pred) const{
00509       if (!_root) return xml_attribute();
00510 
00511       for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
00512       if (pred(attrib))
00513         return attrib;
00514 
00515       return xml_attribute();
00516     }
00517 
00519     template <typename Predicate> xml_node find_child(Predicate pred) const{
00520       if (!_root) return xml_node();
00521 
00522       for (xml_node node = first_child(); node; node = node.next_sibling())
00523       if (pred(node))
00524         return node;
00525 
00526       return xml_node();
00527     }
00528 
00530     template <typename Predicate> xml_node find_node(Predicate pred) const{
00531       if (!_root) return xml_node();
00532 
00533       xml_node cur = first_child();
00534 
00535       while (cur._root && cur._root != _root)
00536       {
00537         if (pred(cur)) return cur;
00538 
00539         if (cur.first_child()) cur = cur.first_child();
00540         else if (cur.next_sibling()) cur = cur.next_sibling();
00541         else
00542         {
00543           while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
00544 
00545           if (cur._root != _root) cur = cur.next_sibling();
00546         }
00547       }
00548 
00549       return xml_node();
00550     }
00551 
00553     xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
00554     xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
00555 
00556 #ifndef PUGIXML_NO_STL
00557 
00558     string_t path(char_t delimiter = '/') const;
00559 #endif
00560 
00562     xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;
00563 
00565     bool traverse(xml_tree_walker& walker);
00566 
00567 #ifndef PUGIXML_NO_XPATH
00568 
00569     xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const;
00570     xpath_node select_single_node(const xpath_query& query) const;
00571 
00573     xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = 0) const;
00574     xpath_node_set select_nodes(const xpath_query& query) const;
00575 #endif
00576 
00578     void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"),
00579       unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
00580 
00581 #ifndef PUGIXML_NO_STL
00582 
00583     void print(std::basic_ostream<char, std::char_traits<char> >& os,
00584       const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default,
00585       xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
00586     void print(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& os,
00587       const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default,
00588       unsigned int depth = 0) const;
00589 #endif
00590 
00592     typedef xml_node_iterator iterator;
00593 
00594     iterator begin() const;
00595     iterator end() const;
00596 
00598     typedef xml_attribute_iterator attribute_iterator;
00599 
00600     attribute_iterator attributes_begin() const;
00601     attribute_iterator attributes_end() const;
00602 
00604     ptrdiff_t offset_debug() const;
00605 
00607     size_t hash_value() const;
00608 
00610     xml_node_struct* internal_object() const;
00611   };
00612 
00613 
00616 #ifdef __BORLANDC__
00617 
00618   bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);
00619   bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);
00620 #endif
00621 
00625 
00626   class PUGIXML_CLASS xml_node_iterator{
00627     friend class xml_node;
00628 
00629   private:
00630     xml_node _wrap;
00631     xml_node _parent;
00632 
00633     xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent);
00634 
00635   public:
00637     typedef ptrdiff_t difference_type;
00638     typedef xml_node value_type;
00639     typedef xml_node* pointer;
00640     typedef xml_node& reference;
00641 
00642 #ifndef PUGIXML_NO_STL
00643     typedef std::bidirectional_iterator_tag iterator_category;
00644 #endif
00645 
00647     xml_node_iterator();
00648 
00650     xml_node_iterator(const xml_node& node);
00651 
00653     bool operator==(const xml_node_iterator& rhs) const;
00654     bool operator!=(const xml_node_iterator& rhs) const;
00655 
00656     xml_node& operator*();
00657     xml_node* operator->();
00658 
00659     const xml_node_iterator& operator++();
00660     xml_node_iterator operator++(int);
00661 
00662     const xml_node_iterator& operator--();
00663     xml_node_iterator operator--(int);
00664   };
00665 
00666 
00668   class PUGIXML_CLASS xml_attribute_iterator{
00669     friend class xml_node;
00670 
00671   private:
00672     xml_attribute _wrap;
00673     xml_node _parent;
00674 
00675     xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent);
00676 
00677   public:
00679     typedef ptrdiff_t difference_type;
00680     typedef xml_attribute value_type;
00681     typedef xml_attribute* pointer;
00682     typedef xml_attribute& reference;
00683 
00684 #ifndef PUGIXML_NO_STL
00685     typedef std::bidirectional_iterator_tag iterator_category;
00686 #endif
00687 
00689     xml_attribute_iterator();
00690 
00692     xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);
00693 
00695     bool operator==(const xml_attribute_iterator& rhs) const;
00696     bool operator!=(const xml_attribute_iterator& rhs) const;
00697 
00698     xml_attribute& operator*();
00699     xml_attribute* operator->();
00700 
00701     const xml_attribute_iterator& operator++();
00702     xml_attribute_iterator operator++(int);
00703 
00704     const xml_attribute_iterator& operator--();
00705     xml_attribute_iterator operator--(int);
00706   };
00707 
00708 
00710   class PUGIXML_CLASS xml_tree_walker{
00711     friend class xml_node;
00712 
00713   private:
00714     int _depth;
00715 
00716   protected:
00718     int depth() const;
00719 
00720   public:
00721     xml_tree_walker();
00722     virtual ~xml_tree_walker();
00723 
00725     virtual bool begin(xml_node& node);
00726 
00728     virtual bool for_each(xml_node& node) = 0;
00729 
00731     virtual bool end(xml_node& node);
00732   };
00733 
00734 
00736   enum xml_parse_status{
00737     status_ok = 0,              
00738 
00739     status_file_not_found,      
00740     status_io_error,            
00741     status_out_of_memory,       
00742     status_internal_error,      
00743 
00744     status_unrecognized_tag,    
00745 
00746     status_bad_pi,              
00747     status_bad_comment,         
00748     status_bad_cdata,           
00749     status_bad_doctype,         
00750     status_bad_pcdata,          
00751     status_bad_start_element,   
00752     status_bad_attribute,       
00753     status_bad_end_element,     
00754     status_end_element_mismatch 
00755   };
00756 
00757 
00759   struct PUGIXML_CLASS xml_parse_result{
00761     xml_parse_status status;
00762 
00764     ptrdiff_t offset;
00765 
00767     xml_encoding encoding;
00768 
00770     xml_parse_result();
00771 
00773     operator bool() const;
00774 
00776     const char* description() const;
00777   };
00778 
00779 
00780 
00782   class PUGIXML_CLASS xml_document : public xml_node{
00783   private:
00784     char_t* _buffer;
00785 
00786     char _memory[192];
00787 
00789     xml_document(const xml_document&);
00790     const xml_document& operator=(const xml_document&);
00791 
00792     void create();
00793     void destroy();
00794 
00795     xml_parse_result load_buffer_impl(void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own);
00796 
00797   public:
00799     xml_document();
00800 
00802     ~xml_document();
00803 
00805     void reset();
00806 
00808     void reset(const xml_document& proto);
00809 
00810 #ifndef PUGIXML_NO_STL
00811 
00812     xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream,
00813       unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00814     xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream,
00815       unsigned int options = parse_default);
00816 
00818     xml_parse_result loadNext(std::basic_istream<char, std::char_traits<char> >& stream,
00819       unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00820 #endif
00821 
00823     xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
00824 
00826     xml_parse_result load_file(const char* path, unsigned int options = parse_default,
00827       xml_encoding encoding = encoding_auto);
00828     xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default,
00829       xml_encoding encoding = encoding_auto);
00830 
00832     xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default,
00833       xml_encoding encoding = encoding_auto);
00834 
00836 
00838     xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default,
00839       xml_encoding encoding = encoding_auto);
00840 
00842 
00844     xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default,
00845       xml_encoding encoding = encoding_auto);
00846 
00848     void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"),
00849       unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
00850 
00851 #ifndef PUGIXML_NO_STL
00852 
00853     void save(std::basic_ostream<char, std::char_traits<char> >& stream,
00854       const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default,
00855       xml_encoding encoding = encoding_auto) const;
00856     void save(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream,
00857       const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const;
00858 #endif
00859 
00861     bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"),
00862       unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
00863     bool save_file(const wchar_t* path, const char_t* indent = PUGIXML_TEXT("\t"),
00864       unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
00865 
00867     xml_node document_element() const;
00868   };
00869 
00870 
00871 #ifndef PUGIXML_NO_XPATH
00872 
00873   enum xpath_value_type{
00874     xpath_type_none,      
00875     xpath_type_node_set,  
00876     xpath_type_number,    
00877     xpath_type_string,    
00878     xpath_type_boolean    
00879   };
00880 
00881 
00883   struct PUGIXML_CLASS xpath_parse_result{
00885     const char* error;
00886 
00888     ptrdiff_t offset;
00889 
00891     xpath_parse_result();
00892 
00894     operator bool() const;
00895 
00897     const char* description() const;
00898   };
00899 
00900 
00902   class PUGIXML_CLASS xpath_variable{
00903     friend class xpath_variable_set;
00904 
00905   protected:
00906     xpath_value_type _type;
00907     xpath_variable* _next;
00908 
00909     xpath_variable();
00910 
00912     xpath_variable(const xpath_variable&);
00913     xpath_variable& operator=(const xpath_variable&);
00914 
00915   public:
00917     const char_t* name() const;
00918 
00920     xpath_value_type type() const;
00921 
00923     bool get_boolean() const;
00924     double get_number() const;
00925     const char_t* get_string() const;
00926     const xpath_node_set& get_node_set() const;
00927 
00929     bool set(bool value);
00930     bool set(double value);
00931     bool set(const char_t* value);
00932     bool set(const xpath_node_set& value);
00933   };
00934 
00935 
00937   class PUGIXML_CLASS xpath_variable_set{
00938   private:
00939     xpath_variable* _data[64];
00940 
00942     xpath_variable_set(const xpath_variable_set&);
00943     xpath_variable_set& operator=(const xpath_variable_set&);
00944 
00945     xpath_variable* find(const char_t* name) const;
00946 
00947   public:
00949     xpath_variable_set();
00950     ~xpath_variable_set();
00951 
00953     xpath_variable* add(const char_t* name, xpath_value_type type);
00954 
00956     bool set(const char_t* name, bool value);
00957     bool set(const char_t* name, double value);
00958     bool set(const char_t* name, const char_t* value);
00959     bool set(const char_t* name, const xpath_node_set& value);
00960 
00962     xpath_variable* get(const char_t* name);
00963     const xpath_variable* get(const char_t* name) const;
00964   };
00965 
00966 
00968   class PUGIXML_CLASS xpath_query{
00969   private:
00970     void* _impl;
00971     xpath_parse_result _result;
00972 
00973     typedef void* xpath_query::*unspecified_bool_type;
00974 
00976     xpath_query(const xpath_query&);
00977     xpath_query& operator=(const xpath_query&);
00978 
00979   public:
00981 
00982     explicit xpath_query(const char_t* query, xpath_variable_set* variables = 0);
00983 
00985     ~xpath_query();
00986 
00988     xpath_value_type return_type() const;
00989 
00991 
00992     bool evaluate_boolean(const xpath_node& n) const;
00993 
00995 
00996     double evaluate_number(const xpath_node& n) const;
00997 
00998 #ifndef PUGIXML_NO_STL
00999 
01000 
01001     string_t evaluate_string(const xpath_node& n) const;
01002 #endif
01003 
01005 
01008     size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const;
01009 
01011 
01013     xpath_node_set evaluate_node_set(const xpath_node& n) const;
01014 
01016     const xpath_parse_result& result() const;
01017 
01019     operator unspecified_bool_type() const;
01020 
01022     bool operator!() const;
01023   };
01024 
01025 
01026 #ifndef PUGIXML_NO_EXCEPTIONS
01027 
01028   class PUGIXML_CLASS xpath_exception : public std::exception {
01029   private:
01030     xpath_parse_result _result;
01031 
01032   public:
01034     explicit xpath_exception(const xpath_parse_result& result);
01035 
01037     virtual const char* what() const throw();
01038 
01040     const xpath_parse_result& result() const;
01041   };
01042 #endif
01043 
01045   class PUGIXML_CLASS xpath_node{
01046   private:
01047     xml_node _node;
01048     xml_attribute _attribute;
01049 
01050     typedef xml_node xpath_node::*unspecified_bool_type;
01051 
01052   public:
01054     xpath_node();
01055 
01057     xpath_node(const xml_node& node);
01058     xpath_node(const xml_attribute& attribute, const xml_node& parent);
01059 
01061     xml_node node() const;
01062     xml_attribute attribute() const;
01063 
01065     xml_node parent() const;
01066 
01068     operator unspecified_bool_type() const;
01069 
01071     bool operator!() const;
01072 
01074     bool operator==(const xpath_node& n) const;
01075     bool operator!=(const xpath_node& n) const;
01076   };
01077 
01079 #ifdef __BORLANDC__
01080 
01081   bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);
01082   bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);
01083 #endif
01084 
01086 
01087   class PUGIXML_CLASS xpath_node_set{
01088   public:
01090     enum type_t{
01091       type_unsorted,                    
01092       type_sorted,                      
01093       type_sorted_reverse               
01094     };
01095 
01097     typedef const xpath_node* const_iterator;
01098 
01100     xpath_node_set();
01101 
01103 
01104     xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted);
01105 
01107     ~xpath_node_set();
01108 
01110     xpath_node_set(const xpath_node_set& ns);
01111     xpath_node_set& operator=(const xpath_node_set& ns);
01112 
01114     type_t type() const;
01115 
01117     size_t size() const;
01118 
01120     const xpath_node& operator[](size_t index) const;
01121 
01123     const_iterator begin() const;
01124     const_iterator end() const;
01125 
01127     void sort(bool reverse = false);
01128 
01130     xpath_node first() const;
01131 
01133     bool empty() const;
01134 
01135   private:
01136     type_t _type;
01137 
01138     xpath_node _storage;
01139 
01140     xpath_node* _begin;
01141     xpath_node* _end;
01142 
01143     void _assign(const_iterator begin, const_iterator end);
01144   };
01145 #endif
01146 
01147 #ifndef PUGIXML_NO_STL
01148 
01149   std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);
01150   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);
01151 
01153   std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
01154   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);
01155 #endif
01156 
01158   typedef void* (*allocation_function)(size_t size);
01159 
01161   typedef void(*deallocation_function)(void* ptr);
01162 
01164   void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);
01165 
01167   allocation_function PUGIXML_FUNCTION get_memory_allocation_function();
01168   deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function();
01169 }
01170 
01171 #if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
01172 namespace std
01173 {
01175   std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_node_iterator&);
01176   std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_attribute_iterator&);
01177 }
01178 #endif
01179 
01180 #if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
01181 namespace std
01182 {
01184   std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_node_iterator&);
01185   std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_attribute_iterator&);
01186 }
01187 #endif
01188 
01191 /*
01192 * Copyright (c) 2006-2010 Arseny Kapoulkine
01193 *
01194 * Permission is hereby granted, free of charge, to any person
01195 * obtaining a copy of this software and associated documentation
01196 * files (the "Software"), to deal in the Software without
01197 * restriction, including without limitation the rights to use,
01198 * copy, modify, merge, publish, distribute, sublicense, and/or sell
01199 * copies of the Software, and to permit persons to whom the
01200 * Software is furnished to do so, subject to the following
01201 * conditions:
01202 *
01203 * The above copyright notice and this permission notice shall be
01204 * included in all copies or substantial portions of the Software.
01205 *
01206 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
01207 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
01208 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
01209 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
01210 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
01211 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
01212 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
01213 * OTHER DEALINGS IN THE SOFTWARE.
01214 */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines