Warning, file /include/XML/tinyxml.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #ifndef XML_TINYXML_H
0002 #define XML_TINYXML_H
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef TIXML_USE_STL
0032 #define TIXML_USE_STL
0033 #endif
0034
0035 #ifndef TINYXML_INCLUDED
0036 #define TINYXML_INCLUDED
0037
0038 #ifdef _MSC_VER
0039 #pragma warning( push )
0040 #pragma warning( disable : 4530 )
0041 #pragma warning( disable : 4786 )
0042 #endif
0043
0044 #include <ctype.h>
0045 #include <stdio.h>
0046 #include <stdlib.h>
0047 #include <string.h>
0048 #include <assert.h>
0049
0050
0051 #if defined( _DEBUG ) && !defined( DEBUG )
0052 #define DEBUG
0053 #endif
0054
0055 #ifdef TIXML_USE_STL
0056 #include <string>
0057 #include <iostream>
0058 #include <sstream>
0059 #define TIXML_STRING std::string
0060 #else
0061 #include "tinystr.h"
0062 #define TIXML_STRING TiXmlString
0063 #endif
0064
0065
0066
0067
0068
0069 #define TIXML_SAFE
0070
0071 #ifdef TIXML_SAFE
0072 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
0073
0074 #define TIXML_SNPRINTF _snprintf_s
0075 #define TIXML_SNSCANF _snscanf_s
0076 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
0077
0078
0079 #define TIXML_SNPRINTF _snprintf
0080 #define TIXML_SNSCANF _snscanf
0081 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
0082
0083
0084 #define TIXML_SNPRINTF snprintf
0085 #define TIXML_SNSCANF snscanf
0086 #endif
0087 #endif
0088
0089 class TiXmlDocument;
0090 class TiXmlElement;
0091 class TiXmlComment;
0092 class TiXmlUnknown;
0093 class TiXmlAttribute;
0094 class TiXmlText;
0095 class TiXmlDeclaration;
0096 class TiXmlParsingData;
0097
0098 const int TIXML_MAJOR_VERSION = 2;
0099 const int TIXML_MINOR_VERSION = 5;
0100 const int TIXML_PATCH_VERSION = 2;
0101
0102
0103
0104
0105 struct TiXmlCursor {
0106 TiXmlCursor() {
0107 Clear();
0108 }
0109 void Clear() {
0110 row = col = -1;
0111 }
0112
0113 int row;
0114 int col;
0115 };
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135 class TiXmlVisitor {
0136 public:
0137 virtual ~TiXmlVisitor() {
0138 }
0139
0140
0141 virtual bool VisitEnter(const TiXmlDocument& ) {
0142 return true;
0143 }
0144
0145 virtual bool VisitExit(const TiXmlDocument& ) {
0146 return true;
0147 }
0148
0149
0150 virtual bool VisitEnter(const TiXmlElement& , const TiXmlAttribute* ) {
0151 return true;
0152 }
0153
0154 virtual bool VisitExit(const TiXmlElement& ) {
0155 return true;
0156 }
0157
0158
0159 virtual bool Visit(const TiXmlDeclaration& ) {
0160 return true;
0161 }
0162
0163 virtual bool Visit(const TiXmlText& ) {
0164 return true;
0165 }
0166
0167 virtual bool Visit(const TiXmlComment& ) {
0168 return true;
0169 }
0170
0171 virtual bool Visit(const TiXmlUnknown& ) {
0172 return true;
0173 }
0174 };
0175
0176
0177 enum {
0178 TIXML_SUCCESS, TIXML_NO_ATTRIBUTE, TIXML_WRONG_TYPE
0179 };
0180
0181
0182 enum TiXmlEncoding {
0183 TIXML_ENCODING_UNKNOWN, TIXML_ENCODING_UTF8, TIXML_ENCODING_LEGACY
0184 };
0185
0186 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210 class TiXmlBase {
0211 friend class TiXmlNode;
0212 friend class TiXmlElement;
0213 friend class TiXmlDocument;
0214
0215 public:
0216 TiXmlBase()
0217 : userData(0) {
0218 }
0219 virtual ~TiXmlBase() {
0220 }
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231 virtual void Print(FILE* cfile, int depth) const = 0;
0232
0233
0234
0235
0236
0237
0238
0239 static void SetCondenseWhiteSpace(bool condense) {
0240 condenseWhiteSpace = condense;
0241 }
0242
0243
0244 static bool IsWhiteSpaceCondensed() {
0245 return condenseWhiteSpace;
0246 }
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266 int Row() const {
0267 return location.row + 1;
0268 }
0269 int Column() const {
0270 return location.col + 1;
0271 }
0272
0273 void SetUserData(void* user) {
0274 userData = user;
0275 }
0276 void* GetUserData() {
0277 return userData;
0278 }
0279 const void* GetUserData() const {
0280 return userData;
0281 }
0282
0283
0284
0285 static const int utf8ByteTable[256];
0286
0287 virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) = 0;
0288
0289 enum {
0290 TIXML_NO_ERROR = 0,
0291 TIXML_ERROR,
0292 TIXML_ERROR_OPENING_FILE,
0293 TIXML_ERROR_OUT_OF_MEMORY,
0294 TIXML_ERROR_PARSING_ELEMENT,
0295 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
0296 TIXML_ERROR_READING_ELEMENT_VALUE,
0297 TIXML_ERROR_READING_ATTRIBUTES,
0298 TIXML_ERROR_PARSING_EMPTY,
0299 TIXML_ERROR_READING_END_TAG,
0300 TIXML_ERROR_PARSING_UNKNOWN,
0301 TIXML_ERROR_PARSING_COMMENT,
0302 TIXML_ERROR_PARSING_DECLARATION,
0303 TIXML_ERROR_DOCUMENT_EMPTY,
0304 TIXML_ERROR_EMBEDDED_NULL,
0305 TIXML_ERROR_PARSING_CDATA,
0306 TIXML_ERROR_DOCUMENT_TOP_ONLY,
0307
0308 TIXML_ERROR_STRING_COUNT
0309 };
0310
0311 protected:
0312
0313 static const char* SkipWhiteSpace(const char*, TiXmlEncoding encoding);
0314 inline static bool IsWhiteSpace(char c) {
0315 return (isspace((unsigned char) c) || c == '\n' || c == '\r');
0316 }
0317 inline static bool IsWhiteSpace(int c) {
0318 if (c < 256)
0319 return IsWhiteSpace((char) c);
0320 return false;
0321 }
0322
0323 #ifdef TIXML_USE_STL
0324 static bool StreamWhiteSpace(std::istream * in, TIXML_STRING * tag);
0325 static bool StreamTo(std::istream * in, int character, TIXML_STRING * tag);
0326 #endif
0327
0328
0329
0330
0331
0332 static const char* ReadName(const char* p, TIXML_STRING* name, TiXmlEncoding encoding);
0333
0334
0335
0336
0337 static const char* ReadText(const char* in,
0338 TIXML_STRING* text,
0339 bool ignoreWhiteSpace,
0340 const char* endTag,
0341 bool ignoreCase,
0342 TiXmlEncoding encoding);
0343
0344
0345 static const char* GetEntity(const char* in, char* value, int* length, TiXmlEncoding encoding);
0346
0347
0348
0349 inline static const char* GetChar(const char* p, char* _value, int* length, TiXmlEncoding encoding) {
0350 assert( p);
0351 if (encoding == TIXML_ENCODING_UTF8) {
0352 *length = utf8ByteTable[*((const unsigned char*) p)];
0353 assert( *length >= 0 && *length < 5);
0354 }
0355 else {
0356 *length = 1;
0357 }
0358
0359 if (*length == 1) {
0360 if (*p == '&')
0361 return GetEntity(p, _value, length, encoding);
0362 *_value = *p;
0363 return p + 1;
0364 }
0365 else if (*length) {
0366
0367
0368 for (int i = 0; p[i] && i < *length; ++i) {
0369 _value[i] = p[i];
0370 }
0371 return p + (*length);
0372 }
0373 else {
0374
0375 return 0;
0376 }
0377 }
0378
0379
0380
0381 static void PutString(const TIXML_STRING& str, TIXML_STRING* out);
0382
0383
0384
0385
0386 static bool StringEqual(const char* p, const char* endTag, bool ignoreCase, TiXmlEncoding encoding);
0387
0388 static const char* errorString[TIXML_ERROR_STRING_COUNT];
0389
0390 TiXmlCursor location;
0391
0392
0393 void* userData;
0394
0395
0396
0397 static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding);
0398 static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding);
0399 inline static int ToLower(int v, TiXmlEncoding encoding) {
0400 if (encoding == TIXML_ENCODING_UTF8) {
0401 if (v < 128)
0402 return tolower(v);
0403 return v;
0404 }
0405 else {
0406 return tolower(v);
0407 }
0408 }
0409 static void ConvertUTF32ToUTF8(unsigned long input, char* output, int* length);
0410
0411 private:
0412 TiXmlBase(const TiXmlBase&);
0413 void operator=(const TiXmlBase& base);
0414
0415 struct Entity {
0416 const char* str;
0417 unsigned int strLength;
0418 char chr;
0419 };
0420 enum {
0421 NUM_ENTITY = 5, MAX_ENTITY_LENGTH = 6
0422
0423 };
0424 static Entity entity[NUM_ENTITY];
0425 static bool condenseWhiteSpace;
0426 };
0427
0428
0429
0430
0431
0432
0433
0434 class TiXmlNode: public TiXmlBase {
0435 friend class TiXmlDocument;
0436 friend class TiXmlElement;
0437
0438 public:
0439 #ifdef TIXML_USE_STL
0440
0441
0442
0443
0444 friend std::istream& operator >>(std::istream& in, TiXmlNode& base);
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462 friend std::ostream& operator<<(std::ostream& out, const TiXmlNode& base);
0463
0464
0465 friend std::string& operator<<(std::string& out, const TiXmlNode& base);
0466
0467 #endif
0468
0469
0470
0471
0472 enum NodeType {
0473 DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, DECLARATION, TYPECOUNT
0474 };
0475
0476 virtual ~TiXmlNode();
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490 const char *Value() const {
0491 return value.c_str();
0492 }
0493
0494 #ifdef TIXML_USE_STL
0495
0496
0497
0498
0499 const std::string& ValueStr() const {
0500 return value;
0501 }
0502 #endif
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513 void SetValue(const char * _value) {
0514 value = _value;
0515 }
0516
0517 #ifdef TIXML_USE_STL
0518
0519 void SetValue(const std::string& _value) {
0520 value = _value;
0521 }
0522 #endif
0523
0524
0525 void Clear();
0526
0527
0528 TiXmlNode* Parent() {
0529 return parent;
0530 }
0531 const TiXmlNode* Parent() const {
0532 return parent;
0533 }
0534
0535 const TiXmlNode* FirstChild() const {
0536 return firstChild;
0537 }
0538 TiXmlNode* FirstChild() {
0539 return firstChild;
0540 }
0541 const TiXmlNode* FirstChild(const char * value) const;
0542
0543 TiXmlNode* FirstChild(const char * _value) {
0544
0545
0546 return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->FirstChild(_value));
0547 }
0548 const TiXmlNode* LastChild() const {
0549 return lastChild;
0550 }
0551 TiXmlNode* LastChild() {
0552 return lastChild;
0553 }
0554
0555 const TiXmlNode* LastChild(const char * value) const;
0556 TiXmlNode* LastChild(const char * _value) {
0557 return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->LastChild(_value));
0558 }
0559
0560 #ifdef TIXML_USE_STL
0561 const TiXmlNode* FirstChild(const std::string& _value) const {
0562 return FirstChild(_value.c_str());
0563 }
0564 TiXmlNode* FirstChild(const std::string& _value) {
0565 return FirstChild(_value.c_str());
0566 }
0567 const TiXmlNode* LastChild(const std::string& _value) const {
0568 return LastChild(_value.c_str());
0569 }
0570 TiXmlNode* LastChild(const std::string& _value) {
0571 return LastChild(_value.c_str());
0572 }
0573 #endif
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591 const TiXmlNode* IterateChildren(const TiXmlNode* previous) const;
0592 TiXmlNode* IterateChildren(const TiXmlNode* previous) {
0593 return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->IterateChildren(previous));
0594 }
0595
0596
0597 const TiXmlNode* IterateChildren(const char * value, const TiXmlNode* previous) const;
0598 TiXmlNode* IterateChildren(const char * _value, const TiXmlNode* previous) {
0599 return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->IterateChildren(_value, previous));
0600 }
0601
0602 #ifdef TIXML_USE_STL
0603 const TiXmlNode* IterateChildren(const std::string& _value, const TiXmlNode* previous) const {
0604 return IterateChildren(_value.c_str(), previous);
0605 }
0606 TiXmlNode* IterateChildren(const std::string& _value, const TiXmlNode* previous) {
0607 return IterateChildren(_value.c_str(), previous);
0608 }
0609 #endif
0610
0611
0612
0613
0614 TiXmlNode* InsertEndChild(const TiXmlNode& addThis);
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625 TiXmlNode* LinkEndChild(TiXmlNode* addThis);
0626
0627
0628
0629
0630 TiXmlNode* InsertBeforeChild(TiXmlNode* beforeThis, const TiXmlNode& addThis);
0631
0632
0633
0634
0635 TiXmlNode* InsertAfterChild(TiXmlNode* afterThis, const TiXmlNode& addThis);
0636
0637
0638
0639
0640 TiXmlNode* ReplaceChild(TiXmlNode* replaceThis, const TiXmlNode& withThis);
0641
0642
0643 bool RemoveChild(TiXmlNode* removeThis);
0644
0645
0646 const TiXmlNode* PreviousSibling() const {
0647 return prev;
0648 }
0649 TiXmlNode* PreviousSibling() {
0650 return prev;
0651 }
0652
0653
0654 const TiXmlNode* PreviousSibling(const char *) const;
0655 TiXmlNode* PreviousSibling(const char *_prev) {
0656 return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->PreviousSibling(_prev));
0657 }
0658
0659 #ifdef TIXML_USE_STL
0660 const TiXmlNode* PreviousSibling(const std::string& _value) const {
0661 return PreviousSibling(_value.c_str());
0662 }
0663 TiXmlNode* PreviousSibling(const std::string& _value) {
0664 return PreviousSibling(_value.c_str());
0665 }
0666 const TiXmlNode* NextSibling(const std::string& _value) const {
0667 return NextSibling(_value.c_str());
0668 }
0669 TiXmlNode* NextSibling(const std::string& _value) {
0670 return NextSibling(_value.c_str());
0671 }
0672 #endif
0673
0674
0675 const TiXmlNode* NextSibling() const {
0676 return next;
0677 }
0678 TiXmlNode* NextSibling() {
0679 return next;
0680 }
0681
0682
0683 const TiXmlNode* NextSibling(const char *) const;
0684 TiXmlNode* NextSibling(const char* _next) {
0685 return const_cast<TiXmlNode*>((const_cast<const TiXmlNode*>(this))->NextSibling(_next));
0686 }
0687
0688
0689
0690
0691
0692 const TiXmlElement* NextSiblingElement() const;
0693 TiXmlElement* NextSiblingElement() {
0694 return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->NextSiblingElement());
0695 }
0696
0697
0698
0699
0700
0701 const TiXmlElement* NextSiblingElement(const char *) const;
0702 TiXmlElement* NextSiblingElement(const char *_next) {
0703 return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->NextSiblingElement(_next));
0704 }
0705
0706
0707
0708
0709
0710 const TiXmlElement* PreviousSiblingElement() const;
0711 TiXmlElement* PreviousSiblingElement() {
0712 return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->PreviousSiblingElement());
0713 }
0714
0715
0716
0717
0718
0719 const TiXmlElement* PreviousSiblingElement(const char *) const;
0720 TiXmlElement* PreviousSiblingElement(const char *_next) {
0721 return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->PreviousSiblingElement(_next));
0722 }
0723
0724 #ifdef TIXML_USE_STL
0725 const TiXmlElement* NextSiblingElement(const std::string& _value) const {
0726 return NextSiblingElement(_value.c_str());
0727 }
0728 TiXmlElement* NextSiblingElement(const std::string& _value) {
0729 return NextSiblingElement(_value.c_str());
0730 }
0731 #endif
0732
0733
0734 const TiXmlElement* FirstChildElement() const;
0735 TiXmlElement* FirstChildElement() {
0736 return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->FirstChildElement());
0737 }
0738
0739
0740 const TiXmlElement* FirstChildElement(const char * _value) const;
0741 TiXmlElement* FirstChildElement(const char * _value) {
0742 return const_cast<TiXmlElement*>((const_cast<const TiXmlNode*>(this))->FirstChildElement(_value));
0743 }
0744
0745 #ifdef TIXML_USE_STL
0746 const TiXmlElement* FirstChildElement(const std::string& _value) const {
0747 return FirstChildElement(_value.c_str());
0748 }
0749 TiXmlElement* FirstChildElement(const std::string& _value) {
0750 return FirstChildElement(_value.c_str());
0751 }
0752 #endif
0753
0754
0755
0756
0757
0758 int Type() const {
0759 return type;
0760 }
0761
0762
0763
0764
0765 const TiXmlDocument* GetDocument() const;
0766 TiXmlDocument* GetDocument() {
0767 return const_cast<TiXmlDocument*>((const_cast<const TiXmlNode*>(this))->GetDocument());
0768 }
0769
0770
0771 bool NoChildren() const {
0772 return !firstChild;
0773 }
0774
0775 virtual const TiXmlDocument* ToDocument() const {
0776 return 0;
0777 }
0778 virtual const TiXmlElement* ToElement() const {
0779 return 0;
0780 }
0781 virtual const TiXmlComment* ToComment() const {
0782 return 0;
0783 }
0784 virtual const TiXmlUnknown* ToUnknown() const {
0785 return 0;
0786 }
0787 virtual const TiXmlText* ToText() const {
0788 return 0;
0789 }
0790 virtual const TiXmlDeclaration* ToDeclaration() const {
0791 return 0;
0792 }
0793
0794 virtual TiXmlDocument* ToDocument() {
0795 return 0;
0796 }
0797 virtual TiXmlElement* ToElement() {
0798 return 0;
0799 }
0800 virtual TiXmlComment* ToComment() {
0801 return 0;
0802 }
0803 virtual TiXmlUnknown* ToUnknown() {
0804 return 0;
0805 }
0806 virtual TiXmlText* ToText() {
0807 return 0;
0808 }
0809 virtual TiXmlDeclaration* ToDeclaration() {
0810 return 0;
0811 }
0812
0813
0814
0815
0816 virtual TiXmlNode* Clone() const = 0;
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833
0834
0835
0836
0837
0838
0839
0840 virtual bool Accept(TiXmlVisitor* visitor) const = 0;
0841
0842 protected:
0843 TiXmlNode(NodeType _type);
0844
0845
0846
0847 void CopyTo(TiXmlNode* target) const;
0848
0849 #ifdef TIXML_USE_STL
0850
0851 virtual void StreamIn(std::istream* in, TIXML_STRING* tag) = 0;
0852 #endif
0853
0854
0855 TiXmlNode* Identify(const char* start, TiXmlEncoding encoding);
0856
0857 TiXmlNode* parent;
0858 NodeType type;
0859
0860 TiXmlNode* firstChild;
0861 TiXmlNode* lastChild;
0862
0863 TIXML_STRING value;
0864
0865 TiXmlNode* prev;
0866 TiXmlNode* next;
0867
0868 private:
0869 TiXmlNode(const TiXmlNode&);
0870 void operator=(const TiXmlNode& base);
0871 };
0872
0873
0874
0875
0876
0877
0878
0879
0880 class TiXmlAttribute: public TiXmlBase {
0881 friend class TiXmlAttributeSet;
0882
0883 public:
0884
0885 TiXmlAttribute()
0886 : TiXmlBase() {
0887 document = 0;
0888 prev = next = 0;
0889 }
0890
0891 #ifdef TIXML_USE_STL
0892
0893 TiXmlAttribute(const std::string& _name, const std::string& _value) {
0894 name = _name;
0895 value = _value;
0896 document = 0;
0897 prev = next = 0;
0898 }
0899 #endif
0900
0901
0902 TiXmlAttribute(const char * _name, const char * _value) {
0903 name = _name;
0904 value = _value;
0905 document = 0;
0906 prev = next = 0;
0907 }
0908
0909 const char* Name() const {
0910 return name.c_str();
0911 }
0912 const char* Value() const {
0913 return value.c_str();
0914 }
0915 #ifdef TIXML_USE_STL
0916 const std::string& ValueStr() const {
0917 return value;
0918 }
0919 #endif
0920 int IntValue() const;
0921 double DoubleValue() const;
0922
0923
0924 const TIXML_STRING& NameTStr() const {
0925 return name;
0926 }
0927
0928
0929
0930
0931
0932
0933
0934
0935
0936
0937 int QueryIntValue(int* _value) const;
0938
0939 int QueryDoubleValue(double* _value) const;
0940
0941 void SetName(const char* _name) {
0942 name = _name;
0943 }
0944 void SetValue(const char* _value) {
0945 value = _value;
0946 }
0947
0948 void SetIntValue(int _value);
0949 void SetDoubleValue(double _value);
0950
0951 #ifdef TIXML_USE_STL
0952
0953 void SetName(const std::string& _name) {
0954 name = _name;
0955 }
0956
0957 void SetValue(const std::string& _value) {
0958 value = _value;
0959 }
0960 #endif
0961
0962
0963 const TiXmlAttribute* Next() const;
0964 TiXmlAttribute* Next() {
0965 return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttribute*>(this))->Next());
0966 }
0967
0968
0969 const TiXmlAttribute* Previous() const;
0970 TiXmlAttribute* Previous() {
0971 return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttribute*>(this))->Previous());
0972 }
0973
0974 bool operator==(const TiXmlAttribute& rhs) const {
0975 return rhs.name == name;
0976 }
0977 bool operator<(const TiXmlAttribute& rhs) const {
0978 return name < rhs.name;
0979 }
0980 bool operator>(const TiXmlAttribute& rhs) const {
0981 return name > rhs.name;
0982 }
0983
0984
0985
0986
0987 virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) override;
0988
0989
0990 virtual void Print(FILE* cfile, int depth) const override {
0991 Print(cfile, depth, 0);
0992 }
0993 void Print(FILE* cfile, int depth, TIXML_STRING* str) const;
0994
0995
0996
0997 void SetDocument(TiXmlDocument* doc) {
0998 document = doc;
0999 }
1000
1001 private:
1002 TiXmlAttribute(const TiXmlAttribute&);
1003 void operator=(const TiXmlAttribute& base);
1004
1005 TiXmlDocument* document;
1006 TIXML_STRING name;TIXML_STRING value;
1007 TiXmlAttribute* prev;
1008 TiXmlAttribute* next;
1009 };
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023 class TiXmlAttributeSet {
1024 public:
1025 TiXmlAttributeSet();
1026 ~TiXmlAttributeSet();
1027
1028 void Add(TiXmlAttribute* attribute);
1029 void Remove(TiXmlAttribute* attribute);
1030
1031 const TiXmlAttribute* First() const {
1032 return (sentinel.next == &sentinel) ? 0 : sentinel.next;
1033 }
1034 TiXmlAttribute* First() {
1035 return (sentinel.next == &sentinel) ? 0 : sentinel.next;
1036 }
1037 const TiXmlAttribute* Last() const {
1038 return (sentinel.prev == &sentinel) ? 0 : sentinel.prev;
1039 }
1040 TiXmlAttribute* Last() {
1041 return (sentinel.prev == &sentinel) ? 0 : sentinel.prev;
1042 }
1043
1044 const TiXmlAttribute* Find(const char* _name) const;
1045 TiXmlAttribute* Find(const char* _name) {
1046 return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttributeSet*>(this))->Find(_name));
1047 }
1048 #ifdef TIXML_USE_STL
1049 const TiXmlAttribute* Find(const std::string& _name) const;
1050 TiXmlAttribute* Find(const std::string& _name) {
1051 return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttributeSet*>(this))->Find(_name));
1052 }
1053
1054 #endif
1055
1056 private:
1057
1058
1059 TiXmlAttributeSet(const TiXmlAttributeSet&);
1060 void operator=(const TiXmlAttributeSet&);
1061
1062 TiXmlAttribute sentinel;
1063 };
1064
1065
1066
1067
1068
1069 class TiXmlElement: public TiXmlNode {
1070 public:
1071
1072 TiXmlElement(const char * in_value);
1073
1074 #ifdef TIXML_USE_STL
1075
1076 TiXmlElement(const std::string& _value);
1077 #endif
1078
1079 TiXmlElement(const TiXmlElement&);
1080
1081 void operator=(const TiXmlElement& base);
1082
1083 virtual ~TiXmlElement();
1084
1085
1086
1087
1088 const TiXmlAttribute* AttributeNode(const char* name) const {
1089 return attributeSet.Find(name);
1090 }
1091
1092
1093
1094
1095 const char* Attribute(const char* name) const;
1096
1097
1098
1099 void ClearAttributes();
1100
1101
1102
1103
1104
1105
1106
1107 const char* Attribute(const char* name, int* i) const;
1108
1109
1110
1111
1112
1113
1114
1115 const char* Attribute(const char* name, double* d) const;
1116
1117
1118
1119
1120
1121
1122
1123
1124 int QueryIntAttribute(const char* name, int* _value) const;
1125
1126 int QueryDoubleAttribute(const char* name, double* _value) const;
1127
1128 int QueryFloatAttribute(const char* name, float* _value) const {
1129 double d;
1130 int result = QueryDoubleAttribute(name, &d);
1131 if (result == TIXML_SUCCESS) {
1132 *_value = (float) d;
1133 }
1134 return result;
1135 }
1136 #ifdef TIXML_USE_STL
1137
1138
1139
1140
1141
1142
1143 template <typename T> int QueryValueAttribute(const std::string& name, T* outValue) const {
1144 const TiXmlAttribute* node = attributeSet.Find(name);
1145 if (!node)
1146 return TIXML_NO_ATTRIBUTE;
1147
1148 std::stringstream sstream(node->ValueStr());
1149 sstream >> *outValue;
1150 if (!sstream.fail())
1151 return TIXML_SUCCESS;
1152 return TIXML_WRONG_TYPE;
1153 }
1154 #endif
1155
1156
1157
1158
1159 void SetAttribute(const char* name, const char * _value);
1160
1161 #ifdef TIXML_USE_STL
1162 const std::string* Attribute(const std::string& name) const;
1163 const std::string* Attribute(const std::string& name, int* i) const;
1164 const std::string* Attribute(const std::string& name, double* d) const;
1165 int QueryIntAttribute(const std::string& name, int* _value) const;
1166 int QueryDoubleAttribute(const std::string& name, double* _value) const;
1167
1168
1169 void SetAttribute(const std::string& name, const std::string& _value);
1170
1171 void SetAttribute(const std::string& name, int _value);
1172 #endif
1173
1174
1175
1176
1177 void SetAttribute(const char * name, int value);
1178
1179
1180
1181
1182 void SetDoubleAttribute(const char * name, double value);
1183
1184
1185
1186 void RemoveAttribute(const char * name);
1187 #ifdef TIXML_USE_STL
1188 void RemoveAttribute(const std::string& name) {
1189 RemoveAttribute(name.c_str());
1190 }
1191 #endif
1192
1193 const TiXmlAttribute* FirstAttribute() const {
1194 return attributeSet.First();
1195 }
1196 TiXmlAttribute* FirstAttribute() {
1197 return attributeSet.First();
1198 }
1199 const TiXmlAttribute* LastAttribute() const {
1200 return attributeSet.Last();
1201 }
1202 TiXmlAttribute* LastAttribute() {
1203 return attributeSet.Last();
1204 }
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238 const char* GetText() const;
1239
1240
1241 virtual TiXmlNode* Clone() const override;
1242
1243 virtual void Print(FILE* cfile, int depth) const override;
1244
1245
1246
1247
1248 virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) override;
1249
1250 virtual const TiXmlElement* ToElement() const override {
1251 return this;
1252 }
1253 virtual TiXmlElement* ToElement() override {
1254 return this;
1255 }
1256
1257
1258
1259 virtual bool Accept(TiXmlVisitor* visitor) const override;
1260
1261 protected:
1262
1263 void CopyTo(TiXmlElement* target) const;
1264 void ClearThis();
1265
1266
1267 #ifdef TIXML_USE_STL
1268 virtual void StreamIn(std::istream * in, TIXML_STRING * tag) override;
1269 #endif
1270
1271
1272
1273
1274 const char* ReadValue(const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding);
1275
1276 private:
1277
1278 TiXmlAttributeSet attributeSet;
1279 };
1280
1281
1282
1283 class TiXmlComment: public TiXmlNode {
1284 public:
1285
1286 TiXmlComment()
1287 : TiXmlNode(TiXmlNode::COMMENT) {
1288 }
1289
1290 TiXmlComment(const char* _value)
1291 : TiXmlNode(TiXmlNode::COMMENT) {
1292 SetValue(_value);
1293 }
1294 TiXmlComment(const TiXmlComment&);
1295 void operator=(const TiXmlComment& base);
1296
1297 virtual ~TiXmlComment() {
1298 }
1299
1300
1301 virtual TiXmlNode* Clone() const override;
1302
1303 virtual void Print(FILE* cfile, int depth) const override;
1304
1305
1306
1307
1308 virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) override;
1309
1310 virtual const TiXmlComment* ToComment() const override {
1311 return this;
1312 }
1313 virtual TiXmlComment* ToComment() override {
1314 return this;
1315 }
1316
1317
1318
1319 virtual bool Accept(TiXmlVisitor* visitor) const override;
1320
1321 protected:
1322 void CopyTo(TiXmlComment* target) const;
1323
1324
1325 #ifdef TIXML_USE_STL
1326 virtual void StreamIn(std::istream * in, TIXML_STRING * tag) override;
1327 #endif
1328
1329
1330 private:
1331
1332 };
1333
1334
1335
1336
1337
1338
1339 class TiXmlText: public TiXmlNode {
1340 friend class TiXmlElement;
1341 public:
1342
1343
1344
1345
1346 TiXmlText(const char * initValue)
1347 : TiXmlNode(TiXmlNode::TEXT) {
1348 SetValue(initValue);
1349 cdata = false;
1350 }
1351 virtual ~TiXmlText() {
1352 }
1353
1354 #ifdef TIXML_USE_STL
1355
1356 TiXmlText(const std::string& initValue)
1357 : TiXmlNode(TiXmlNode::TEXT) {
1358 SetValue(initValue);
1359 cdata = false;
1360 }
1361 #endif
1362
1363 TiXmlText(const TiXmlText& copy)
1364 : TiXmlNode(TiXmlNode::TEXT) {
1365 copy.CopyTo(this);
1366 }
1367 void operator=(const TiXmlText& base) {
1368 base.CopyTo(this);
1369 }
1370
1371
1372 virtual void Print(FILE* cfile, int depth) const override;
1373
1374
1375 bool CDATA() const {
1376 return cdata;
1377 }
1378
1379 void SetCDATA(bool _cdata) {
1380 cdata = _cdata;
1381 }
1382
1383 virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) override;
1384
1385 virtual const TiXmlText* ToText() const override {
1386 return this;
1387 }
1388 virtual TiXmlText* ToText() override {
1389 return this;
1390 }
1391
1392
1393
1394 virtual bool Accept(TiXmlVisitor* content) const override;
1395
1396 protected:
1397
1398 virtual TiXmlNode* Clone() const override;
1399 void CopyTo(TiXmlText* target) const;
1400
1401 bool Blank() const;
1402
1403 #ifdef TIXML_USE_STL
1404 virtual void StreamIn(std::istream * in, TIXML_STRING * tag) override;
1405 #endif
1406
1407 private:
1408 bool cdata;
1409 };
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424 class TiXmlDeclaration: public TiXmlNode {
1425 public:
1426
1427 TiXmlDeclaration()
1428 : TiXmlNode(TiXmlNode::DECLARATION) {
1429 }
1430
1431 #ifdef TIXML_USE_STL
1432
1433 TiXmlDeclaration(const std::string& _version, const std::string& _encoding, const std::string& _standalone);
1434 #endif
1435
1436
1437 TiXmlDeclaration(const char* _version, const char* _encoding, const char* _standalone);
1438
1439 TiXmlDeclaration(const TiXmlDeclaration& copy);
1440 void operator=(const TiXmlDeclaration& copy);
1441
1442 virtual ~TiXmlDeclaration() {
1443 }
1444
1445
1446 const char *Version() const {
1447 return version.c_str();
1448 }
1449
1450 const char *Encoding() const {
1451 return encoding.c_str();
1452 }
1453
1454 const char *Standalone() const {
1455 return standalone.c_str();
1456 }
1457
1458
1459 virtual TiXmlNode* Clone() const override;
1460
1461 virtual void Print(FILE* cfile, int depth, TIXML_STRING* str) const;
1462 virtual void Print(FILE* cfile, int depth) const override {
1463 Print(cfile, depth, 0);
1464 }
1465
1466 virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) override;
1467
1468 virtual const TiXmlDeclaration* ToDeclaration() const override {
1469 return this;
1470 }
1471 virtual TiXmlDeclaration* ToDeclaration() override {
1472 return this;
1473 }
1474
1475
1476
1477 virtual bool Accept(TiXmlVisitor* visitor) const override;
1478
1479 protected:
1480 void CopyTo(TiXmlDeclaration* target) const;
1481
1482 #ifdef TIXML_USE_STL
1483 virtual void StreamIn(std::istream * in, TIXML_STRING * tag) override;
1484 #endif
1485
1486 private:
1487
1488 TIXML_STRING version;TIXML_STRING encoding;TIXML_STRING standalone;
1489 };
1490
1491
1492
1493
1494
1495
1496
1497
1498 class TiXmlUnknown: public TiXmlNode {
1499 public:
1500 TiXmlUnknown()
1501 : TiXmlNode(TiXmlNode::UNKNOWN) {
1502 }
1503 virtual ~TiXmlUnknown() {
1504 }
1505
1506 TiXmlUnknown(const TiXmlUnknown& copy)
1507 : TiXmlNode(TiXmlNode::UNKNOWN) {
1508 copy.CopyTo(this);
1509 }
1510 void operator=(const TiXmlUnknown& copy) {
1511 copy.CopyTo(this);
1512 }
1513
1514
1515 virtual TiXmlNode* Clone() const override;
1516
1517 virtual void Print(FILE* cfile, int depth) const override;
1518
1519 virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) override;
1520
1521 virtual const TiXmlUnknown* ToUnknown() const override {
1522 return this;
1523 }
1524 virtual TiXmlUnknown* ToUnknown() override{
1525 return this;
1526 }
1527
1528
1529
1530 virtual bool Accept(TiXmlVisitor* content) const override;
1531
1532 protected:
1533 void CopyTo(TiXmlUnknown* target) const;
1534
1535 #ifdef TIXML_USE_STL
1536 virtual void StreamIn(std::istream * in, TIXML_STRING * tag) override;
1537 #endif
1538
1539 private:
1540
1541 };
1542
1543
1544
1545
1546
1547 class TiXmlDocument: public TiXmlNode {
1548 public:
1549
1550 TiXmlDocument();
1551
1552 TiXmlDocument(const char * documentName);
1553
1554 #ifdef TIXML_USE_STL
1555
1556 TiXmlDocument(const std::string& documentName);
1557 #endif
1558
1559 TiXmlDocument(const TiXmlDocument& copy);
1560 void operator=(const TiXmlDocument& copy);
1561
1562 virtual ~TiXmlDocument() {
1563 }
1564
1565
1566
1567
1568
1569 bool LoadFile(TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
1570
1571 bool SaveFile() const;
1572
1573 bool LoadFile(const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
1574
1575 bool SaveFile(const char * filename) const;
1576
1577
1578
1579
1580
1581 bool LoadFile(FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
1582
1583 bool SaveFile(FILE*) const;
1584
1585 #ifdef TIXML_USE_STL
1586 bool LoadFile(const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING)
1587 {
1588
1589
1590 return LoadFile(filename.c_str(), encoding);
1591 }
1592 bool SaveFile(const std::string& filename) const
1593 {
1594
1595
1596 return SaveFile(filename.c_str());
1597 }
1598 #endif
1599
1600
1601
1602
1603
1604 virtual const char* Parse(const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING) override;
1605
1606
1607
1608
1609
1610 const TiXmlElement* RootElement() const {
1611 return FirstChildElement();
1612 }
1613 TiXmlElement* RootElement() {
1614 return FirstChildElement();
1615 }
1616
1617
1618
1619
1620
1621
1622 bool Error() const {
1623 return error;
1624 }
1625
1626
1627 const char * ErrorDesc() const {
1628 return errorDesc.c_str();
1629 }
1630
1631
1632
1633
1634 int ErrorId() const {
1635 return errorId;
1636 }
1637
1638
1639
1640
1641
1642
1643
1644
1645 int ErrorRow() const {
1646 return errorLocation.row + 1;
1647 }
1648 int ErrorCol() const {
1649 return errorLocation.col + 1;
1650 }
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676 void SetTabSize(int _tabsize) {
1677 tabsize = _tabsize;
1678 }
1679
1680 int TabSize() const {
1681 return tabsize;
1682 }
1683
1684
1685
1686
1687 void ClearError() {
1688 error = false;
1689 errorId = 0;
1690 errorDesc = "";
1691 errorLocation.row = errorLocation.col = 0;
1692
1693 }
1694
1695
1696 void Print() const {
1697 Print(stdout, 0);
1698 }
1699
1700
1701
1702
1703
1704
1705
1706 virtual void Print(FILE* cfile, int depth = 0) const override;
1707
1708 void SetError(int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding);
1709
1710 virtual const TiXmlDocument* ToDocument() const override {
1711 return this;
1712 }
1713 virtual TiXmlDocument* ToDocument() override {
1714 return this;
1715 }
1716
1717
1718
1719 virtual bool Accept(TiXmlVisitor* content) const override;
1720
1721 protected:
1722
1723 virtual TiXmlNode* Clone() const override;
1724 #ifdef TIXML_USE_STL
1725 virtual void StreamIn(std::istream * in, TIXML_STRING * tag) override;
1726 #endif
1727
1728 private:
1729 void CopyTo(TiXmlDocument* target) const;
1730
1731 bool error;
1732 int errorId;TIXML_STRING errorDesc;
1733 int tabsize;
1734 TiXmlCursor errorLocation;
1735 bool useMicrosoftBOM;
1736 };
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818 class TiXmlHandle_t {
1819 public:
1820
1821 TiXmlHandle_t(TiXmlNode* _node) {
1822 this->node = _node;
1823 }
1824
1825 TiXmlHandle_t(const TiXmlHandle_t& ref) {
1826 this->node = ref.node;
1827 }
1828 TiXmlHandle_t operator=(const TiXmlHandle_t& ref) {
1829 this->node = ref.node;
1830 return *this;
1831 }
1832
1833
1834 TiXmlHandle_t FirstChild() const;
1835
1836 TiXmlHandle_t FirstChild(const char * value) const;
1837
1838 TiXmlHandle_t FirstChildElement() const;
1839
1840 TiXmlHandle_t FirstChildElement(const char * value) const;
1841
1842
1843
1844
1845 TiXmlHandle_t Child(const char* value, int index) const;
1846
1847
1848
1849 TiXmlHandle_t Child(int index) const;
1850
1851
1852
1853
1854 TiXmlHandle_t ChildElement(const char* value, int index) const;
1855
1856
1857
1858
1859 TiXmlHandle_t ChildElement(int index) const;
1860
1861 #ifdef TIXML_USE_STL
1862 TiXmlHandle_t FirstChild(const std::string& _value) const {
1863 return FirstChild(_value.c_str());
1864 }
1865 TiXmlHandle_t FirstChildElement(const std::string& _value) const {
1866 return FirstChildElement(_value.c_str());
1867 }
1868
1869 TiXmlHandle_t Child(const std::string& _value, int index) const {
1870 return Child(_value.c_str(), index);
1871 }
1872 TiXmlHandle_t ChildElement(const std::string& _value, int index) const {
1873 return ChildElement(_value.c_str(), index);
1874 }
1875 #endif
1876
1877
1878
1879 TiXmlNode* ToNode() const {
1880 return node;
1881 }
1882
1883
1884 TiXmlElement* ToElement() const {
1885 return ((node && node->ToElement()) ? node->ToElement() : 0);
1886 }
1887
1888
1889 TiXmlText* ToText() const {
1890 return ((node && node->ToText()) ? node->ToText() : 0);
1891 }
1892
1893
1894 TiXmlUnknown* ToUnknown() const {
1895 return ((node && node->ToUnknown()) ? node->ToUnknown() : 0);
1896 }
1897
1898
1899
1900
1901 TiXmlNode* Node() const {
1902 return ToNode();
1903 }
1904
1905
1906
1907 TiXmlElement* Element() const {
1908 return ToElement();
1909 }
1910
1911
1912
1913 TiXmlText* Text() const {
1914 return ToText();
1915 }
1916
1917
1918
1919 TiXmlUnknown* Unknown() const {
1920 return ToUnknown();
1921 }
1922
1923 private:
1924 TiXmlNode* node;
1925 };
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946 class TiXmlPrinter: public TiXmlVisitor {
1947 public:
1948 TiXmlPrinter()
1949 : depth(0), simpleTextPrint(false), buffer(), indent(" "), lineBreak("\n") {
1950 }
1951
1952 virtual bool VisitEnter(const TiXmlDocument& doc) override;
1953 virtual bool VisitExit(const TiXmlDocument& doc) override;
1954
1955 virtual bool VisitEnter(const TiXmlElement& element, const TiXmlAttribute* firstAttribute) override;
1956 virtual bool VisitExit(const TiXmlElement& element) override;
1957
1958 virtual bool Visit(const TiXmlDeclaration& declaration) override;
1959 virtual bool Visit(const TiXmlText& text) override;
1960 virtual bool Visit(const TiXmlComment& comment) override;
1961 virtual bool Visit(const TiXmlUnknown& unknown) override;
1962
1963
1964
1965
1966 void SetIndent(const char* _indent) {
1967 indent = _indent ? _indent : "";
1968 }
1969
1970 const char* Indent() {
1971 return indent.c_str();
1972 }
1973
1974
1975
1976
1977 void SetLineBreak(const char* _lineBreak) {
1978 lineBreak = _lineBreak ? _lineBreak : "";
1979 }
1980
1981 const char* LineBreak() {
1982 return lineBreak.c_str();
1983 }
1984
1985
1986
1987
1988 void SetStreamPrinting() {
1989 indent = "";
1990 lineBreak = "";
1991 }
1992
1993 const char* CStr() {
1994 return buffer.c_str();
1995 }
1996
1997 size_t Size() {
1998 return buffer.size();
1999 }
2000
2001 #ifdef TIXML_USE_STL
2002
2003 const std::string& Str() {
2004 return buffer;
2005 }
2006 #endif
2007
2008 private:
2009 void DoIndent() {
2010 for (int i = 0; i < depth; ++i)
2011 buffer += indent;
2012 }
2013 void DoLineBreak() {
2014 buffer += lineBreak;
2015 }
2016
2017 int depth;
2018 bool simpleTextPrint;TIXML_STRING buffer;TIXML_STRING indent;TIXML_STRING lineBreak;
2019 };
2020
2021 #ifdef _MSC_VER
2022 #pragma warning( pop )
2023 #endif
2024
2025 #endif
2026
2027
2028 #endif