Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 244 | chris | 1 | #ifndef __XMLPARSER_H__ |
| 2 | #define __XMLPARSER_H__ |
||
| 3 | |||
| 4 | #include "Common.h" |
||
| 5 | |||
| 6 | #include "PerfTimer.h" |
||
| 7 | |||
| 8 | struct PFILE; |
||
| 9 | |||
| 10 | namespace Sexy |
||
| 11 | { |
||
| 12 | |||
| 13 | class XMLParam |
||
| 14 | { |
||
| 15 | public: |
||
| 16 | std::string mKey; |
||
| 17 | std::string mValue; |
||
| 18 | }; |
||
| 19 | |||
| 20 | typedef std::map<SexyString, SexyString> XMLParamMap; |
||
| 21 | typedef std::list<XMLParamMap::iterator> XMLParamMapIteratorList; |
||
| 22 | |||
| 23 | typedef std::vector<wchar_t> XMLParserBuffer; |
||
| 24 | |||
| 25 | class XMLElement |
||
| 26 | { |
||
| 27 | public: |
||
| 28 | enum |
||
| 29 | { |
||
| 30 | TYPE_NONE, |
||
| 31 | TYPE_START, |
||
| 32 | TYPE_END, |
||
| 33 | TYPE_ELEMENT, |
||
| 34 | TYPE_INSTRUCTION, |
||
| 35 | TYPE_COMMENT |
||
| 36 | }; |
||
| 37 | public: |
||
| 38 | |||
| 39 | int mType; |
||
| 40 | SexyString mSection; |
||
| 41 | SexyString mValue; |
||
| 42 | SexyString mInstruction; |
||
| 43 | XMLParamMap mAttributes; |
||
| 44 | XMLParamMapIteratorList mAttributeIteratorList; // stores attribute iterators in their original order |
||
| 45 | }; |
||
| 46 | |||
| 47 | class XMLParser |
||
| 48 | { |
||
| 49 | protected: |
||
| 50 | std::string mFileName; |
||
| 51 | SexyString mErrorText; |
||
| 52 | int mLineNum; |
||
| 53 | PFILE* mFile; |
||
| 54 | bool mHasFailed; |
||
| 55 | bool mAllowComments; |
||
| 56 | XMLParserBuffer mBufferedText; |
||
| 57 | SexyString mSection; |
||
| 58 | bool (XMLParser::*mGetCharFunc)(wchar_t* theChar, bool* error); |
||
| 59 | bool mForcedEncodingType; |
||
| 60 | bool mFirstChar; |
||
| 61 | bool mByteSwap; |
||
| 62 | |||
| 63 | protected: |
||
| 64 | void Fail(const SexyString& theErrorText); |
||
| 65 | void Init(); |
||
| 66 | |||
| 67 | bool AddAttribute(XMLElement* theElement, const SexyString& aAttributeKey, const SexyString& aAttributeValue); |
||
| 68 | |||
| 69 | bool GetAsciiChar(wchar_t* theChar, bool* error); |
||
| 70 | bool GetUTF8Char(wchar_t* theChar, bool* error); |
||
| 71 | bool GetUTF16Char(wchar_t* theChar, bool* error); |
||
| 72 | bool GetUTF16LEChar(wchar_t* theChar, bool* error); |
||
| 73 | bool GetUTF16BEChar(wchar_t* theChar, bool* error); |
||
| 74 | |||
| 75 | public: |
||
| 76 | enum XMLEncodingType |
||
| 77 | { |
||
| 78 | ASCII, |
||
| 79 | UTF_8, |
||
| 80 | UTF_16, |
||
| 81 | UTF_16_LE, |
||
| 82 | UTF_16_BE |
||
| 83 | }; |
||
| 84 | |||
| 85 | public: |
||
| 86 | XMLParser(); |
||
| 87 | virtual ~XMLParser(); |
||
| 88 | |||
| 89 | void SetEncodingType(XMLEncodingType theEncoding); |
||
| 90 | bool OpenFile(const std::string& theFilename); |
||
| 91 | void SetStringSource(const std::wstring& theString); |
||
| 92 | void SetStringSource(const std::string& theString); |
||
| 93 | bool NextElement(XMLElement* theElement); |
||
| 94 | SexyString GetErrorText(); |
||
| 95 | int GetCurrentLineNum(); |
||
| 96 | std::string GetFileName(); |
||
| 97 | |||
| 98 | inline void AllowComments(bool doAllow) { mAllowComments = doAllow; } |
||
| 99 | |||
| 100 | bool HasFailed(); |
||
| 101 | bool EndOfFile(); |
||
| 102 | }; |
||
| 103 | |||
| 104 | }; |
||
| 105 | |||
| 106 | #endif //__XMLPARSER_H__ |