1
0

obj_xml.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef NULLSOFT_XML_OBJ_XML_H
  2. #define NULLSOFT_XML_OBJ_XML_H
  3. #include <bfc/dispatch.h>
  4. #include <bfc/platform/types.h>
  5. class ifc_xmlreadercallback;
  6. enum
  7. {
  8. OBJ_XML_SUCCESS=0,
  9. OBJ_XML_FAILURE=1,
  10. OBJ_XML_NOTIMPLEMENTED=2,
  11. /* these two are for backwards compatability. we'll get rid of them eventually so don't use these values */
  12. API_XML_SUCCESS=0,
  13. API_XML_FAILURE=1,
  14. };
  15. class NOVTABLE obj_xml : public Dispatchable
  16. {
  17. public:
  18. void xmlreader_registerCallback(const wchar_t *matchstr, ifc_xmlreadercallback *callback);
  19. void xmlreader_unregisterCallback(ifc_xmlreadercallback *callback);
  20. int xmlreader_open();
  21. int xmlreader_open_namespace();
  22. void xmlreader_oldfeed(const void *data, size_t dataSize); // no error return value, for backwards compat
  23. int xmlreader_feed(const void *data, size_t dataSize); // call with 0, 0 to flush fed data. use at the end of a file
  24. void xmlreader_close();
  25. void xmlreader_interrupt(); // causes parsing of the already-fed data to stop, and picks up with any new data you feed
  26. void xmlreader_resume(); // call resume when you're ready to go back to the already-fed data
  27. void xmlreader_reset(); // call to allow an existing obj_xml object to parse a new file. keeps your existing callbacks
  28. void xmlreader_setEncoding(const wchar_t *encoding); // call to manually set encoding (maybe from HTTP headers)
  29. /** by default, callback matches are not case sensitive.
  30. ** also, the xmlpath value sent to callbacks is convertered to UPPERCASE
  31. ** although this behaviour might not make sense, it is the default for compatability reasons.
  32. ** call this function to make matches case sensitive and to make the object pass you the xmlpath "as-is"
  33. **/
  34. int xmlreader_setCaseSensitive(); // makes the callback matching case sensitive. call this before registering callbacks.
  35. DISPATCH_CODES
  36. {
  37. OBJ_XML_REGISTERCALLBACK = 0,
  38. OBJ_XML_UNREGISTERCALLBACK = 10,
  39. OBJ_XML_OPEN = 20,
  40. OBJ_XML_OPEN2 = 21,
  41. OBJ_XML_OLDFEED =30,
  42. OBJ_XML_FEED = 31,
  43. OBJ_XML_CLOSE = 40,
  44. // OBJ_XML_CLONE = 50,
  45. OBJ_XML_INTERRUPT = 60,
  46. OBJ_XML_RESUME = 70,
  47. OBJ_XML_RESET = 80,
  48. OBJ_XML_SETENCODING = 90,
  49. OBJ_XML_SETCASESENSITIVE=100,
  50. };
  51. };
  52. inline void obj_xml::xmlreader_registerCallback(const wchar_t *matchstr, ifc_xmlreadercallback *callback)
  53. {
  54. _voidcall(OBJ_XML_REGISTERCALLBACK, matchstr, callback);
  55. }
  56. inline void obj_xml::xmlreader_unregisterCallback(ifc_xmlreadercallback *callback)
  57. {
  58. _voidcall(OBJ_XML_UNREGISTERCALLBACK, callback);
  59. }
  60. inline int obj_xml::xmlreader_open()
  61. {
  62. return _call(OBJ_XML_OPEN, (int)OBJ_XML_FAILURE);
  63. }
  64. inline int obj_xml::xmlreader_open_namespace()
  65. {
  66. return _call(OBJ_XML_OPEN2, (int)OBJ_XML_FAILURE);
  67. }
  68. inline void obj_xml::xmlreader_oldfeed(const void *data, size_t dataSize)
  69. {
  70. _voidcall(OBJ_XML_OLDFEED, data, dataSize);
  71. }
  72. inline int obj_xml::xmlreader_feed(const void *data, size_t dataSize)
  73. {
  74. return _call(OBJ_XML_FEED, (int)OBJ_XML_FAILURE, data, dataSize);
  75. }
  76. inline void obj_xml::xmlreader_close()
  77. {
  78. _voidcall(OBJ_XML_CLOSE);
  79. }
  80. inline void obj_xml::xmlreader_interrupt()
  81. {
  82. _voidcall(OBJ_XML_INTERRUPT);
  83. }
  84. inline void obj_xml::xmlreader_resume()
  85. {
  86. _voidcall(OBJ_XML_RESUME);
  87. }
  88. inline void obj_xml::xmlreader_reset()
  89. {
  90. _voidcall(OBJ_XML_RESET);
  91. }
  92. inline void obj_xml::xmlreader_setEncoding(const wchar_t *encoding)
  93. {
  94. _voidcall(OBJ_XML_SETENCODING, encoding);
  95. }
  96. inline int obj_xml::xmlreader_setCaseSensitive()
  97. {
  98. return _call(OBJ_XML_SETCASESENSITIVE, (int)OBJ_XML_NOTIMPLEMENTED);
  99. }
  100. // {3DB2A390-BE91-41f3-BEC6-B736EC7792CA}
  101. static const GUID obj_xmlGUID =
  102. { 0x3db2a390, 0xbe91, 0x41f3, { 0xbe, 0xc6, 0xb7, 0x36, 0xec, 0x77, 0x92, 0xca } };
  103. extern obj_xml *xmlApi;
  104. #endif