xmlreader.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef _XMLREADER_H
  2. #define _XMLREADER_H
  3. #include <bfc/ptrlist.h>
  4. #include <bfc/string/bfcstring.h>
  5. #include <bfc/stack.h>
  6. #include <bfc/dispatch.h>
  7. #include <api/xml/xmlparams.h>
  8. #include "../xml/ifc_xmlreadercallbackI.h"
  9. #include <api/xml/XMLAutoInclude.h>
  10. class svc_xmlProvider;
  11. typedef enum {
  12. TYPE_CLASS_CALLBACK = 1,
  13. TYPE_STATIC_CALLBACK,
  14. } xmlreader_callbackType;
  15. class XmlReaderCallbackI
  16. {
  17. public:
  18. XmlReaderCallbackI() : handle(NULL) {}
  19. virtual void xmlReaderOnStartElementCallback(const wchar_t *xmltag, skin_xmlreaderparams *params) { }
  20. virtual void xmlReaderOnEndElementCallback(const wchar_t *xmltag) { }
  21. private:
  22. void *handle;
  23. };
  24. class xmlreader_cb_struct
  25. {
  26. public:
  27. xmlreader_cb_struct(const wchar_t *m, xmlreader_callbackType t, XmlReaderCallbackI *cb) : matchstr(m), type(t), callback(cb)
  28. {
  29. matchstr.toupper();
  30. }
  31. StringW matchstr;
  32. xmlreader_callbackType type;
  33. XmlReaderCallbackI * callback;
  34. };
  35. class XmlReader : public ifc_xmlreadercallbackI
  36. {
  37. public:
  38. // matchstr is a regexp string such as "WinampAbstractionLayer/Layer[a-z]"
  39. // or "Winamp*Layer/*/Layout"
  40. void registerCallback(const wchar_t *matchstr, XmlReaderCallbackI *callback);
  41. void registerCallback(const wchar_t *matchstr, void (*static_callback)(int start, const wchar_t *xmltag, skin_xmlreaderparams *params));
  42. void unregisterCallback(void *callback);
  43. // if only_this_class param is specified, only this class will be called back
  44. // returns 1 on success, 0 on error
  45. int loadFile(const wchar_t *filename, const wchar_t *incpath = NULL, int isinclude = 0);
  46. const wchar_t *getIncludePath();
  47. int getNumCallbacks() { return callback_list.getNumItems(); }
  48. private:
  49. void xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
  50. void xmlReaderOnEndElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag);
  51. void xmlReaderOnError(int linenum, int errcode, const wchar_t *errstr);
  52. // int doLoadFile(FILE *fp, svc_xmlProvider *svc, const wchar_t *filename, const wchar_t *incpath);
  53. PtrList<xmlreader_cb_struct> callback_list;
  54. StringW includePath;
  55. XMLAutoInclude *includer;
  56. };
  57. extern XmlReader skinXML;
  58. #endif