26 #ifndef __EDELIB_TIXML_H__
27 #define __EDELIB_TIXML_H__
36 #if defined( _DEBUG ) && !defined( DEBUG )
44 #define TIXML_STRING std::string
47 #define TIXML_STRING EDELIB_NS_PREPEND(String)
57 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
59 #define TIXML_SNPRINTF _snprintf_s
60 #define TIXML_SNSCANF _snscanf_s
61 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
64 #define TIXML_SNPRINTF _snprintf
65 #define TIXML_SNSCANF _snscanf
66 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
69 #define TIXML_SNPRINTF snprintf
70 #define TIXML_SNSCANF snscanf
81 class TiXmlParsingData;
83 const int TIXML_MAJOR_VERSION = 2;
84 const int TIXML_MINOR_VERSION = 5;
85 const int TIXML_PATCH_VERSION = 2;
94 TiXmlCursor() { Clear(); }
95 void Clear() { row = col = -1; }
158 TIXML_ENCODING_UNKNOWN,
160 TIXML_ENCODING_LEGACY
163 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
214 virtual void Print( FILE* cfile,
int depth )
const = 0;
258 static const int utf8ByteTable[256];
260 virtual const char*
Parse(
const char* p,
261 TiXmlParsingData* data,
262 TiXmlEncoding encoding ) = 0;
269 TIXML_ERROR_OPENING_FILE,
270 TIXML_ERROR_OUT_OF_MEMORY,
271 TIXML_ERROR_PARSING_ELEMENT,
272 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
273 TIXML_ERROR_READING_ELEMENT_VALUE,
274 TIXML_ERROR_READING_ATTRIBUTES,
275 TIXML_ERROR_PARSING_EMPTY,
276 TIXML_ERROR_READING_END_TAG,
277 TIXML_ERROR_PARSING_UNKNOWN,
278 TIXML_ERROR_PARSING_COMMENT,
279 TIXML_ERROR_PARSING_DECLARATION,
280 TIXML_ERROR_DOCUMENT_EMPTY,
281 TIXML_ERROR_EMBEDDED_NULL,
282 TIXML_ERROR_PARSING_CDATA,
283 TIXML_ERROR_DOCUMENT_TOP_ONLY,
285 TIXML_ERROR_STRING_COUNT
290 static const char* SkipWhiteSpace(
const char*, TiXmlEncoding encoding );
291 inline static bool IsWhiteSpace(
char c )
293 return ( isspace( (
unsigned char) c ) || c ==
'\n' || c ==
'\r' );
295 inline static bool IsWhiteSpace(
int c )
298 return IsWhiteSpace( (
char) c );
303 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
304 static bool StreamTo( std::istream * in,
int character, TIXML_STRING * tag );
314 static const char*
ReadName(
const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
320 static const char*
ReadText(
const char* in,
322 bool ignoreWhiteSpace,
325 TiXmlEncoding encoding );
328 static const char*
GetEntity(
const char* in,
char* value,
int* length, TiXmlEncoding encoding );
334 inline static const char*
GetChar(
const char* p,
char* _value,
int* length, TiXmlEncoding encoding )
337 if ( encoding == TIXML_ENCODING_UTF8 )
339 *length = utf8ByteTable[ *((
const unsigned char*)p) ];
340 assert( *length >= 0 && *length < 5 );
350 return GetEntity( p, _value, length, encoding );
358 for(
int i=0; p[i] && i<*length; ++i ) {
361 return p + (*length);
374 static void PutString(
const TIXML_STRING& str, TIXML_STRING* out );
384 TiXmlEncoding encoding );
399 static int IsAlpha(
unsigned char anyByte, TiXmlEncoding encoding );
401 static int IsAlphaNum(
unsigned char anyByte, TiXmlEncoding encoding );
403 inline static int ToLower(
int v, TiXmlEncoding encoding )
405 if ( encoding == TIXML_ENCODING_UTF8 )
407 if ( v < 128 )
return tolower( v );
425 unsigned int strLength;
432 MAX_ENTITY_LENGTH = 6
435 static Entity entity[ NUM_ENTITY ];
436 static bool condenseWhiteSpace;
462 friend std::istream& operator >> (std::istream& in,
TiXmlNode& base);
517 const char *
Value()
const {
return value.c_str (); }
525 const std::string& ValueStr()
const {
return value; }
538 void SetValue(
const char * _value) { value = _value;}
542 void SetValue(
const std::string& _value ) { value = _value; }
565 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->FirstChild( _value ));
579 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->LastChild( _value ));
614 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( previous ) );
621 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( _value, previous ) );
691 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->PreviousSibling( _prev ) );
714 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSibling( _next ) );
740 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSiblingElement( _next ) );
764 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->FirstChildElement( _value ) );
784 int Type()
const {
return type; }
868 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
905 friend class TiXmlAttributeSet;
917 TiXmlAttribute(
const std::string& _name,
const std::string& _value )
936 const char*
Name()
const {
return name.c_str(); }
938 const char*
Value()
const {
return value.c_str(); }
941 const std::string& ValueStr()
const {
return value; }
944 int IntValue()
const;
946 double DoubleValue()
const;
949 const TIXML_STRING&
NameTStr()
const {
return name; }
961 int QueryIntValue(
int* _value )
const;
963 int QueryDoubleValue(
double* _value )
const;
966 void SetName(
const char* _name ) { name = _name; }
968 void SetValue(
const char* _value ) { value = _value; }
971 void SetIntValue(
int _value );
973 void SetDoubleValue(
double _value );
977 void SetName(
const std::string& _name ) { name = _name; }
979 void SetValue(
const std::string& _value ) { value = _value; }
1007 virtual const char* Parse(
const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1010 virtual void Print( FILE* cfile,
int depth )
const {
1011 Print( cfile, depth, 0 );
1014 void Print( FILE* cfile,
int depth, TIXML_STRING* str )
const;
1047 class TiXmlAttributeSet
1050 TiXmlAttributeSet();
1051 ~TiXmlAttributeSet();
1056 const TiXmlAttribute* First()
const {
return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
1057 TiXmlAttribute* First() {
return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
1058 const TiXmlAttribute* Last()
const {
return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
1059 TiXmlAttribute* Last() {
return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
1063 return const_cast< TiXmlAttribute*
>( (
const_cast< const TiXmlAttributeSet*
>(
this))->Find( _name ) );
1065 #ifdef TIXML_USE_STL
1068 return const_cast< TiXmlAttribute*
>( (
const_cast< const TiXmlAttributeSet*
>(
this))->Find( _name ) );
1075 TiXmlAttributeSet(
const TiXmlAttributeSet& );
1076 void operator=(
const TiXmlAttributeSet& );
1098 #ifdef TIXML_USE_STL
1116 const char* Attribute(
const char* name )
const;
1125 const char* Attribute(
const char* name,
int* i )
const;
1134 const char* Attribute(
const char* name,
double* d )
const;
1144 int QueryIntAttribute(
const char* name,
int* _value )
const;
1146 int QueryDoubleAttribute(
const char* name,
double* _value )
const;
1150 int result = QueryDoubleAttribute( name, &d );
1151 if ( result == TIXML_SUCCESS ) {
1156 #ifdef TIXML_USE_STL
1164 template<
typename T >
int QueryValueAttribute(
const std::string& name, T* outValue )
const
1168 return TIXML_NO_ATTRIBUTE;
1170 std::stringstream sstream( node->ValueStr() );
1171 sstream >> *outValue;
1172 if ( !sstream.fail() )
1173 return TIXML_SUCCESS;
1174 return TIXML_WRONG_TYPE;
1182 void SetAttribute(
const char* name,
const char * _value );
1184 #ifdef TIXML_USE_STL
1186 const std::string* Attribute(
const std::string& name )
const;
1188 const std::string* Attribute(
const std::string& name,
int* i )
const;
1190 const std::string* Attribute(
const std::string& name,
double* d )
const;
1192 int QueryIntAttribute(
const std::string& name,
int* _value )
const;
1194 int QueryDoubleAttribute(
const std::string& name,
double* _value )
const;
1197 void SetAttribute(
const std::string& name,
const std::string& _value );
1199 void SetAttribute(
const std::string& name,
int _value );
1206 void SetAttribute(
const char * name,
int value );
1212 void SetDoubleAttribute(
const char * name,
double value );
1215 void RemoveAttribute(
const char * name );
1216 #ifdef TIXML_USE_STL
1218 void RemoveAttribute(
const std::string& name ) { RemoveAttribute (name.c_str ()); }
1264 const char* GetText()
const;
1269 virtual void Print( FILE* cfile,
int depth )
const;
1275 virtual const char* Parse(
const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1291 #ifdef TIXML_USE_STL
1292 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1299 const char* ReadValue(
const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1304 TiXmlAttributeSet attributeSet;
1332 virtual void Print( FILE* cfile,
int depth )
const;
1338 virtual const char* Parse(
const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1353 #ifdef TIXML_USE_STL
1354 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1387 #ifdef TIXML_USE_STL
1401 virtual void Print( FILE* cfile,
int depth )
const;
1409 virtual const char*
Parse(
const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1427 #ifdef TIXML_USE_STL
1428 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1461 #ifdef TIXML_USE_STL
1464 const std::string& _encoding,
1465 const std::string& _standalone );
1470 const char* _encoding,
1471 const char* _standalone );
1483 const char *
Version()
const {
return version.c_str (); }
1485 const char *
Encoding()
const {
return encoding.c_str (); }
1493 virtual void Print( FILE* cfile,
int depth, TIXML_STRING* str )
const;
1495 virtual void Print( FILE* cfile,
int depth )
const {
1496 Print( cfile, depth, 0 );
1499 virtual const char* Parse(
const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1513 #ifdef TIXML_USE_STL
1514 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1521 TIXML_STRING version;
1522 TIXML_STRING encoding;
1523 TIXML_STRING standalone;
1555 virtual void Print( FILE* cfile,
int depth )
const;
1557 virtual const char* Parse(
const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1571 #ifdef TIXML_USE_STL
1572 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1598 #ifdef TIXML_USE_STL
1617 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1619 bool SaveFile()
const;
1621 bool LoadFile(
const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1623 bool SaveFile(
const char * filename )
const;
1630 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1632 bool SaveFile( FILE* )
const;
1634 #ifdef TIXML_USE_STL
1636 bool LoadFile(
const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
1638 return LoadFile( filename.c_str(), encoding );
1642 bool SaveFile(
const std::string& filename )
const
1644 return SaveFile( filename.c_str() );
1653 virtual const char* Parse(
const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1673 const char *
ErrorDesc()
const {
return errorDesc.c_str (); }
1731 errorLocation.row = errorLocation.col = 0;
1746 virtual void Print( FILE* cfile,
int depth = 0 )
const;
1749 void SetError(
int err,
const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1763 #ifdef TIXML_USE_STL
1764 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1774 TIXML_STRING errorDesc;
1776 TiXmlCursor errorLocation;
1777 bool useMicrosoftBOM;
1879 TiXmlHandle FirstChild(
const char * value )
const;
1883 TiXmlHandle FirstChildElement(
const char * value )
const;
1889 TiXmlHandle Child(
const char* value,
int index )
const;
1900 TiXmlHandle ChildElement(
const char* value,
int index )
const;
1908 #ifdef TIXML_USE_STL
1910 TiXmlHandle FirstChild(
const std::string& _value )
const {
return FirstChild( _value.c_str() ); }
1912 TiXmlHandle FirstChildElement(
const std::string& _value )
const {
return FirstChildElement( _value.c_str() ); }
1915 TiXmlHandle Child(
const std::string& _value,
int index )
const {
return Child( _value.c_str(), index ); }
1917 TiXmlHandle ChildElement(
const std::string& _value,
int index )
const {
return ChildElement( _value.c_str(), index ); }
1983 buffer(), indent(
" " ), lineBreak(
"\n" ) {}
2001 void SetIndent(
const char* _indent ) { indent = _indent ? _indent :
"" ; }
2010 void SetLineBreak(
const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak :
""; }
2025 #ifdef TIXML_USE_STL
2027 const std::string& Str() {
return buffer; }
2032 for(
int i=0; i<depth; ++i )
2035 void DoLineBreak() {
2036 buffer += lineBreak;
2040 bool simpleTextPrint;
2041 TIXML_STRING buffer;
2042 TIXML_STRING indent;
2043 TIXML_STRING lineBreak;
2048 #pragma warning( pop )