CCSAXParser.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /****************************************************************************
  2. Copyright (c) 2010 cocos2d-x.org
  3. Copyright (c) 2010 Максим Аксенов
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CCSAXPARSER_H__
  21. #define __CCSAXPARSER_H__
  22. /// @cond DO_NOT_SHOW
  23. #include "platform/CCPlatformConfig.h"
  24. #include "platform/CCCommon.h"
  25. #include <string>
  26. NS_CC_BEGIN
  27. /**
  28. * @addtogroup platform
  29. * @{
  30. */
  31. typedef unsigned char CC_XML_CHAR;
  32. class CC_DLL SAXDelegator
  33. {
  34. public:
  35. virtual ~SAXDelegator() {}
  36. /**
  37. * @js NA
  38. * @lua NA
  39. */
  40. virtual void startElement(void *ctx, const char *name, const char **atts) = 0;
  41. /**
  42. * @js NA
  43. * @lua NA
  44. */
  45. virtual void endElement(void *ctx, const char *name) = 0;
  46. /**
  47. * @js NA
  48. * @lua NA
  49. */
  50. virtual void textHandler(void *ctx, const char *s, size_t len) = 0;
  51. };
  52. class CC_DLL SAXParser
  53. {
  54. SAXDelegator* _delegator;
  55. public:
  56. /**
  57. * @js NA
  58. * @lua NA
  59. */
  60. SAXParser();
  61. /**
  62. * @js NA
  63. * @lua NA
  64. */
  65. ~SAXParser(void);
  66. /**
  67. * @js NA
  68. * @lua NA
  69. */
  70. bool init(const char *encoding);
  71. /**
  72. * @js NA
  73. * @lua NA
  74. */
  75. bool parse(const char* xmlData, size_t dataLength);
  76. /**
  77. * @js NA
  78. * @lua NA
  79. */
  80. bool parse(const std::string& filename);
  81. /**
  82. * New API for performance.
  83. */
  84. bool parseIntrusive(char* xmlData, size_t dataLength);
  85. /**
  86. * @js NA
  87. * @lua NA
  88. */
  89. void setDelegator(SAXDelegator* delegator);
  90. /**
  91. * @js NA
  92. * @lua NA
  93. */
  94. static void startElement(void *ctx, const CC_XML_CHAR *name, const CC_XML_CHAR **atts);
  95. /**
  96. * @js NA
  97. * @lua NA
  98. */
  99. static void endElement(void *ctx, const CC_XML_CHAR *name);
  100. /**
  101. * @js NA
  102. * @lua NA
  103. */
  104. static void textHandler(void *ctx, const CC_XML_CHAR *name, size_t len);
  105. };
  106. // end of platform group
  107. /// @}
  108. NS_CC_END
  109. /// @endcond
  110. #endif //__CCSAXPARSER_H__