svc_collection.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #ifndef _SVC_COLLECTION_H
  2. #define _SVC_COLLECTION_H
  3. #include <bfc/dispatch.h>
  4. #include <bfc/ptrlist.h>
  5. #include <bfc/pair.h>
  6. #include <api/xml/xmlreader.h>
  7. #include <api/service/services.h>
  8. class CollectionElement;
  9. class svc_collectionI;
  10. class NOVTABLE svc_collection : public Dispatchable
  11. {
  12. public:
  13. static FOURCC getServiceType() { return WaSvc::COLLECTION; }
  14. int testTag(const wchar_t *xmltag);
  15. void addElement(const wchar_t *id, const wchar_t *includepath, int removalid, skin_xmlreaderparams *params);
  16. void removeElement(int recored_value);
  17. void removeAllElements();
  18. int getNumElements();
  19. int getNumElementsUnique();
  20. CollectionElement *enumElement(int n, int *ancestor);
  21. CollectionElement *enumElementUnique(int n, int *ancestor);
  22. CollectionElement *getElement(const wchar_t *id, int *ancestor);
  23. CollectionElement *getAncestor(CollectionElement *e);
  24. enum
  25. {
  26. COLLECTION_TESTTAG=10,
  27. COLLECTION_ADDELEMENT=20,
  28. COLLECTION_REMOVEELEMENT=30,
  29. COLLECTION_REMOVEALLELEMENTS=35,
  30. COLLECTION_GETNUMELEMENTS=40,
  31. COLLECTION_GETNUMELEMENTSUNIQUE=50,
  32. COLLECTION_ENUMELEMENT=60,
  33. COLLECTION_ENUMELEMENTUNIQUE=70,
  34. COLLECTION_GETELEMENT=80,
  35. };
  36. };
  37. inline int svc_collection::testTag(const wchar_t *xmltag) {
  38. return _call(COLLECTION_TESTTAG, 0, xmltag);
  39. }
  40. inline void svc_collection::addElement(const wchar_t *id, const wchar_t *includepath, int incrementalremovalid, skin_xmlreaderparams *params) {
  41. _voidcall(COLLECTION_ADDELEMENT, id, includepath, incrementalremovalid, params);
  42. }
  43. inline void svc_collection::removeElement(int removalid) {
  44. _voidcall(COLLECTION_REMOVEELEMENT, removalid);
  45. }
  46. inline void svc_collection::removeAllElements() {
  47. _voidcall(COLLECTION_REMOVEALLELEMENTS);
  48. }
  49. inline int svc_collection::getNumElements() {
  50. return _call(COLLECTION_GETNUMELEMENTS, 0);
  51. }
  52. inline int svc_collection::getNumElementsUnique() {
  53. return _call(COLLECTION_GETNUMELEMENTSUNIQUE, 0);
  54. }
  55. inline CollectionElement *svc_collection::enumElement(int n, int *ancestor) {
  56. return _call(COLLECTION_ENUMELEMENT, (CollectionElement *)NULL, n, ancestor);
  57. }
  58. inline CollectionElement *svc_collection::enumElementUnique(int n, int *ancestor) {
  59. return _call(COLLECTION_ENUMELEMENTUNIQUE, (CollectionElement *)NULL, n, ancestor);
  60. }
  61. inline CollectionElement *svc_collection::getElement(const wchar_t *id, int *ancestor) {
  62. return _call(COLLECTION_GETELEMENT, (CollectionElement *)NULL, id, ancestor);
  63. }
  64. class SortPairString {
  65. public:
  66. static int compareItem(Pair<StringW, StringW> *p1, Pair<StringW, StringW> *p2) {
  67. return WCSICMP(p1->a, p2->a);
  68. }
  69. static int compareAttrib(const wchar_t *attrib, Pair<StringW, StringW> *item) {
  70. return WCSICMP(attrib, item->a);
  71. }
  72. };
  73. class CollectionElement : public Dispatchable {
  74. public:
  75. const wchar_t *getId();
  76. const wchar_t *getParamValue(const wchar_t *param, CollectionElement **item=NULL);
  77. int getParamValueInt(const wchar_t *param);
  78. const wchar_t *getIncludePath(const wchar_t *param=NULL);
  79. CollectionElement *getAncestor();
  80. enum {
  81. COLLECTIONELEMENT_GETID=10,
  82. COLLECTIONELEMENT_GETPARAMVALUE=20,
  83. COLLECTIONELEMENT_GETPARAMVALUEINT=30,
  84. COLLECTIONELEMENT_GETANCESTOR=40,
  85. COLLECTIONELEMENT_GETINCLUDEPATH=50,
  86. };
  87. };
  88. inline const wchar_t *CollectionElement::getId() {
  89. return _call(COLLECTIONELEMENT_GETID, (const wchar_t *)NULL);
  90. }
  91. inline const wchar_t *CollectionElement::getParamValue(const wchar_t *param, CollectionElement **item) {
  92. return _call(COLLECTIONELEMENT_GETPARAMVALUE, (const wchar_t *)NULL, param, item);
  93. }
  94. inline int CollectionElement::getParamValueInt(const wchar_t *param) {
  95. return _call(COLLECTIONELEMENT_GETPARAMVALUEINT, 0, param);
  96. }
  97. inline CollectionElement *CollectionElement::getAncestor() {
  98. return _call(COLLECTIONELEMENT_GETANCESTOR, (CollectionElement *)NULL);
  99. }
  100. inline const wchar_t *CollectionElement::getIncludePath(const wchar_t *param) {
  101. return _call(COLLECTIONELEMENT_GETINCLUDEPATH, (const wchar_t *)NULL, param);
  102. }
  103. class CollectionElementI : public CollectionElement {
  104. public:
  105. CollectionElementI(svc_collectionI *collectionI, const wchar_t *id, skin_xmlreaderparams *params, int seccount, const wchar_t *includepath);
  106. virtual ~CollectionElementI();
  107. virtual const wchar_t *getId();
  108. virtual const wchar_t *getParamValue(const wchar_t *param, CollectionElement **item=NULL);
  109. virtual int getParamValueInt(const wchar_t *param);
  110. virtual CollectionElement *getAncestor();
  111. const wchar_t *getIncludePath(const wchar_t *param=NULL); // null returns last override's include path
  112. int getSecCount();
  113. protected:
  114. RECVS_DISPATCH;
  115. PtrListQuickSorted < Pair < StringW, StringW >, SortPairString > params;
  116. StringW id;
  117. int seccount;
  118. svc_collectionI *collection;
  119. StringW path;
  120. };
  121. class SortCollectionElementsI {
  122. public:
  123. static int compareItem(CollectionElementI *p1, CollectionElementI *p2) {
  124. int r = WCSICMP(p1->getId(), p2->getId());
  125. if (r == 0) {
  126. if (p1->getSecCount() < p2->getSecCount()) return -1;
  127. if (p1->getSecCount() > p2->getSecCount()) return 1;
  128. return 0;
  129. }
  130. return r;
  131. }
  132. static int compareAttrib(const wchar_t *attrib, CollectionElementI *item) {
  133. return WCSICMP(attrib, item->getId());
  134. }
  135. };
  136. // derive from this one
  137. class svc_collectionI : public svc_collection {
  138. public:
  139. svc_collectionI();
  140. virtual ~svc_collectionI();
  141. virtual int testTag(const wchar_t *xmltag)=0;
  142. virtual void addElement(const wchar_t *id, const wchar_t *includepath, int incrementalremovalid, skin_xmlreaderparams *params);
  143. virtual void removeElement(int removalid);
  144. virtual void removeAllElements();
  145. virtual int getNumElements();
  146. virtual int getNumElementsUnique();
  147. virtual CollectionElement *enumElement(int n, int *ancestor);
  148. virtual CollectionElement *enumElementUnique(int n, int *ancestor);
  149. virtual CollectionElement *getElement(const wchar_t *id, int *ancestor);
  150. virtual CollectionElement *getAncestor(CollectionElement *e);
  151. protected:
  152. RECVS_DISPATCH;
  153. PtrListQuickMultiSorted < CollectionElementI, SortCollectionElementsI > elements;
  154. int count;
  155. };
  156. #include <api/service/servicei.h>
  157. template <class T>
  158. class CollectionCreator : public waServiceFactoryTSingle<svc_collection, T> {};
  159. template <wchar_t TAG[]>
  160. class CollectionSvc : public svc_collectionI {
  161. public:
  162. int testTag(const wchar_t *xmltag) {
  163. if (!WCSICMP(xmltag, TAG)) return 1;
  164. return 0;
  165. }
  166. static const char *getServiceName() { return StringPrintf("Collection Service for \"%S\"", TAG); }
  167. };
  168. template <class T>
  169. class CollectionSvc2 : public svc_collectionI {
  170. public:
  171. int testTag(const wchar_t *xmltag) {
  172. if (STRCASEEQL(xmltag, T::collection_getXmlTag())) return 1;
  173. return 0;
  174. }
  175. static const char *getServiceName() { return StringPrintf("Collection Service for \"%S\"", T::collection_getXmlTag()); }
  176. };
  177. #include <api/service/svc_enum.h>
  178. #include <bfc/string/StringW.h>
  179. class CollectionSvcEnum : public SvcEnumT<svc_collection>
  180. {
  181. public:
  182. CollectionSvcEnum(const wchar_t *xmltag) : tag(xmltag) {}
  183. protected:
  184. virtual int testService(svc_collection *svc) {
  185. return (svc->testTag(tag));
  186. }
  187. private:
  188. StringW tag;
  189. };
  190. #endif