35 #ifndef TINYXML_INCLUDED 36 #define TINYXML_INCLUDED 39 #pragma warning( push ) 40 #pragma warning( disable : 4530 ) 41 #pragma warning( disable : 4786 ) 51 #if defined( _DEBUG ) && !defined( DEBUG ) 59 #define TIXML_STRING std::string 62 #define TIXML_STRING TiXmlString 72 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) 74 #define TIXML_SNPRINTF _snprintf_s 75 #define TIXML_SSCANF sscanf_s 76 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) 79 #define TIXML_SNPRINTF _snprintf 80 #define TIXML_SSCANF sscanf 81 #elif defined(__GNUC__) && (__GNUC__ >= 3 ) 84 #define TIXML_SNPRINTF snprintf 85 #define TIXML_SSCANF sscanf 87 #define TIXML_SNPRINTF snprintf 88 #define TIXML_SSCANF sscanf 222 virtual void Print( FILE* cfile,
int depth )
const = 0;
264 virtual const char*
Parse(
const char* p,
301 return ( isspace( (
unsigned char) c ) || c ==
'\n' || c ==
'\r' );
311 static bool StreamWhiteSpace( std::istream * in,
TIXML_STRING * tag );
312 static bool StreamTo( std::istream * in,
int character,
TIXML_STRING * tag );
324 static const char*
ReadText(
const char* in,
326 bool ignoreWhiteSpace,
341 *length = utf8ByteTable[ *((
const unsigned char*)p) ];
342 assert( *length >= 0 && *length < 5 );
352 return GetEntity( p, _value, length, encoding );
360 for(
int i=0; p[
i] &&
i<*length; ++
i ) {
363 return p + (*length);
395 if ( v < 128 )
return tolower( v );
412 unsigned int strLength;
418 MAX_ENTITY_LENGTH = 6
421 static Entity entity[ NUM_ENTITY ];
422 static bool condenseWhiteSpace;
443 friend std::istream& operator >> (std::istream& in,
TiXmlNode& base);
503 const std::string& ValueStr()
const {
return value; }
520 void SetValue(
const std::string& _value ) {
value = _value; }
538 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->FirstChild( _value ));
545 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->LastChild( _value ));
573 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( previous ) );
579 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( _value, previous ) );
629 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->PreviousSibling( _prev ) );
646 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSibling( _next ) );
664 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSiblingElement( _next ) );
681 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->FirstChildElement( _value ) );
758 virtual void StreamIn( std::istream* in,
TIXML_STRING* tag ) = 0;
801 TiXmlAttribute(
const std::string& _name,
const std::string& _value )
820 const char*
Name()
const {
return name.c_str(); }
821 const char*
Value()
const {
return value.c_str(); }
823 const std::string& ValueStr()
const {
return value; }
825 int IntValue()
const;
826 double DoubleValue()
const;
840 int QueryIntValue(
int* _value )
const;
842 int QueryDoubleValue(
double* _value )
const;
844 void SetName(
const char* _name ) { name = _name; }
845 void SetValue(
const char* _value ) { value = _value; }
847 void SetIntValue(
int _value );
848 void SetDoubleValue(
double _value );
851 void SetName(
const std::string& _name ) { name = _name; }
854 void SetValue(
const std::string& _value ) { value = _value; }
879 virtual void Print( FILE* cfile,
int depth )
const {
880 Print( cfile, depth, 0 );
882 void Print( FILE* cfile,
int depth,
TIXML_STRING* str )
const;
929 # ifdef TIXML_USE_STL 969 const char* Attribute(
const char* name )
const;
977 const char* Attribute(
const char* name,
int*
i )
const;
985 const char* Attribute(
const char* name,
double* d )
const;
994 int QueryIntAttribute(
const char* name,
int* _value )
const;
996 int QueryUnsignedAttribute(
const char* name,
unsigned* _value )
const;
1001 int QueryBoolAttribute(
const char* name,
bool* _value )
const;
1003 int QueryDoubleAttribute(
const char* name,
double* _value )
const;
1007 int result = QueryDoubleAttribute( name, &d );
1014 #ifdef TIXML_USE_STL 1015 int QueryStringAttribute(
const char* name, std::string* _value )
const {
1017 const char* cstr = Attribute( name );
1019 *_value = std::string( cstr );
1033 template<
typename T >
int QueryValueAttribute(
const std::string& name, T* outValue )
const 1039 std::stringstream sstream( node->ValueStr() );
1040 sstream >> *outValue;
1041 if ( !sstream.fail() )
1046 int QueryValueAttribute(
const std::string& name, std::string* outValue )
const 1051 *outValue = node->ValueStr();
1059 void SetAttribute(
const char* name,
const char * _value );
1061 #ifdef TIXML_USE_STL 1062 const std::string* Attribute(
const std::string& name )
const;
1063 const std::string* Attribute(
const std::string& name,
int* i )
const;
1064 const std::string* Attribute(
const std::string& name,
double* d )
const;
1065 int QueryIntAttribute(
const std::string& name,
int* _value )
const;
1066 int QueryDoubleAttribute(
const std::string& name,
double* _value )
const;
1069 void SetAttribute(
const std::string& name,
const std::string& _value );
1071 void SetAttribute(
const std::string& name,
int _value );
1073 void SetDoubleAttribute(
const std::string& name,
double value );
1079 void SetAttribute(
const char * name,
int value );
1084 void SetDoubleAttribute(
const char * name,
double value );
1088 void RemoveAttribute(
const char * name );
1089 #ifdef TIXML_USE_STL 1090 void RemoveAttribute(
const std::string& name ) { RemoveAttribute (name.c_str ()); }
1130 const char* GetText()
const;
1135 virtual void Print( FILE* cfile,
int depth )
const;
1155 #ifdef TIXML_USE_STL 1156 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1188 virtual void Print( FILE* cfile,
int depth )
const;
1206 #ifdef TIXML_USE_STL 1207 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1236 #ifdef TIXML_USE_STL 1249 virtual void Print( FILE* cfile,
int depth )
const;
1272 #ifdef TIXML_USE_STL 1273 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1300 #ifdef TIXML_USE_STL 1303 const std::string& _encoding,
1304 const std::string& _standalone );
1309 const char* _encoding,
1310 const char* _standalone );
1318 const char *
Version()
const {
return version.c_str (); }
1320 const char *
Encoding()
const {
return encoding.c_str (); }
1327 virtual void Print( FILE* cfile,
int depth,
TIXML_STRING* str )
const;
1328 virtual void Print( FILE* cfile,
int depth )
const {
1329 Print( cfile, depth, 0 );
1344 #ifdef TIXML_USE_STL 1345 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1375 virtual void Print( FILE* cfile,
int depth )
const;
1389 #ifdef TIXML_USE_STL 1390 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1410 #ifdef TIXML_USE_STL 1426 bool SaveFile()
const;
1430 bool SaveFile(
const char * filename )
const;
1438 bool SaveFile( FILE* )
const;
1440 #ifdef TIXML_USE_STL 1443 return LoadFile( filename.c_str(), encoding );
1445 bool SaveFile(
const std::string& filename )
const 1447 return SaveFile( filename.c_str() );
1472 const char *
ErrorDesc()
const {
return errorDesc.c_str (); }
1523 errorLocation.row = errorLocation.col = 0;
1537 virtual void Print( FILE* cfile,
int depth = 0 )
const;
1551 #ifdef TIXML_USE_STL 1552 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1563 bool useMicrosoftBOM;
1659 TiXmlHandle FirstChild(
const char * value )
const;
1663 TiXmlHandle FirstChildElement(
const char * value )
const;
1668 TiXmlHandle Child(
const char* value,
int index )
const;
1677 TiXmlHandle ChildElement(
const char* value,
int index )
const;
1684 #ifdef TIXML_USE_STL 1685 TiXmlHandle FirstChild(
const std::string& _value )
const {
return FirstChild( _value.c_str() ); }
1686 TiXmlHandle FirstChildElement(
const std::string& _value )
const {
return FirstChildElement( _value.c_str() ); }
1688 TiXmlHandle Child(
const std::string& _value,
int index )
const {
return Child( _value.c_str(), index ); }
1689 TiXmlHandle ChildElement(
const std::string& _value,
int index )
const {
return ChildElement( _value.c_str(), index ); }
1750 buffer(), indent(
" " ), lineBreak(
"\n" ) {}
1759 virtual bool Visit(
const TiXmlText& text );
1766 void SetIndent(
const char* _indent ) { indent = _indent ? _indent :
"" ; }
1768 const char*
Indent() {
return indent.c_str(); }
1773 void SetLineBreak(
const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak :
""; }
1784 const char*
CStr() {
return buffer.c_str(); }
1786 size_t Size() {
return buffer.size(); }
1788 #ifdef TIXML_USE_STL 1789 const std::string& Str() {
return buffer; }
1795 for(
int i=0;
i<depth; ++
i )
1798 void DoLineBreak() {
1799 buffer += lineBreak;
1803 bool simpleTextPrint;
1811 #pragma warning( pop )
static const int utf8ByteTable[256]
const TiXmlAttribute * First() const
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
TiXmlNode * LastChild(const char *_value)
The last child of this node matching 'value'. Will be null if there are no children.
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
TiXmlUnknown * Unknown() const
virtual bool Accept(TiXmlVisitor *visitor) const
void SetUserData(void *user)
Set a pointer to arbitrary user data.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
TiXmlUnknown(const TiXmlUnknown ©)
const TiXmlNode * Parent() const
const TiXmlElement * RootElement() const
void SetLineBreak(const char *_lineBreak)
const TIXML_STRING & ValueTStr() const
TiXmlElement * NextSiblingElement()
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
TiXmlNode * PreviousSibling(const char *_prev)
TiXmlNode * LastChild()
The last child of this node. Will be null if there are no children.
const char * LineBreak()
Query the current line breaking string.
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null if not of the requested type.
virtual bool Visit(const TiXmlUnknown &)
Visit an unknown node.
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
void CopyTo(TiXmlUnknown *target) const
const void * GetUserData() const
Get a pointer to arbitrary user data.
static int ToLower(int v, TiXmlEncoding encoding)
TiXmlNode * IterateChildren(const char *_value, const TiXmlNode *previous)
static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding)
TiXmlElement & operator=(const TiXmlElement &base)
virtual void Print(FILE *cfile, int depth) const
const TIXML_STRING & NameTStr() const
TiXmlAttribute * FirstAttribute()
TiXmlElement * FirstChildElement(const char *_value)
static const char * ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
const TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
virtual bool VisitExit(const TiXmlElement &)
Visit an element.
void SetName(const char *_name)
Set the name of this attribute.
TiXmlNode * NextSibling()
void SetTabSize(int _tabsize)
TiXmlAttribute()
Construct an empty attribute.
const int TIXML_PATCH_VERSION
const char * Standalone() const
Is this a standalone document?
TiXmlElement * ToElement() const
TiXmlElement * NextSiblingElement(const char *_next)
TiXmlElement * FirstChildElement()
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null if not of the requested type.
const char * Value() const
Return the value of this attribute.
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null if not of the requested type.
virtual void Print(FILE *cfile, int depth) const
static const char * errorString[TIXML_ERROR_STRING_COUNT]
void SetValue(const char *_value)
int ErrorCol() const
The column where the error occured. See ErrorRow()
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null not of the requested type.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
TiXmlNode * PreviousSibling()
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
const char * Encoding() const
Encoding. Will return an empty string if none was found.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
const TiXmlNode * LastChild() const
const char * Name() const
Return the name of this attribute.
void * userData
Field containing a generic user pointer.
TiXmlDocument * GetDocument()
const TiXmlAttribute * Last() const
static bool IsWhiteSpace(char c)
virtual bool Visit(const TiXmlText &)
Visit a text node.
const TiXmlEncoding TIXML_DEFAULT_ENCODING
const char * Version() const
Version. Will return an empty string if none was found.
TiXmlNode * NextSibling(const char *_next)
int Column() const
See Row()
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
TiXmlText(const TiXmlText ©)
static const char * ReadText(const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
const int TIXML_MAJOR_VERSION
void SetIndent(const char *_indent)
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null not of the requested type.
virtual void Print(FILE *cfile, int depth) const
void SetCDATA(bool _cdata)
Turns on or off a CDATA representation of text.
const char * Indent()
Query the indention string.
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null not of the requested type.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
int QueryFloatAttribute(const char *name, float *_value) const
QueryFloatAttribute examines the attribute - see QueryIntAttribute().
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Log & operator<<(Log &log, T data)
TiXmlText & operator=(const TiXmlText &base)
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlDocument * GetDocument() const
bool CDATA() const
Queries whether this represents text using a CDATA section.
static bool IsWhiteSpace(int c)
virtual TiXmlComment * ToComment()
Cast to a more defined type. Will return null if not of the requested type.
bool operator>(const TiXmlAttribute &rhs) const
static const char * GetEntity(const char *in, char *value, int *length, TiXmlEncoding encoding)
TiXmlNode * ToNode() const
static void SetCondenseWhiteSpace(bool condense)
bool operator<(const TiXmlAttribute &rhs) const
const TiXmlElement * NextSiblingElement() const
TiXmlNode * Parent()
One step up the DOM.
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null if not of the requested type.
bool operator==(const TiXmlAttribute &rhs) const
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null if not of the requested type.
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
TiXmlHandle operator=(const TiXmlHandle &ref)
TiXmlNode * IterateChildren(const TiXmlNode *previous)
TiXmlAttribute * Previous()
TiXmlElement * Element() const
TiXmlNode(NodeType _type)
TiXmlElement * RootElement()
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
void * GetUserData()
Get a pointer to arbitrary user data.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
size_t Size()
Return the length of the result string.
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
virtual bool Visit(const TiXmlComment &)
Visit a comment node.
static const char * GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
TiXmlText(const char *initValue)
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
const char * Value() const
TiXmlDocument & operator=(const TiXmlDocument ©)
void CopyTo(TiXmlText *target) const
TiXmlUnknown & operator=(const TiXmlUnknown ©)
bool NoChildren() const
Returns true if this node has no children.
void CopyTo(TiXmlElement *target) const
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
void SetDocument(TiXmlDocument *doc)
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null not of the requested type.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
void SetValue(const char *_value)
Set the value.
virtual ~TiXmlDeclaration()
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null not of the requested type.
TiXmlAttribute * LastAttribute()
TiXmlText * ToText() const
TiXmlDeclaration()
Construct an empty declaration.
static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
TiXmlUnknown * ToUnknown() const
const char * CStr()
Return the result.
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null if not of the requested type.
const int TIXML_MINOR_VERSION
virtual bool VisitEnter(const TiXmlElement &, const TiXmlAttribute *)
Visit an element.
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.