00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #if !defined(TIXML_USE_STL)
00027 #define TIXML_USE_STL
00028 #endif
00029 #include "tinyxml.h"
00030
00031 #ifdef WIN32
00032
00033 #pragma warning(disable : 4100) // unreferenced formal parameter
00034 #pragma warning(disable : 4511) // copy constructor could not be generated
00035 #pragma warning(disable : 4512) // assignment operator could not be generated
00036
00037 #pragma warning(disable : 4663) // C++ language change: to explicitly specialize class template use the following syntax:
00038 #pragma warning(disable : 4018) // signed/unsigned mismatch
00039 #pragma warning(disable : 4245) // 'initializing' : conversion signed/unsigned mismatch
00040 #endif
00041
00042 #include <stdlib.h>
00043 #include "TinyXmlPlus.h"
00044
00045 #ifndef WIN32
00046
00047 #define stricmp strcasecmp
00048 #endif
00049
00050 const char * GetString(const TiXmlNode * node)
00051 {
00052 const TiXmlNode * node2;
00053 const TiXmlText * text;
00054
00055 if (!node)
00056 return NULL;
00057
00058 node2 = node->FirstChild();
00059 while (node2 && node2->Type() == TiXmlNode::COMMENT)
00060 node2 = node2->NextSibling();
00061
00062 if (!node2)
00063 return NULL;
00064
00065 text = node2->ToText();
00066 if (!text)
00067 return NULL;
00068
00069 return text->Value();
00070 }
00071
00072 long GetLong(const TiXmlNode * node, long def)
00073 {
00074 const char * ptr = GetString(node);
00075 if (ptr == NULL)
00076 return def;
00077 else
00078 return atol(ptr);
00079 }
00080
00081 double GetDouble(const TiXmlNode * node, double def)
00082 {
00083 const char * ptr = GetString(node);
00084 if (ptr == NULL)
00085 return def;
00086 else
00087 return atof(ptr);
00088 }
00089
00090 bool GetBool(const TiXmlNode * node)
00091 {
00092 const char * ptr = GetString(node);
00093 if (ptr && stricmp(ptr, "true") == 0)
00094 return true;
00095 else
00096 return false;
00097 }
00098
00099 TiXmlElement * AddString(TiXmlNode * node, const char * name, const char * str)
00100 {
00101 TiXmlElement * txe = new TiXmlElement(name);
00102 TiXmlText txt(str);
00103 txe->InsertEndChild(txt);
00104 node->LinkEndChild(txe);
00105 return txe;
00106 }
00107
00108 TiXmlElement * AddLong(TiXmlNode * node, const char * name, long num)
00109 {
00110 return AddString(node, name, Long2String(num).c_str());
00111 }
00112
00113 TiXmlElement * AddDouble(TiXmlNode * node, const char * name, double num)
00114 {
00115 return AddString(node, name, Float2String(num).c_str());
00116 }
00117
00118 TiXmlElement * AddBool(TiXmlNode * node, const char * name, bool val)
00119 {
00120 return AddString(node, name, val ? "true" : "false");
00121 }