Updated German translation
[dasher.git] / Src / DasherCore / XMLUtil.h
blob72ca8108a7e1d32f36b60c61682e6e5479028b8b
2 // Some very simple XML utility functions that just function on STL strings.
3 //
4 // Good for recursively splitting up the job of reinstatiating objects
5 // that have been serialized to an XML file.
6 //
7 // Copyright 2005 by Keith Vertanen
9 #ifndef __XML_UTIL_H__
10 #define __XML_UTIL_H__
12 #include <cstdlib>
13 #include <string>
14 #include <vector>
15 #include <stdio.h>
16 #include "FileLogger.h"
18 extern CFileLogger* gLogger;
20 using namespace std;
22 #ifndef VECTOR_STRING
23 typedef vector<string> VECTOR_STRING;
24 #endif
25 #ifndef VECTOR_STRING_ITER
26 typedef vector<string>::iterator VECTOR_STRING_ITER;
27 #endif
29 // We want to be able grab all the name/value pairs in XML like:
30 // <Params>
31 // <Color>red</Color>
32 // <Size>10</Size>
33 // </Params>
34 struct NameValuePair
36 string strName;
37 string strValue;
40 typedef vector<NameValuePair> VECTOR_NAME_VALUE_PAIR;
41 typedef vector<NameValuePair>::iterator VECTOR_NAME_VALUE_PAIR_ITER;
43 const int XML_UTIL_READ_BUFFER_SIZE = 4096;
44 const int XML_UTIL_DEFAULT_VECTOR_SIZE = 128;
45 /// \ingroup Logging
46 /// @{
47 class XMLUtil
49 public:
50 XMLUtil();
52 static string LoadFile(const string& filename, unsigned int iSizeHint = 128000);
53 static string GetElementString(const string& strTag, const string& strXML, bool bStripWhiteSpace = true);
54 static int GetElementInt(const string& strTag, const string& strXML, bool* pFound = NULL);
55 static int64 GetElementLongLong(const string& strTag, const string& strXML, bool* pFound = NULL);
56 static float GetElementFloat(const string& strTag, const string& strXML, bool* pFound = NULL);
57 static VECTOR_STRING GetElementStrings(const string& strTag, const string& strXML, bool bStripWhiteSpace = true);
58 static VECTOR_NAME_VALUE_PAIR GetNameValuePairs(const string& strXML, bool bStripWhiteSpace = true);
60 static bool IsWhiteSpace(char cLetter);
61 static string StripWhiteSpace(const string& strText);
62 static bool IsDigit(char cLetter);
65 /// @}
67 #endif