1
0

xmlobject.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef __XMLOBJECT_H
  2. #define __XMLOBJECT_H
  3. #include <bfc/nsguid.h>
  4. #include <bfc/ptrlist.h>
  5. #include <bfc/dispatch.h>
  6. #include <bfc/string/StringW.h>
  7. #include <bfc/wasabi_std.h>
  8. #define XML_ATTRIBUTE_IMPLIED 0
  9. #define XML_ATTRIBUTE_REQUIRED 1
  10. class XmlObject : public Dispatchable
  11. {
  12. public:
  13. int setXmlParam(const wchar_t *name, const wchar_t *strvalue);
  14. const wchar_t *getXmlParamValue(int n);
  15. int getXmlParam(const wchar_t *paramname);
  16. enum
  17. {
  18. SETXMLPARAM=10,
  19. GETXMLPARAMVALUE=40,
  20. GETXMLPARAM=50,
  21. };
  22. };
  23. inline int XmlObject::setXmlParam(const wchar_t *name, const wchar_t *strvalue)
  24. {
  25. return _call(SETXMLPARAM, 0, name, strvalue);
  26. }
  27. inline const wchar_t *XmlObject::getXmlParamValue(int n)
  28. {
  29. return _call(GETXMLPARAMVALUE, (const wchar_t *)0, n);
  30. }
  31. inline int XmlObject::getXmlParam(const wchar_t *paramname)
  32. {
  33. return _call(GETXMLPARAM, 0, paramname);
  34. }
  35. class XmlObjectParam
  36. {
  37. public:
  38. XmlObjectParam(int xmlhandle, wchar_t *xmlattribute, int xmlattributeid);
  39. virtual ~XmlObjectParam() {}
  40. const wchar_t *getXmlAttribute()
  41. {
  42. return xmlattributename;
  43. }
  44. int getXmlAttributeId()
  45. {
  46. return attributeid;
  47. }
  48. int getXmlHandle()
  49. {
  50. return handle;
  51. }
  52. void setLastValue(const wchar_t *val)
  53. {
  54. lastvalue = val;
  55. }
  56. const wchar_t *getLastValue()
  57. {
  58. return lastvalue;
  59. }
  60. private:
  61. const wchar_t *xmlattributename;
  62. StringW lastvalue;
  63. int attributeid;
  64. int handle;
  65. };
  66. class XmlObjectParamSort
  67. {
  68. public:
  69. static inline int compareItem(XmlObjectParam *p1, XmlObjectParam*p2)
  70. {
  71. return wcscmp(p1->getXmlAttribute(), p2->getXmlAttribute());
  72. }
  73. static inline int compareAttrib(const wchar_t *attrib, XmlObjectParam *item)
  74. {
  75. return WCSICMP(attrib, item->getXmlAttribute());
  76. }
  77. };
  78. struct XMLParamPair
  79. {
  80. int id;
  81. wchar_t name[64];
  82. };
  83. class XmlObjectI : public XmlObject
  84. {
  85. public:
  86. XmlObjectI();
  87. virtual ~XmlObjectI();
  88. virtual int setXmlParam(const wchar_t *name, const wchar_t *strvalue); // receives from system
  89. virtual int setXmlParamById(int xmlhandle, int xmlattributeid, const wchar_t *name, const wchar_t *strvalue); // distributes to inheritors
  90. virtual const wchar_t *getXmlParamValue(int n);
  91. virtual int getXmlParam(const wchar_t *paramname);
  92. const wchar_t *getXmlParamByName(const wchar_t *paramname);
  93. void addParam(int xmlhandle, XMLParamPair &param, int unused=0);
  94. //void addXmlParam(int xmlhandle, const wchar_t *xmlattribute, int xmlattributeid);
  95. protected:
  96. virtual int onUnknownXmlParam(const wchar_t *param, const wchar_t *value);
  97. int newXmlHandle();
  98. void hintNumberOfParams(int xmlhandle, int params);
  99. private:
  100. XmlObjectParam *enumParam(int n)
  101. {
  102. return params[n];
  103. }
  104. PtrListInsertSorted<XmlObjectParam, XmlObjectParamSort> params;
  105. int handlepos;
  106. protected:
  107. RECVS_DISPATCH;
  108. };
  109. #endif