Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List

TinyXmlPlus.cpp

00001 /*
00002 Copyright 2003 - 2005 Elliott Kleinrock, Dan Neely, Kurt W. Over, Damon Domjan
00003 
00004 This file is part of FreeStars, a free clone of the Stars! game.
00005 
00006 FreeStars is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 FreeStars is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with FreeStars; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 The full GPL Copyright notice should be in the file COPYING.txt
00021 
00022 Contact:
00023 Email Elliott at 9jm0tjj02@sneakemail.com
00024 */
00025 
00026 #if !defined(TIXML_USE_STL)
00027 #define TIXML_USE_STL
00028 #endif
00029 #include "tinyxml.h"
00030 
00031 #ifdef WIN32
00032 // Kill STL warnings
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 // disabling these warnings doesn't seem to work...
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 // For compiling on linux
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 }

Generated on Mon Aug 8 21:33:45 2005 for Freestars by  doxygen 1.4.2-20050421