1
0

xmlInt32Parser.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "./xmlInt32Parser.h"
  2. #include <shlwapi.h>
  3. #include <strsafe.h>
  4. XmlInt32Parser::XmlInt32Parser()
  5. : value(0), result(E_PENDING)
  6. {
  7. memset(szBuffer, 0, sizeof(szBuffer));
  8. }
  9. XmlInt32Parser::~XmlInt32Parser()
  10. {
  11. }
  12. HRESULT XmlInt32Parser::GetValue(INT *pValue)
  13. {
  14. if (NULL == pValue) return E_POINTER;
  15. *pValue = value;
  16. return result;
  17. }
  18. void XmlInt32Parser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
  19. {
  20. szBuffer[0] = L'\0';
  21. result = S_FALSE;
  22. }
  23. void XmlInt32Parser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
  24. {
  25. if (SUCCEEDED(result))
  26. {
  27. if (FALSE == StrToIntEx(szBuffer, STIF_SUPPORT_HEX, &value))
  28. result = E_FAIL;
  29. else
  30. result = S_OK;
  31. }
  32. szBuffer[0] = L'\0';
  33. }
  34. void XmlInt32Parser::Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value)
  35. {
  36. if (SUCCEEDED(result))
  37. {
  38. if (FAILED(StringCchCat(szBuffer, ARRAYSIZE(szBuffer), value)))
  39. result = E_FAIL;
  40. }
  41. }
  42. void XmlInt32Parser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
  43. {
  44. szBuffer[0] = L'\0';
  45. result = E_FAIL;
  46. }
  47. #define CBCLASS XmlInt32Parser
  48. START_DISPATCH;
  49. VCB(ONSTARTELEMENT, Event_XmlStartElement)
  50. VCB(ONENDELEMENT, Event_XmlEndElement)
  51. VCB(ONCHARDATA, Event_XmlCharData)
  52. VCB(ONERROR, Event_XmlError)
  53. END_DISPATCH;
  54. #undef CBCLASS