tinyxml.h

Go to the documentation of this file.
00001 
00002 /*
00003 www.sourceforge.net/projects/tinyxml
00004 Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
00005 
00006 This software is provided 'as-is', without any express or implied
00007 warranty. In no event will the authors be held liable for any
00008 damages arising from the use of this software.
00009 
00010 Permission is granted to anyone to use this software for any
00011 purpose, including commercial applications, and to alter it and
00012 redistribute it freely, subject to the following restrictions:
00013 
00014 1. The origin of this software must not be misrepresented; you must
00015 not claim that you wrote the original software. If you use this
00016 software in a product, an acknowledgment in the product documentation
00017 would be appreciated but is not required.
00018 
00019 2. Altered source versions must be plainly marked as such, and
00020 must not be misrepresented as being the original software.
00021 
00022 3. This notice may not be removed or altered from any source
00023 distribution.
00024 */
00025 
00026 
00027 #ifndef TINYXML_INCLUDED
00028 #define TINYXML_INCLUDED
00029 
00030 #ifdef _MSC_VER
00031 #pragma warning( disable : 4530 )
00032 #pragma warning( disable : 4786 )
00033 #endif
00034 
00035 #include <ctype.h>
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <assert.h>
00040 
00041 // Help out windows:
00042 #if defined( _DEBUG ) && !defined( DEBUG )
00043 #define DEBUG
00044 #endif
00045 
00046 #if defined( DEBUG ) && defined( _MSC_VER )
00047 #include <windows.h>
00048 #define TIXML_LOG OutputDebugString
00049 #else
00050 #define TIXML_LOG printf
00051 #endif
00052 
00053 // Uncomment the following definition for Apple's Project Builder 
00054 #define TIXML_NEED_STREAM
00055 
00056 #define TIXML_USE_STL
00057 
00058 #ifdef TIXML_USE_STL
00059 #include <string>
00060 #ifdef TIXML_NEED_STREAM
00061 #include <iostream>
00062 #endif
00063 #define TIXML_STRING     std::string
00064 #define TIXML_ISTREAM    std::istream
00065 #define TIXML_OSTREAM    std::ostream
00066 #else
00067 #include "tinystr.h"
00068 #define TIXML_STRING     TiXmlString
00069 #define TIXML_OSTREAM    TiXmlOutStream
00070 #endif
00071 
00072 class TiXmlDocument;
00073 class TiXmlElement;
00074 class TiXmlComment;
00075 class TiXmlUnknown;
00076 class TiXmlAttribute;
00077 class TiXmlText;
00078 class TiXmlDeclaration;
00079 
00080 
00103 class TiXmlBase
00104 {
00105     friend class TiXmlNode;
00106     friend class TiXmlElement;
00107     friend class TiXmlDocument;
00108 
00109   public:
00110       TiXmlBase()
00111     {
00112     }
00113     virtual ~ TiXmlBase()
00114     {
00115     }
00116 
00122     virtual void Print(FILE * cfile, int depth) const = 0;
00123 
00130     static void SetCondenseWhiteSpace(bool condense)
00131     {
00132         condenseWhiteSpace = condense;
00133     }
00134 
00136     static bool IsWhiteSpaceCondensed()
00137     {
00138         return condenseWhiteSpace;
00139     }
00140 
00141   protected:
00142     // See STL_STRING_BUG
00143     // Utility class to overcome a bug.
00144     class StringToBuffer
00145     {
00146       public:
00147         StringToBuffer(const TIXML_STRING & str);
00148         ~StringToBuffer();
00149         char *buffer;
00150     };
00151 
00152     static const char *SkipWhiteSpace(const char *);
00153     inline static bool IsWhiteSpace(int c)
00154     {
00155         return (isspace(c) || c == '\n' || c == '\r');
00156     }
00157 
00158     virtual void StreamOut(TIXML_OSTREAM *) const = 0;
00159 
00160 #ifdef TIXML_USE_STL
00161     static bool StreamWhiteSpace(TIXML_ISTREAM * in, TIXML_STRING * tag);
00162     static bool StreamTo(TIXML_ISTREAM * in, int character, TIXML_STRING * tag);
00163 #endif
00164 
00165     /*      Reads an XML name into the string provided. Returns
00166        a pointer just past the last character of the name,
00167        or 0 if the function has an error.
00168      */
00169     static const char *ReadName(const char *p, TIXML_STRING * name);
00170 
00171     /*      Reads text. Returns a pointer past the given end tag.
00172        Wickedly complex options, but it keeps the (sensitive) code in one place.
00173      */
00174     static const char *ReadText(const char *in, // where to start
00175                                 TIXML_STRING * text,    // the string read
00176                                 bool ignoreWhiteSpace,  // whether to keep the white space
00177                                 const char *endTag,     // what ends this text
00178                                 bool ignoreCase);       // whether to ignore case in the end tag
00179     virtual const char *Parse(const char *p) = 0;
00180 
00181     // If an entity has been found, transform it into a character.
00182     static const char *GetEntity(const char *in, char *value);
00183 
00184     // Get a character, while interpreting entities.
00185     inline static const char *GetChar(const char *p, char *value)
00186     {
00187         assert(p);
00188         if(*p == '&')
00189         {
00190             return GetEntity(p, value);
00191         }
00192         else
00193         {
00194             *value = *p;
00195             return p + 1;
00196         }
00197     }
00198 
00199     // Puts a string to a stream, expanding entities as it goes.
00200     // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
00201     static void PutString(const TIXML_STRING & str, TIXML_OSTREAM * out);
00202 
00203     static void PutString(const TIXML_STRING & str, TIXML_STRING * out);
00204 
00205     // Return true if the next characters in the stream are any of the endTag sequences.
00206     bool static StringEqual(const char *p, const char *endTag, bool ignoreCase);
00207 
00208 
00209     enum
00210     {
00211         TIXML_NO_ERROR = 0,
00212         TIXML_ERROR,
00213         TIXML_ERROR_OPENING_FILE,
00214         TIXML_ERROR_OUT_OF_MEMORY,
00215         TIXML_ERROR_PARSING_ELEMENT,
00216         TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00217         TIXML_ERROR_READING_ELEMENT_VALUE,
00218         TIXML_ERROR_READING_ATTRIBUTES,
00219         TIXML_ERROR_PARSING_EMPTY,
00220         TIXML_ERROR_READING_END_TAG,
00221         TIXML_ERROR_PARSING_UNKNOWN,
00222         TIXML_ERROR_PARSING_COMMENT,
00223         TIXML_ERROR_PARSING_DECLARATION,
00224         TIXML_ERROR_DOCUMENT_EMPTY,
00225 
00226         TIXML_ERROR_STRING_COUNT
00227     };
00228     static const char *errorString[TIXML_ERROR_STRING_COUNT];
00229 
00230   private:
00231     struct Entity
00232     {
00233         const char *str;
00234         unsigned int strLength;
00235         char chr;
00236     };
00237     enum
00238     {
00239         NUM_ENTITY = 5,
00240         MAX_ENTITY_LENGTH = 6
00241     };
00242     static Entity entity[NUM_ENTITY];
00243     static bool condenseWhiteSpace;
00244 };
00245 
00246 
00253 class TiXmlNode:public TiXmlBase
00254 {
00255     friend class TiXmlDocument;
00256     friend class TiXmlElement;
00257 
00258   public:
00259 #ifdef TIXML_USE_STL
00260 
00264       friend std::istream & operator >>(std::istream & in, TiXmlNode & base);
00265 
00281     friend std::ostream & operator<<(std::ostream & out,
00282                                      const TiXmlNode & base);
00283 
00284 #else
00285     // Used internally, not part of the public API.
00286       friend TIXML_OSTREAM & operator<<(TIXML_OSTREAM & out,
00287                                         const TiXmlNode & base);
00288 #endif
00289 
00293     enum NodeType
00294     {
00295         DOCUMENT,
00296         ELEMENT,
00297         COMMENT,
00298         UNKNOWN,
00299         TEXT,
00300         DECLARATION,
00301         TYPECOUNT
00302     };
00303 
00304       virtual ~ TiXmlNode();
00305 
00318     const char *Value() const
00319     {
00320         return value.c_str();
00321     }
00322 
00332     void SetValue(const char *_value)
00333     {
00334         value = _value;
00335     }
00336 
00337 #ifdef TIXML_USE_STL
00339     void SetValue(const std::string & value)
00340     {
00341         StringToBuffer buf(value);
00342 
00343         SetValue(buf.buffer ? buf.buffer : "");
00344     }
00345 #endif
00346 
00348     void Clear();
00349 
00351     TiXmlNode *Parent() const
00352     {
00353         return parent;
00354     }
00355 
00356     TiXmlNode *FirstChild() const
00357     {
00358         return firstChild;
00359     }                           
00360     TiXmlNode *FirstChild(const char *value) const;     
00361 
00362     TiXmlNode *LastChild() const
00363     {
00364         return lastChild;
00365     }                           
00366     TiXmlNode *LastChild(const char *value) const;      
00367 
00368 #ifdef TIXML_USE_STL
00369     TiXmlNode *FirstChild(const std::string & value) const
00370     {
00371         return FirstChild(value.c_str());
00372     }                           
00373     TiXmlNode *LastChild(const std::string & value) const
00374     {
00375         return LastChild(value.c_str());
00376     }                           
00377 #endif
00378 
00395     TiXmlNode *IterateChildren(TiXmlNode * previous) const;
00396 
00398     TiXmlNode *IterateChildren(const char *value, TiXmlNode * previous) const;
00399 
00400 #ifdef TIXML_USE_STL
00401     TiXmlNode *IterateChildren(const std::string & value, TiXmlNode * previous) const
00402     {
00403         return IterateChildren(value.c_str(), previous);
00404     }                           
00405 #endif
00406 
00410     TiXmlNode *InsertEndChild(const TiXmlNode & addThis);
00411 
00412 
00422     TiXmlNode *LinkEndChild(TiXmlNode * addThis);
00423 
00427     TiXmlNode *InsertBeforeChild(TiXmlNode * beforeThis,
00428                                  const TiXmlNode & addThis);
00429 
00433     TiXmlNode *InsertAfterChild(TiXmlNode * afterThis,
00434                                 const TiXmlNode & addThis);
00435 
00439     TiXmlNode *ReplaceChild(TiXmlNode * replaceThis,
00440                             const TiXmlNode & withThis);
00441 
00443     bool RemoveChild(TiXmlNode * removeThis);
00444 
00446     TiXmlNode *PreviousSibling() const
00447     {
00448         return prev;
00449     }
00450 
00452     TiXmlNode *PreviousSibling(const char *) const;
00453 
00454 #ifdef TIXML_USE_STL
00455     TiXmlNode *PreviousSibling(const std::string & value) const
00456     {
00457         return PreviousSibling(value.c_str());
00458     }                           
00459     TiXmlNode *NextSibling(const std::string & value) const
00460     {
00461         return NextSibling(value.c_str());
00462     }                           
00463 #endif
00464 
00466     TiXmlNode *NextSibling() const
00467     {
00468         return next;
00469     }
00470 
00472     TiXmlNode *NextSibling(const char *) const;
00473 
00478     TiXmlElement *NextSiblingElement() const;
00479 
00484     TiXmlElement *NextSiblingElement(const char *) const;
00485 
00486 #ifdef TIXML_USE_STL
00487     TiXmlElement *NextSiblingElement(const std::string & value) const
00488     {
00489         return NextSiblingElement(value.c_str());
00490     }                           
00491 #endif
00492 
00494     TiXmlElement *FirstChildElement() const;
00495 
00497     TiXmlElement *FirstChildElement(const char *value) const;
00498 
00499 #ifdef TIXML_USE_STL
00500     TiXmlElement *FirstChildElement(const std::string & value) const
00501     {
00502         return FirstChildElement(value.c_str());
00503     }                           
00504 #endif
00505 
00507     virtual int Type() const
00508     {
00509         return type;
00510     }
00511 
00515     TiXmlDocument *GetDocument() const;
00516 
00518     bool NoChildren() const
00519     {
00520         return !firstChild;
00521     }
00522 
00523     TiXmlDocument *ToDocument() const
00524     {
00525         return (this && type == DOCUMENT) ? (TiXmlDocument *) this : 0;
00526     }                           
00527     TiXmlElement *ToElement() const
00528     {
00529         return (this && type == ELEMENT) ? (TiXmlElement *) this : 0;
00530     }                           
00531     TiXmlComment *ToComment() const
00532     {
00533         return (this && type == COMMENT) ? (TiXmlComment *) this : 0;
00534     }                           
00535     TiXmlUnknown *ToUnknown() const
00536     {
00537         return (this && type == UNKNOWN) ? (TiXmlUnknown *) this : 0;
00538     }                           
00539     TiXmlText *ToText() const
00540     {
00541         return (this && type == TEXT) ? (TiXmlText *) this : 0;
00542     }                           
00543     TiXmlDeclaration *ToDeclaration() const
00544     {
00545         return (this && type == DECLARATION) ? (TiXmlDeclaration *) this : 0;
00546     }                           
00547 
00548     virtual TiXmlNode *Clone() const = 0;
00549 
00550     void SetUserData(void *user)
00551     {
00552         userData = user;
00553     }
00554     void *GetUserData()
00555     {
00556         return userData;
00557     }
00558 
00559   protected:
00560     TiXmlNode(NodeType type);
00561 
00562 #ifdef TIXML_USE_STL
00563     // The real work of the input operator.
00564     virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag) = 0;
00565 #endif
00566 
00567     // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
00568     TiXmlNode *Identify(const char *start);
00569     void CopyToClone(TiXmlNode * target) const
00570     {
00571         target->SetValue(value.c_str());
00572         target->userData = userData;
00573     }
00574 
00575     // Internal Value function returning a TIXML_STRING
00576     TIXML_STRING SValue() const
00577     {
00578         return value;
00579     }
00580 
00581     TiXmlNode *parent;
00582     NodeType type;
00583 
00584     TiXmlNode *firstChild;
00585     TiXmlNode *lastChild;
00586 
00587     TIXML_STRING value;
00588 
00589     TiXmlNode *prev;
00590     TiXmlNode *next;
00591     void *userData;
00592 };
00593 
00594 
00604 class TiXmlAttribute:public TiXmlBase
00605 {
00606     friend class TiXmlAttributeSet;
00607 
00608   public:
00610       TiXmlAttribute():prev(0), next(0)
00611     {
00612     }
00613 
00614 #ifdef TIXML_USE_STL
00616     TiXmlAttribute(const std::string & _name, const std::string & _value)
00617     {
00618         name = _name;
00619         value = _value;
00620     }
00621 #endif
00622 
00624     TiXmlAttribute(const char *_name, const char *_value):name(_name),
00625         value(_value), prev(0), next(0)
00626     {
00627     }
00628     const char *Name() const
00629     {
00630         return name.c_str();
00631     }                           
00632     const char *Value() const
00633     {
00634         return value.c_str();
00635     }                           
00636     const int IntValue() const; 
00637     const double DoubleValue() const;   
00638 
00639     void SetName(const char *_name)
00640     {
00641         name = _name;
00642     }                           
00643     void SetValue(const char *_value)
00644     {
00645         value = _value;
00646     }                           
00647 
00648     void SetIntValue(int value);        
00649     void SetDoubleValue(double value);  
00650 
00651 #ifdef TIXML_USE_STL
00653     void SetName(const std::string & _name)
00654     {
00655         StringToBuffer buf(_name);
00656 
00657         SetName(buf.buffer ? buf.buffer : "error");
00658     }
00660     void SetValue(const std::string & _value)
00661     {
00662         StringToBuffer buf(_value);
00663 
00664         SetValue(buf.buffer ? buf.buffer : "error");
00665     }
00666 #endif
00667 
00669     TiXmlAttribute *Next() const;
00670 
00672     TiXmlAttribute *Previous() const;
00673 
00674     bool operator==(const TiXmlAttribute & rhs) const
00675     {
00676         return rhs.name == name;
00677     }
00678     bool operator<(const TiXmlAttribute & rhs) const
00679     {
00680         return name < rhs.name;
00681     }
00682     bool operator>(const TiXmlAttribute & rhs) const
00683     {
00684         return name > rhs.name;
00685     }
00686 
00687     /*      [internal use]
00688        Attribtue parsing starts: first letter of the name
00689        returns: the next char after the value end quote
00690      */
00691     virtual const char *Parse(const char *p);
00692 
00693     // [internal use]
00694     virtual void Print(FILE * cfile, int depth) const;
00695 
00696     virtual void StreamOut(TIXML_OSTREAM * out) const;
00697 
00698     // [internal use]
00699     // Set the document pointer so the attribute can report errors.
00700     void SetDocument(TiXmlDocument * doc)
00701     {
00702         document = doc;
00703     }
00704 
00705   private:
00706     TiXmlDocument * document;   // A pointer back to a document, for error reporting.
00707     TIXML_STRING name;
00708     TIXML_STRING value;
00709     TiXmlAttribute *prev;
00710     TiXmlAttribute *next;
00711 };
00712 
00713 
00714 /*   A class used to manage a group of attributes.
00715      It is only used internally, both by the ELEMENT and the DECLARATION.
00716      
00717      The set can be changed transparent to the Element and Declaration
00718      classes that use it, but NOT transparent to the Attribute
00719      which has to implement a next() and previous() method. Which makes
00720      it a bit problematic and prevents the use of STL.
00721 
00722      This version is implemented with circular lists because:
00723           - I like circular lists
00724           - it demonstrates some independence from the (typical) doubly linked list.
00725 */
00726 class TiXmlAttributeSet
00727 {
00728   public:
00729     TiXmlAttributeSet();
00730     ~TiXmlAttributeSet();
00731 
00732     void Add(TiXmlAttribute * attribute);
00733     void Remove(TiXmlAttribute * attribute);
00734 
00735     TiXmlAttribute *First() const
00736     {
00737         return (sentinel.next == &sentinel) ? 0 : sentinel.next;
00738     }
00739     TiXmlAttribute *Last() const
00740     {
00741         return (sentinel.prev == &sentinel) ? 0 : sentinel.prev;
00742     }
00743     TiXmlAttribute *Find(const char *name) const;
00744 
00745   private:
00746       TiXmlAttribute sentinel;
00747 };
00748 
00749 
00754 class TiXmlElement:public TiXmlNode
00755 {
00756   public:
00758     TiXmlElement(const char *in_value);
00759 
00760 #ifdef TIXML_USE_STL
00762       TiXmlElement(const std::string & _value):TiXmlNode(TiXmlNode::ELEMENT)
00763     {
00764         firstChild = lastChild = 0;
00765         value = _value;
00766     }
00767 #endif
00768 
00769     virtual ~ TiXmlElement();
00770 
00774     const char *Attribute(const char *name) const;
00775 
00782     const char *Attribute(const char *name, int *i) const;
00783 
00787     void SetAttribute(const char *name, const char *value);
00788 
00789 #ifdef TIXML_USE_STL
00790     const char *Attribute(const std::string & name) const
00791     {
00792         return Attribute(name.c_str());
00793     }
00794     const char *Attribute(const std::string & name, int *i) const
00795     {
00796         return Attribute(name.c_str(), i);
00797     }
00798 
00800     void SetAttribute(const std::string & name, const std::string & value)
00801     {
00802         StringToBuffer n(name);
00803         StringToBuffer v(value);
00804 
00805         if(n.buffer && v.buffer)
00806             SetAttribute(n.buffer, v.buffer);
00807     }
00809     void SetAttribute(const std::string & name, int value)
00810     {
00811         StringToBuffer n(name);
00812 
00813         if(n.buffer)
00814             SetAttribute(n.buffer, value);
00815     }
00816 #endif
00817 
00821     void SetAttribute(const char *name, int value);
00822 
00825     void RemoveAttribute(const char *name);
00826 
00827 #ifdef TIXML_USE_STL
00828     void RemoveAttribute(const std::string & name)
00829     {
00830         RemoveAttribute(name.c_str());
00831     }                           
00832 #endif
00833 
00834     TiXmlAttribute *FirstAttribute() const
00835     {
00836         return attributeSet.First();
00837     }                           
00838     TiXmlAttribute *LastAttribute() const
00839     {
00840         return attributeSet.Last();
00841     }                           
00842 
00843     // [internal use] Creates a new Element and returs it.
00844     virtual TiXmlNode *Clone() const;
00845 
00846     // [internal use]
00847 
00848     virtual void Print(FILE * cfile, int depth) const;
00849 
00850   protected:
00851 
00852     // Used to be public [internal use]
00853 #ifdef TIXML_USE_STL
00854     virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
00855 #endif
00856     virtual void StreamOut(TIXML_OSTREAM * out) const;
00857 
00858     /*      [internal use]
00859        Attribtue parsing starts: next char past '<'
00860        returns: next char past '>'
00861      */
00862     virtual const char *Parse(const char *p);
00863 
00864     /*      [internal use]
00865        Reads the "value" of the element -- another element, or text.
00866        This should terminate with the current end tag.
00867      */
00868     const char *ReadValue(const char *in);
00869 
00870   private:
00871     TiXmlAttributeSet attributeSet;
00872 };
00873 
00874 
00877 class TiXmlComment:public TiXmlNode
00878 {
00879   public:
00881     TiXmlComment():TiXmlNode(TiXmlNode::COMMENT)
00882     {
00883     }
00884     virtual ~ TiXmlComment()
00885     {
00886     }
00887 
00888     // [internal use] Creates a new Element and returs it.
00889     virtual TiXmlNode *Clone() const;
00890 
00891     // [internal use]
00892     virtual void Print(FILE * cfile, int depth) const;
00893 
00894   protected:
00895     // used to be public
00896 #ifdef TIXML_USE_STL
00897     virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
00898 #endif
00899     virtual void StreamOut(TIXML_OSTREAM * out) const;
00900 
00901     /*      [internal use]
00902        Attribtue parsing starts: at the ! of the !--
00903        returns: next char past '>'
00904      */
00905     virtual const char *Parse(const char *p);
00906 };
00907 
00908 
00911 class TiXmlText:public TiXmlNode
00912 {
00913     friend class TiXmlElement;
00914   public:
00916       TiXmlText(const char *initValue):TiXmlNode(TiXmlNode::TEXT)
00917     {
00918         SetValue(initValue);
00919     }
00920     virtual ~ TiXmlText()
00921     {
00922     }
00923 
00924 #ifdef TIXML_USE_STL
00926     TiXmlText(const std::string & initValue):TiXmlNode(TiXmlNode::TEXT)
00927     {
00928         SetValue(initValue);
00929     }
00930 #endif
00931 
00932     // [internal use]
00933     virtual void Print(FILE * cfile, int depth) const;
00934 
00935   protected:
00936     // [internal use] Creates a new Element and returns it.
00937     virtual TiXmlNode * Clone()const;
00938     virtual void StreamOut(TIXML_OSTREAM * out) const;
00939 
00940     // [internal use]
00941     bool Blank() const;         // returns true if all white space and new lines
00942 
00943     /*      [internal use]
00944        Attribtue parsing starts: First char of the text
00945        returns: next char past '>'
00946      */
00947     virtual const char *Parse(const char *p);
00948 
00949     // [internal use]
00950 #ifdef TIXML_USE_STL
00951     virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
00952 #endif
00953 };
00954 
00955 
00969 class TiXmlDeclaration:public TiXmlNode
00970 {
00971   public:
00973     TiXmlDeclaration():TiXmlNode(TiXmlNode::DECLARATION)
00974     {
00975     }
00976 
00977 #ifdef TIXML_USE_STL
00979     TiXmlDeclaration(const std::string & _version,
00980                      const std::string & _encoding,
00981                      const std::string & _standalone):TiXmlNode(TiXmlNode::
00982                                                                 DECLARATION)
00983     {
00984         version = _version;
00985         encoding = _encoding;
00986         standalone = _standalone;
00987     }
00988 #endif
00989 
00991     TiXmlDeclaration(const char *_version,
00992                const char *_encoding,
00993                const char *_standalone);
00994 
00995     virtual ~ TiXmlDeclaration()
00996     {
00997     }
00998 
01000     const char *Version() const
01001     {
01002         return version.c_str();
01003     }
01005     const char *Encoding() const
01006     {
01007         return encoding.c_str();
01008     }
01010     const char *Standalone() const
01011     {
01012         return standalone.c_str();
01013     }
01014 
01015     // [internal use] Creates a new Element and returs it.
01016     virtual TiXmlNode *Clone() const;
01017 
01018     // [internal use]
01019     virtual void Print(FILE * cfile, int depth) const;
01020 
01021   protected:
01022     // used to be public
01023 #ifdef TIXML_USE_STL
01024     virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
01025 #endif
01026     virtual void StreamOut(TIXML_OSTREAM * out) const;
01027 
01028     //      [internal use]
01029     //      Attribtue parsing starts: next char past '<'
01030     //                                       returns: next char past '>'
01031 
01032     virtual const char *Parse(const char *p);
01033 
01034   private:
01035     TIXML_STRING version;
01036     TIXML_STRING encoding;
01037     TIXML_STRING standalone;
01038 };
01039 
01040 
01046 class TiXmlUnknown:public TiXmlNode
01047 {
01048   public:
01049     TiXmlUnknown():TiXmlNode(TiXmlNode::UNKNOWN)
01050     {
01051     }
01052     virtual ~ TiXmlUnknown()
01053     {
01054     }
01055 
01056     // [internal use]
01057     virtual TiXmlNode *Clone() const;
01058 
01059     // [internal use]
01060     virtual void Print(FILE * cfile, int depth) const;
01061 
01062   protected:
01063     // used to be public
01064 #ifdef TIXML_USE_STL
01065     virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
01066 #endif
01067     virtual void StreamOut(TIXML_OSTREAM * out) const;
01068 
01069     /*      [internal use]
01070        Attribute parsing starts: First char of the text
01071        returns: next char past '>'
01072      */
01073     virtual const char *Parse(const char *p);
01074 };
01075 
01076 
01081 class TiXmlDocument:public TiXmlNode
01082 {
01083   public:
01085     TiXmlDocument();
01087     TiXmlDocument(const char *documentName);
01088 
01089 #ifdef TIXML_USE_STL
01091       TiXmlDocument(const std::string & documentName):TiXmlNode(TiXmlNode::
01092                                                                 DOCUMENT)
01093     {
01094         value = documentName;
01095         error = false;
01096     }
01097 #endif
01098 
01099     virtual ~ TiXmlDocument()
01100     {
01101     }
01102 
01107     bool LoadFile();
01108 
01110     bool SaveFile() const;
01111 
01113     bool LoadFile(const char *filename);
01114 
01116     bool SaveFile(const char *filename) const;
01117 
01118 #ifdef TIXML_USE_STL
01119     bool LoadFile(const std::string & filename) 
01120     {
01121         StringToBuffer f(filename);
01122 
01123         return (f.buffer && LoadFile(f.buffer));
01124     }
01125     bool SaveFile(const std::string & filename) const   
01126     {
01127         StringToBuffer f(filename);
01128           return (f.buffer && SaveFile(f.buffer));
01129     }
01130 #endif
01131 
01133     virtual const char *Parse(const char *p);
01134 
01139     TiXmlElement *RootElement() const
01140     {
01141         return FirstChildElement();
01142     }
01143 
01145     bool Error() const
01146     {
01147         return error;
01148     }
01149 
01151     const char *ErrorDesc() const
01152     {
01153         return errorDesc.c_str();
01154     }
01155 
01159     const int ErrorId() const
01160     {
01161         return errorId;
01162     }
01163 
01165     void ClearError()
01166     {
01167         error = false;
01168         errorId = 0;
01169         errorDesc = "";
01170     }
01171 
01173     void Print() const
01174     {
01175         Print(stdout, 0);
01176     }
01177 
01178     // [internal use]
01179     virtual void Print(FILE * cfile, int depth = 0) const;
01180 
01181     // [internal use]
01182     void SetError(int err)
01183     {
01184         assert(err > 0 && err < TIXML_ERROR_STRING_COUNT);
01185         error = true;
01186         errorId = err;
01187         errorDesc = errorString[errorId];
01188     }
01189 
01190   protected:
01191     virtual void StreamOut(TIXML_OSTREAM * out) const;
01192 
01193     // [internal use]
01194     virtual TiXmlNode *Clone() const;
01195 
01196 #ifdef TIXML_USE_STL
01197     virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
01198 #endif
01199 
01200   private:
01201     bool error;
01202     int errorId;
01203     TIXML_STRING errorDesc;
01204 };
01205 
01206 #endif

Generated on Sun Mar 11 15:33:23 2007 for MetalWarriors by  doxygen 1.4.7