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.GPL  **
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 
00050 //#include "pugiconfig.hpp" we use everything here
00051 
00052 #ifndef PUGIXML_NO_STL
00053 namespace std
00054 {
00055   struct bidirectional_iterator_tag;
00056 
00057 #ifdef __SUNPRO_CC
00058   // Sun C++ compiler has a bug which forces template argument names in forward declarations to be the same as in actual definitions
00059   template <class _T> class allocator;
00060   template <class _charT> struct char_traits;
00061   template <class _charT, class _Traits> class basic_istream;
00062   template <class _charT, class _Traits> class basic_ostream;
00063   template <class _charT, class _Traits, class _Allocator> class basic_string;
00064 #else
00065   // Borland C++ compiler has a bug which forces template argument names in forward declarations to be the same as in actual definitions
00066   template <class _Ty> class allocator;
00067   template <class _Ty> struct char_traits;
00068   template <class _Elem, class _Traits> class basic_istream;
00069   template <class _Elem, class _Traits> class basic_ostream;
00070   template <class _Elem, class _Traits, class _Ax> class basic_string;
00071 #endif
00072 
00073   // Digital Mars compiler has a bug which requires a forward declaration for explicit instantiation (otherwise type selection is messed up later, producing link errors)
00074   // Also note that we have to declare char_traits as a class here, since it's defined that way
00075 #ifdef __DMC__
00076   template <> class char_traits<char>;
00077 #endif
00078 }
00079 #endif
00080 
00081 // Macro for deprecated features
00082 #ifndef PUGIXML_DEPRECATED
00083 #       if defined(__GNUC__)
00084 #               define PUGIXML_DEPRECATED __attribute__((deprecated))
00085 #       elif defined(_MSC_VER) && _MSC_VER >= 1300
00086 #               define PUGIXML_DEPRECATED __declspec(deprecated)
00087 #       else
00088 #               define PUGIXML_DEPRECATED
00089 #       endif
00090 #endif
00091 
00092 // Include exception header for XPath
00093 #if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
00094 #       include <exception>
00095 #endif
00096 
00097 // If no API is defined, assume default
00098 #ifndef PUGIXML_API
00099 #   define PUGIXML_API
00100 #endif
00101 
00102 // If no API for classes is defined, assume default
00103 #ifndef PUGIXML_CLASS
00104 #   define PUGIXML_CLASS PUGIXML_API
00105 #endif
00106 
00107 // If no API for functions is defined, assume default
00108 #ifndef PUGIXML_FUNCTION
00109 #   define PUGIXML_FUNCTION PUGIXML_API
00110 #endif
00111 
00112 #include <stddef.h>
00113 
00114 // Character interface macros
00115 #ifdef PUGIXML_WCHAR_MODE
00116 #       define PUGIXML_TEXT(t) L ## t
00117 #       define PUGIXML_CHAR wchar_t
00118 #else
00119 #       define PUGIXML_TEXT(t) t
00120 #       define PUGIXML_CHAR char
00121 #endif
00122 
00128 
00129 namespace pugi{
00131   typedef PUGIXML_CHAR char_t;
00132 
00133 #ifndef PUGIXML_NO_STL
00134 
00135   typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
00136 #endif
00137 
00139 
00140   enum xml_node_type{
00141     node_null,          
00142     node_document,      
00143     node_element,       
00144     node_pcdata,        
00145     node_cdata,         
00146     node_comment,       
00147     node_pi,            
00148     node_declaration,   
00149     node_doctype        
00150   };
00151   
00152   
00154 
00156   const unsigned int parse_minimal = 0x0000;
00157   
00159 
00160   const unsigned int parse_pi = 0x0001;
00161   
00163 
00164   const unsigned int parse_comments = 0x0002;
00165   
00167 
00168   const unsigned int parse_cdata = 0x0004;
00169   
00171 
00172   const unsigned int parse_ws_pcdata = 0x0008;
00173   
00175 
00176   const unsigned int parse_escapes = 0x0010;
00177   
00179 
00180   const unsigned int parse_eol = 0x0020;
00181         
00182   // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. 
00184   const unsigned int parse_wconv_attribute = 0x0040;
00185   
00187 
00188   const unsigned int parse_wnorm_attribute = 0x0080;
00189   
00191 
00192   const unsigned int parse_declaration = 0x0100;
00193   
00195 
00196   const unsigned int parse_doctype = 0x0200;
00197   
00199 
00201   const unsigned int parse_default = parse_cdata | parse_escapes | parse_wconv_attribute | parse_eol;
00202 
00203   // The full parsing mode.
00206   const unsigned int parse_full = parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype;
00207 
00209   enum xml_encoding{
00210     encoding_auto,      
00211     encoding_utf8,      
00212     encoding_utf16_le,  
00213     encoding_utf16_be,  
00214     encoding_utf16,     
00215     encoding_utf32_le,  
00216     encoding_utf32_be,  
00217     encoding_utf32,     
00218     encoding_wchar      
00219   };
00220   
00221   
00223 
00224   const unsigned int format_indent = 0x01;
00225   
00227 
00228   const unsigned int format_write_bom = 0x02;
00229   
00231 
00232   const unsigned int format_raw = 0x04;
00233   
00235 
00236   const unsigned int format_no_declaration = 0x08;
00237     
00239 
00240   const unsigned int format_default = format_indent;
00241   
00243   // Forward declarations
00244   struct xml_attribute_struct;
00245   struct xml_node_struct;
00246   
00247   class xml_node_iterator;
00248   class xml_attribute_iterator;
00249   
00250   class xml_tree_walker;
00251   
00252   class xml_node;
00253   
00254 #ifndef PUGIXML_NO_XPATH
00255   class xpath_node;
00256   class xpath_node_set;
00257   class xpath_query;
00258   class xpath_variable_set;
00259 #endif
00260   
00263 
00264   class PUGIXML_CLASS xml_writer{
00265     public:
00266     virtual ~xml_writer() {}
00267     
00268     // Write memory chunk into stream/file/whatever
00269     virtual void write(const void* data, size_t size) = 0;
00270   };
00271     
00272     
00274   class PUGIXML_CLASS xml_writer_file: public xml_writer{
00275     public:
00277     xml_writer_file(void* file);    
00278     virtual void write(const void* data, size_t size);
00279     
00280     private:
00281     void* file;
00282   };
00283   
00284   
00285 #ifndef PUGIXML_NO_STL
00286 
00287   class PUGIXML_CLASS xml_writer_stream: public xml_writer{
00288     public:
00290     xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
00291     xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
00292     
00293     virtual void write(const void* data, size_t size);
00294     
00295     private:
00296     std::basic_ostream<char, std::char_traits<char> >* narrow_stream;
00297     std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream;
00298   };
00299 #endif
00300         
00302   class PUGIXML_CLASS xml_attribute{
00303     friend class xml_attribute_iterator;
00304     friend class xml_node;
00305     
00306     private:
00307     xml_attribute_struct* _attr;
00308     
00309     typedef xml_attribute_struct* xml_attribute::*unspecified_bool_type;
00310     
00311     public:
00313     xml_attribute();
00314     
00316     explicit xml_attribute(xml_attribute_struct* attr);
00317     
00319     operator unspecified_bool_type() const;
00320     
00322     bool operator!() const;
00323     
00325     bool operator==(const xml_attribute& r) const;
00326     bool operator!=(const xml_attribute& r) const;
00327     bool operator<(const xml_attribute& r) const;
00328     bool operator>(const xml_attribute& r) const;
00329     bool operator<=(const xml_attribute& r) const;
00330     bool operator>=(const xml_attribute& r) const;
00331       
00333     bool empty() const;
00334       
00336     const char_t* name() const;
00337     const char_t* value() const;
00338       
00340     int as_int() const;
00341     unsigned int as_uint() const;
00342     double as_double() const;
00343     float as_float() const;
00344       
00346     bool as_bool() const;
00347       
00349     bool set_name(const char_t* rhs);
00350     bool set_value(const char_t* rhs);
00351       
00353     bool set_value(int rhs);
00354     bool set_value(unsigned int rhs);
00355     bool set_value(double rhs);
00356     bool set_value(bool rhs);
00357       
00359     xml_attribute& operator=(const char_t* rhs);
00360     xml_attribute& operator=(int rhs);
00361     xml_attribute& operator=(unsigned int rhs);
00362     xml_attribute& operator=(double rhs);
00363     xml_attribute& operator=(bool rhs);
00364       
00366     xml_attribute next_attribute() const;
00367     xml_attribute previous_attribute() const;
00368       
00370     size_t hash_value() const;
00371       
00373     xml_attribute_struct* internal_object() const;
00374   };
00375     
00376     
00377           
00379 #ifdef __BORLANDC__
00380 
00381   bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs);
00382   bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs);
00383 #endif
00384 
00386 
00387   class PUGIXML_CLASS xml_node{
00388     friend class xml_attribute_iterator;
00389     friend class xml_node_iterator;
00390       
00391     protected:
00392     xml_node_struct* _root;
00393       
00394     typedef xml_node_struct* xml_node::*unspecified_bool_type;
00395       
00396     public:
00398     xml_node();
00399       
00401     explicit xml_node(xml_node_struct* p);
00402       
00404     operator unspecified_bool_type() const;
00405       
00407     bool operator!() const;
00408       
00410     bool operator==(const xml_node& r) const;
00411     bool operator!=(const xml_node& r) const;
00412     bool operator<(const xml_node& r) const;
00413     bool operator>(const xml_node& r) const;
00414     bool operator<=(const xml_node& r) const;
00415     bool operator>=(const xml_node& r) const;
00416       
00418     bool empty() const;
00419       
00421     xml_node_type type() const;
00422       
00424     const char_t* name() const;
00425     const char_t* value() const;
00426       
00428     xml_attribute first_attribute() const;
00429     xml_attribute last_attribute() const;
00430       
00432     xml_node first_child() const;
00433     xml_node last_child() const;
00434       
00436     xml_node next_sibling() const;
00437     xml_node previous_sibling() const;
00438       
00440     xml_node parent() const;
00441       
00443     xml_node root() const;
00444       
00446     xml_node child(const char_t* name) const;
00447     xml_attribute attribute(const char_t* name) const;
00448     xml_node next_sibling(const char_t* name) const;
00449     xml_node previous_sibling(const char_t* name) const;
00450 
00452     const char_t* child_value() const;
00453       
00455     const char_t* child_value(const char_t* name) const;
00456       
00458     bool set_name(const char_t* rhs);
00459     bool set_value(const char_t* rhs);
00460       
00462     xml_attribute append_attribute(const char_t* name);
00463     xml_attribute prepend_attribute(const char_t* name);
00464     xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr);
00465     xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr);
00466       
00468     xml_attribute append_copy(const xml_attribute& proto);
00469     xml_attribute prepend_copy(const xml_attribute& proto);
00470     xml_attribute insert_copy_after(const xml_attribute& proto, const xml_attribute& attr);
00471     xml_attribute insert_copy_before(const xml_attribute& proto, const xml_attribute& attr);
00472       
00474     xml_node append_child(xml_node_type type = node_element);
00475     xml_node prepend_child(xml_node_type type = node_element);
00476     xml_node insert_child_after(xml_node_type type, const xml_node& node);
00477     xml_node insert_child_before(xml_node_type type, const xml_node& node);
00478       
00480     xml_node append_child(const char_t* name);
00481     xml_node prepend_child(const char_t* name);
00482     xml_node insert_child_after(const char_t* name, const xml_node& node);
00483     xml_node insert_child_before(const char_t* name, const xml_node& node);
00484       
00486     xml_node append_copy(const xml_node& proto);
00487     xml_node prepend_copy(const xml_node& proto);
00488     xml_node insert_copy_after(const xml_node& proto, const xml_node& node);
00489     xml_node insert_copy_before(const xml_node& proto, const xml_node& node);
00490       
00492     bool remove_attribute(const xml_attribute& a);
00493     bool remove_attribute(const char_t* name);
00494       
00496     bool remove_child(const xml_node& n);
00497     bool remove_child(const char_t* name);
00498       
00500     template <typename Predicate> xml_attribute find_attribute(Predicate pred) const{
00501       if (!_root) return xml_attribute();
00502         
00503       for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
00504         if (pred(attrib))
00505           return attrib;
00506         
00507       return xml_attribute();
00508     }
00509       
00511     template <typename Predicate> xml_node find_child(Predicate pred) const{
00512       if (!_root) return xml_node();
00513         
00514       for (xml_node node = first_child(); node; node = node.next_sibling())
00515         if (pred(node))
00516           return node;
00517         
00518       return xml_node();
00519     }
00520       
00522     template <typename Predicate> xml_node find_node(Predicate pred) const{
00523       if (!_root) return xml_node();
00524         
00525       xml_node cur = first_child();
00526         
00527       while (cur._root && cur._root != _root)
00528         {
00529           if (pred(cur)) return cur;
00530             
00531           if (cur.first_child()) cur = cur.first_child();
00532           else if (cur.next_sibling()) cur = cur.next_sibling();
00533           else
00534             {
00535               while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
00536                 
00537               if (cur._root != _root) cur = cur.next_sibling();
00538             }
00539         }
00540         
00541       return xml_node();
00542     }
00543       
00545     xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
00546     xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
00547       
00548 #ifndef PUGIXML_NO_STL
00549 
00550     string_t path(char_t delimiter = '/') const;
00551 #endif
00552       
00554     xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;
00555       
00557     bool traverse(xml_tree_walker& walker);
00558       
00559 #ifndef PUGIXML_NO_XPATH
00560 
00561     xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const;
00562     xpath_node select_single_node(const xpath_query& query) const;
00563       
00565     xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = 0) const;
00566     xpath_node_set select_nodes(const xpath_query& query) const;
00567 #endif
00568       
00570     void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), 
00571                unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
00572       
00573 #ifndef PUGIXML_NO_STL
00574 
00575     void print(std::basic_ostream<char, std::char_traits<char> >& os, 
00576                const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, 
00577                xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
00578     void print(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& os, 
00579                const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, 
00580                unsigned int depth = 0) const;
00581 #endif
00582       
00584     typedef xml_node_iterator iterator;
00585       
00586     iterator begin() const;
00587     iterator end() const;
00588       
00590     typedef xml_attribute_iterator attribute_iterator;
00591       
00592     attribute_iterator attributes_begin() const;
00593     attribute_iterator attributes_end() const;
00594       
00596     ptrdiff_t offset_debug() const;
00597       
00599     size_t hash_value() const;
00600       
00602     xml_node_struct* internal_object() const;
00603   };
00604     
00605 
00608 #ifdef __BORLANDC__
00609 
00610   bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);
00611   bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);
00612 #endif
00613 
00617 
00618   class PUGIXML_CLASS xml_node_iterator{
00619     friend class xml_node;
00620       
00621     private:
00622     xml_node _wrap;
00623     xml_node _parent;
00624       
00625     xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent);
00626       
00627     public:
00629     typedef ptrdiff_t difference_type;
00630     typedef xml_node value_type;
00631     typedef xml_node* pointer;
00632     typedef xml_node& reference;
00633       
00634 #ifndef PUGIXML_NO_STL
00635     typedef std::bidirectional_iterator_tag iterator_category;
00636 #endif
00637       
00639     xml_node_iterator();
00640       
00642     xml_node_iterator(const xml_node& node);
00643       
00645     bool operator==(const xml_node_iterator& rhs) const;
00646     bool operator!=(const xml_node_iterator& rhs) const;
00647       
00648     xml_node& operator*();
00649     xml_node* operator->();
00650       
00651     const xml_node_iterator& operator++();
00652     xml_node_iterator operator++(int);
00653       
00654     const xml_node_iterator& operator--();
00655     xml_node_iterator operator--(int);
00656   };
00657     
00658     
00660   class PUGIXML_CLASS xml_attribute_iterator{
00661     friend class xml_node;
00662       
00663     private:
00664     xml_attribute _wrap;
00665     xml_node _parent;
00666       
00667     xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent);
00668       
00669     public:
00671     typedef ptrdiff_t difference_type;
00672     typedef xml_attribute value_type;
00673     typedef xml_attribute* pointer;
00674     typedef xml_attribute& reference;
00675       
00676 #ifndef PUGIXML_NO_STL
00677     typedef std::bidirectional_iterator_tag iterator_category;
00678 #endif
00679       
00681     xml_attribute_iterator();
00682       
00684     xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);
00685       
00687     bool operator==(const xml_attribute_iterator& rhs) const;
00688     bool operator!=(const xml_attribute_iterator& rhs) const;
00689       
00690     xml_attribute& operator*();
00691     xml_attribute* operator->();
00692       
00693     const xml_attribute_iterator& operator++();
00694     xml_attribute_iterator operator++(int);
00695       
00696     const xml_attribute_iterator& operator--();
00697     xml_attribute_iterator operator--(int);
00698   };
00699 
00700     
00702   class PUGIXML_CLASS xml_tree_walker{
00703     friend class xml_node;
00704       
00705     private:
00706     int _depth;
00707       
00708     protected:
00710     int depth() const;
00711       
00712     public:
00713     xml_tree_walker();
00714     virtual ~xml_tree_walker();
00715       
00717     virtual bool begin(xml_node& node);
00718       
00720     virtual bool for_each(xml_node& node) = 0;
00721       
00723     virtual bool end(xml_node& node);
00724   };
00725 
00726 
00728   enum xml_parse_status{
00729     status_ok = 0,              
00730       
00731     status_file_not_found,      
00732     status_io_error,            
00733     status_out_of_memory,       
00734     status_internal_error,      
00735       
00736     status_unrecognized_tag,    
00737       
00738     status_bad_pi,              
00739     status_bad_comment,         
00740     status_bad_cdata,           
00741     status_bad_doctype,         
00742     status_bad_pcdata,          
00743     status_bad_start_element,   
00744     status_bad_attribute,       
00745     status_bad_end_element,     
00746     status_end_element_mismatch 
00747   };
00748     
00749     
00751   struct PUGIXML_CLASS xml_parse_result{
00753     xml_parse_status status;
00754       
00756     ptrdiff_t offset;
00757       
00759     xml_encoding encoding;
00760       
00762     xml_parse_result();
00763       
00765     operator bool() const;
00766       
00768     const char* description() const;
00769   };
00770     
00771 
00772     
00774   class PUGIXML_CLASS xml_document: public xml_node{
00775     private:
00776     char_t* _buffer;
00777       
00778     char _memory[192];
00779       
00781     xml_document(const xml_document&);
00782     const xml_document& operator=(const xml_document&);
00783       
00784     void create();
00785     void destroy();
00786       
00787     xml_parse_result load_buffer_impl(void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own);
00788       
00789     public:
00791     xml_document();
00792       
00794     ~xml_document();
00795       
00797     void reset();
00798       
00800     void reset(const xml_document& proto);
00801       
00802 #ifndef PUGIXML_NO_STL
00803 
00804     xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream, 
00805                           unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00806     xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream, 
00807                           unsigned int options = parse_default);
00808       
00810     xml_parse_result loadNext(std::basic_istream<char, std::char_traits<char> >& stream, 
00811                               unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00812 #endif
00813       
00815     xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
00816       
00818     xml_parse_result load_file(const char* path, unsigned int options = parse_default, 
00819                                xml_encoding encoding = encoding_auto);
00820     xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, 
00821                                xml_encoding encoding = encoding_auto);
00822       
00824     xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, 
00825                                  xml_encoding encoding = encoding_auto);
00826       
00828 
00830     xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, 
00831                                          xml_encoding encoding = encoding_auto);
00832       
00834 
00836     xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, 
00837                                              xml_encoding encoding = encoding_auto);
00838       
00840     void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), 
00841               unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
00842       
00843 #ifndef PUGIXML_NO_STL
00844 
00845     void save(std::basic_ostream<char, std::char_traits<char> >& stream, 
00846               const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, 
00847               xml_encoding encoding = encoding_auto) const;
00848     void save(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream, 
00849               const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const;
00850 #endif
00851       
00853     bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), 
00854                    unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
00855     bool save_file(const wchar_t* path, const char_t* indent = PUGIXML_TEXT("\t"), 
00856                    unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
00857       
00859     xml_node document_element() const;
00860   };
00861     
00862     
00863 #ifndef PUGIXML_NO_XPATH
00864 
00865   enum xpath_value_type{
00866     xpath_type_none,      
00867     xpath_type_node_set,  
00868     xpath_type_number,    
00869     xpath_type_string,    
00870     xpath_type_boolean    
00871   };
00872     
00873     
00875   struct PUGIXML_CLASS xpath_parse_result{
00877     const char* error;
00878       
00880     ptrdiff_t offset;
00881       
00883     xpath_parse_result();
00884       
00886     operator bool() const;
00887       
00889     const char* description() const;
00890   };
00891     
00892     
00894   class PUGIXML_CLASS xpath_variable{
00895     friend class xpath_variable_set;
00896       
00897     protected:
00898     xpath_value_type _type;
00899     xpath_variable* _next;
00900       
00901     xpath_variable();
00902       
00904     xpath_variable(const xpath_variable&);
00905     xpath_variable& operator=(const xpath_variable&);
00906       
00907     public:
00909     const char_t* name() const;
00910       
00912     xpath_value_type type() const;
00913       
00915     bool get_boolean() const;
00916     double get_number() const;
00917     const char_t* get_string() const;
00918     const xpath_node_set& get_node_set() const;
00919       
00921     bool set(bool value);
00922     bool set(double value);
00923     bool set(const char_t* value);
00924     bool set(const xpath_node_set& value);
00925   };
00926 
00927     
00929   class PUGIXML_CLASS xpath_variable_set{
00930     private:
00931     xpath_variable* _data[64];
00932       
00934     xpath_variable_set(const xpath_variable_set&);
00935     xpath_variable_set& operator=(const xpath_variable_set&);
00936       
00937     xpath_variable* find(const char_t* name) const;
00938       
00939     public:
00941     xpath_variable_set();
00942     ~xpath_variable_set();
00943       
00945     xpath_variable* add(const char_t* name, xpath_value_type type);
00946       
00948     bool set(const char_t* name, bool value);
00949     bool set(const char_t* name, double value);
00950     bool set(const char_t* name, const char_t* value);
00951     bool set(const char_t* name, const xpath_node_set& value);
00952       
00954     xpath_variable* get(const char_t* name);
00955     const xpath_variable* get(const char_t* name) const;
00956   };
00957     
00958     
00960   class PUGIXML_CLASS xpath_query{
00961     private:
00962     void* _impl;
00963     xpath_parse_result _result;
00964       
00965     typedef void* xpath_query::*unspecified_bool_type;
00966       
00968     xpath_query(const xpath_query&);
00969     xpath_query& operator=(const xpath_query&);
00970       
00971     public:
00973 
00974     explicit xpath_query(const char_t* query, xpath_variable_set* variables = 0);
00975       
00977     ~xpath_query();
00978       
00980     xpath_value_type return_type() const;
00981       
00983 
00984     bool evaluate_boolean(const xpath_node& n) const;
00985       
00987 
00988     double evaluate_number(const xpath_node& n) const;
00989       
00990 #ifndef PUGIXML_NO_STL
00991 
00992 
00993     string_t evaluate_string(const xpath_node& n) const;
00994 #endif
00995       
00997 
01000     size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const;
01001       
01003 
01005     xpath_node_set evaluate_node_set(const xpath_node& n) const;
01006       
01008     const xpath_parse_result& result() const;
01009       
01011     operator unspecified_bool_type() const;
01012       
01014     bool operator!() const;
01015   };
01016         
01017 
01018 #ifndef PUGIXML_NO_EXCEPTIONS
01019 
01020   class PUGIXML_CLASS xpath_exception: public std::exception {
01021     private:
01022     xpath_parse_result _result;
01023       
01024     public:
01026     explicit xpath_exception(const xpath_parse_result& result);
01027       
01029     virtual const char* what() const throw();
01030       
01032     const xpath_parse_result& result() const;
01033   };
01034 #endif
01035     
01037   class PUGIXML_CLASS xpath_node{
01038     private:
01039     xml_node _node;
01040     xml_attribute _attribute;
01041       
01042     typedef xml_node xpath_node::*unspecified_bool_type;
01043       
01044     public:
01046     xpath_node();
01047       
01049     xpath_node(const xml_node& node);
01050     xpath_node(const xml_attribute& attribute, const xml_node& parent);
01051       
01053     xml_node node() const;
01054     xml_attribute attribute() const;
01055       
01057     xml_node parent() const;
01058       
01060     operator unspecified_bool_type() const;
01061       
01063     bool operator!() const;
01064       
01066     bool operator==(const xpath_node& n) const;
01067     bool operator!=(const xpath_node& n) const;
01068   };
01069 
01071 #ifdef __BORLANDC__
01072 
01073   bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);
01074   bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);
01075 #endif
01076 
01078 
01079   class PUGIXML_CLASS xpath_node_set{
01080     public:
01082     enum type_t{
01083       type_unsorted,                    
01084       type_sorted,                      
01085       type_sorted_reverse               
01086     };
01087       
01089     typedef const xpath_node* const_iterator;
01090       
01092     xpath_node_set();
01093       
01095 
01096     xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted);
01097       
01099     ~xpath_node_set();
01100       
01102     xpath_node_set(const xpath_node_set& ns);
01103     xpath_node_set& operator=(const xpath_node_set& ns);
01104       
01106     type_t type() const;
01107       
01109     size_t size() const;
01110       
01112     const xpath_node& operator[](size_t index) const;
01113       
01115     const_iterator begin() const;
01116     const_iterator end() const;
01117       
01119     void sort(bool reverse = false);
01120       
01122     xpath_node first() const;
01123       
01125     bool empty() const;
01126       
01127     private:
01128     type_t _type;
01129       
01130     xpath_node _storage;
01131       
01132     xpath_node* _begin;
01133     xpath_node* _end;
01134       
01135     void _assign(const_iterator begin, const_iterator end);
01136   };
01137 #endif
01138     
01139 #ifndef PUGIXML_NO_STL
01140 
01141   std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);
01142   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);
01143     
01145   std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
01146   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);
01147 #endif
01148     
01150   typedef void* (*allocation_function)(size_t size);
01151     
01153   typedef void (*deallocation_function)(void* ptr);
01154     
01156   void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);
01157     
01159   allocation_function PUGIXML_FUNCTION get_memory_allocation_function();
01160   deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function();
01161 }
01162 
01163 #if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
01164 namespace std
01165 {
01167   std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_node_iterator&);
01168   std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_attribute_iterator&);
01169 }
01170 #endif
01171 
01172 #if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
01173 namespace std
01174 {
01176   std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_node_iterator&);
01177   std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_attribute_iterator&);
01178 }
01179 #endif
01180 
01183 /*
01184  * Copyright (c) 2006-2010 Arseny Kapoulkine
01185  *
01186  * Permission is hereby granted, free of charge, to any person
01187  * obtaining a copy of this software and associated documentation
01188  * files (the "Software"), to deal in the Software without
01189  * restriction, including without limitation the rights to use,
01190  * copy, modify, merge, publish, distribute, sublicense, and/or sell
01191  * copies of the Software, and to permit persons to whom the
01192  * Software is furnished to do so, subject to the following
01193  * conditions:
01194  *
01195  * The above copyright notice and this permission notice shall be
01196  * included in all copies or substantial portions of the Software.
01197  * 
01198  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
01199  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
01200  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
01201  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
01202  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
01203  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
01204  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
01205  * OTHER DEALINGS IN THE SOFTWARE.
01206  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines