Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cXmlReader.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cXmlReader_H
8 #define _INC_cXmlReader_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #include "cXml.h"
16 
17 namespace GrayLib
18 {
20 
22  {
27 
28  public:
29  cXmlReadVisitor() noexcept
30  {
31  }
32  virtual ~cXmlReadVisitor()
33  {
34  }
35 
36  virtual HRESULT onElementStart(cXmlReader& rReader, const cXmlString& sElement, cXmlAttributeSet& Attribs, bool bEnd)
37  {
42  UNREFERENCED_REFERENCE(rReader); // UNREFERENCED_REFERENCE
43  UNREFERENCED_REFERENCE(sElement);
44  UNREFERENCED_REFERENCE(Attribs);
45  return bEnd ? S_FALSE : S_OK;
46  }
47  virtual HRESULT onText(cXmlReader& rReader, XMLNODE_TYPE eType, const cXmlString& sValue, bool bCDATA)
48  {
53  UNREFERENCED_REFERENCE(rReader);
55  UNREFERENCED_REFERENCE(sValue);
56  UNREFERENCED_PARAMETER(bCDATA);
57  return S_OK;
58  }
59  virtual HRESULT onElementEnd(cXmlReader& rReader, const cXmlString& sElement)
60  {
62  UNREFERENCED_REFERENCE(rReader);
63  UNREFERENCED_REFERENCE(sElement);
64  return S_OK;
65  }
66  };
67 
68  class GRAYLIB_LINK cXmlReader : public cTextReader, public cXml
69  {
75 
76  friend class cXmlNode;
77  typedef cTextReader SUPER_t;
78 
79 #define cXmlNodeTypeDEF(a,b,c) friend class cXml##a;
80 #include "cXmlNodeTypes.tbl"
81 #undef cXmlNodeTypeDEF
82 
83  public:
87  int m_iDepth;
88 
89  private:
92  StrLen_t GetCharSize() const;
93  StrLen_t ParseChar(char* pszValueOut, StrLen_t* piLengthOut);
94  void IncChar(StrLen_t nLen);
95  bool IncChar()
96  {
97  StrLen_t nLen = GetCharSize();
98  if (nLen <= 0)
99  return false;
100  IncChar(nLen);
101  return true;
102  }
103 
104  protected:
107  bool IsAlpha(wchar_t anyByte) const;
108  bool IsAlphaNum(wchar_t anyByte) const;
109  wchar_t ToLower(wchar_t v) const;
110 
111  bool IsStringEqual(const char* pszData, const char* pszEndTag, bool bIgnoreCase = false) const;
112 
113  bool ReadWhitespace();
114 
118  HRESULT ParseName(OUT cXmlString& rsName);
119 
122  HRESULT ParseStringTo(OUT cXmlString& rsText, const char* pszEndTag, bool bIgnoreWhitespace);
123 
126  HRESULT ParseAttrib(OUT cXmlString& sName, OUT cXmlString& sValue);
127  HRESULT ParseAttribSet(OUT cXmlAttributeSet& Attribs);
128 
129  HRESULT ParseDeclaration(OUT cXmlAttributeSet& Attribs);
130  HRESULT ParseUnknown(OUT cXmlString& sValue);
131  HRESULT ParseComment(OUT cXmlString& sValue);
132  HRESULT ParseText(OUT cXmlString& sValue, bool bCDATAExpected);
133 
134  HRESULT ParseNodeType();
135  bool ParseMicrosoftBOM();
136 
137  HRESULT ParseElement(OUT cXmlString& sElement, OUT cXmlAttributeSet& Attribs);
138 
139  HRESULT ParseVisitType(cXmlReadVisitor* pVisitor, XMLNODE_TYPE eNodeType, bool bDoc, bool bCDATA);
140 
141  public:
142  cXmlReader(const char* pszStart="", StrLen_t nLenMax = StrT::k_LEN_MAX, StrLen_t iTabSize = cStrConst::k_TabSize,
143  CXML_ENCODING_TYPE eEncoding = CXML_ENCODING_UNKNOWN, bool bCondenseWhitespace = true);
144  ~cXmlReader();
145 
146  HRESULT ReturnError(HRESULT hRes) const;
147 
148  static CXML_ENCODING_TYPE GRAYCALL GetEncodingEnum(cXmlString sEncoding);
149  static StrLen_t GRAYCALL FixNewLines(char* pszBuffer, StrLen_t nLenInp);
150 
151  void put_CondenseWhitespace(bool bCondense) noexcept
152  {
157  m_bCondenseWhitespace = bCondense;
158  }
159  bool isCondensedWhitespace() const noexcept
160  {
162  return m_bCondenseWhitespace;
163  }
164 
165  HRESULT Parse(cXmlReadVisitor* pVisitor, cXmlString sElementParent);
166  HRESULT Parse(cXmlReadVisitor* pVisitor);
167 
168  HRESULT ParseText(const char* pszText, cXmlReadVisitor* pVisitor);
169  HRESULT ParseStream(cStreamInput& rInp, cXmlReadVisitor* pVisitor);
170  HRESULT ParseFile(const FILECHAR_t* pszXMLFile, cXmlReadVisitor* pVisitor);
171  };
172 }
173 #endif // _INC_cXmlReader_H
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define UNREFERENCED_PARAMETER(P)
< _WIN32 type thing. get rid of stupid warning.
Definition: SysTypes.h:299
#define UNREFERENCED_REFERENCE(x)
Definition: SysTypes.h:318
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cXmlDocument.h:30
Definition: cXmlReader.h:22
virtual ~cXmlReadVisitor()
Definition: cXmlReader.h:32
virtual HRESULT onText(cXmlReader &rReader, XMLNODE_TYPE eType, const cXmlString &sValue, bool bCDATA)
Definition: cXmlReader.h:47
virtual HRESULT onElementStart(cXmlReader &rReader, const cXmlString &sElement, cXmlAttributeSet &Attribs, bool bEnd)
Definition: cXmlReader.h:36
virtual HRESULT onElementEnd(cXmlReader &rReader, const cXmlString &sElement)
Definition: cXmlReader.h:59
cXmlReadVisitor() noexcept
Definition: cXmlReader.h:29
Definition: cXmlReader.h:69
int m_iDepth
Indent depth of reader.
Definition: cXmlReader.h:87
bool isCondensedWhitespace() const noexcept
Definition: cXmlReader.h:159
cTextPos m_PosNode
The cursor at the start of current XMLNODE_TYPE m_Pos. as opposed to cTextReader is the current curso...
Definition: cXmlReader.h:84
CXML_ENCODING_TYPE m_eEncoding
current encoding.
Definition: cXmlReader.h:85
bool m_bCondenseWhitespace
try to preserve Whitespace or not?
Definition: cXmlReader.h:86
void put_CondenseWhitespace(bool bCondense) noexcept
Definition: cXmlReader.h:151
Definition: cIniMap.h:56
static const StrLen_t k_TabSize
default desired spaces for a tab.
Definition: StrConst.h:47
Definition: cStream.h:306
Definition: cTextPos.h:18
Definition: cTextPos.h:107
Definition: cMesh.h:22
class __DECL_IMPORT cXmlReader
Definition: cXmlReader.h:19
CXML_ENCODING_TYPE
Definition: cXml.h:24
@ CXML_ENCODING_UNKNOWN
Definition: cXml.h:27
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
Definition: cXml.h:34
XMLNODE_TYPE
Definition: cXml.h:39
static const StrLen_t k_LEN_MAX
arbitrary max size for Format() etc. NOTE: _MSC_VER says stack frame should be at least 16384
Definition: StrT.h:75