Various small changes
[dasher.git] / Src / DasherCore / XMLUtil.h
blobc4e5db49d1c1ad89287ea8766695460e72c2bf52
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 <string>
13 #include <vector>
14 #include <stdio.h>
15 #include "FileLogger.h"
17 extern CFileLogger* gLogger;
19 using namespace std;
21 #ifndef VECTOR_STRING
22 typedef vector<string> VECTOR_STRING;
23 #endif
24 #ifndef VECTOR_STRING_ITER
25 typedef vector<string>::iterator VECTOR_STRING_ITER;
26 #endif
28 // We want to be able grab all the name/value pairs in XML like:
29 // <Params>
30 // <Color>red</Color>
31 // <Size>10</Size>
32 // </Params>
33 struct NameValuePair
35 string strName;
36 string strValue;
39 typedef vector<NameValuePair> VECTOR_NAME_VALUE_PAIR;
40 typedef vector<NameValuePair>::iterator VECTOR_NAME_VALUE_PAIR_ITER;
42 const int XML_UTIL_READ_BUFFER_SIZE = 4096;
43 const int XML_UTIL_DEFAULT_VECTOR_SIZE = 128;
45 class XMLUtil
47 public:
48 XMLUtil();
50 static string LoadFile(const string& filename, unsigned int iSizeHint = 128000);
51 static string GetElementString(const string& strTag, const string& strXML, bool bStripWhiteSpace = true);
52 static int GetElementInt(const string& strTag, const string& strXML, bool* pFound = NULL);
53 static int64 GetElementLongLong(const string& strTag, const string& strXML, bool* pFound = NULL);
54 static float GetElementFloat(const string& strTag, const string& strXML, bool* pFound = NULL);
55 static VECTOR_STRING GetElementStrings(const string& strTag, const string& strXML, bool bStripWhiteSpace = true);
56 static VECTOR_NAME_VALUE_PAIR GetNameValuePairs(const string& strXML, bool bStripWhiteSpace = true);
58 static bool IsWhiteSpace(char cLetter);
59 static string StripWhiteSpace(const string& strText);
60 static bool IsDigit(char cLetter);
64 #endif