1
0

cfgscriptobj.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #ifndef __CFGSCRIPTOBJ_H
  2. #define __CFGSCRIPTOBJ_H
  3. #include <api/script/objects/rootobj.h>
  4. #include <api/script/objcontroller.h>
  5. #include <api/script/scriptobj.h>
  6. #include <bfc/depview.h>
  7. #include <api/service/svcs/svc_scriptobji.h>
  8. #include <api/config/items/attribs.h>
  9. class CfgItem;
  10. class ConfigObject;
  11. class ConfigItemObject;
  12. class ConfigAttributeObject;
  13. extern ScriptObjectController *configController;
  14. extern ScriptObjectController *configItemController;
  15. extern ScriptObjectController *configAttributeController;
  16. enum cfgtypes {
  17. CFG_INT = 0,
  18. CFG_BOOL = 1,
  19. CFG_FLOAT = 2,
  20. CFG_STRING = 3,
  21. };
  22. // -----------------------------------------------------------------------------------------------------
  23. // ScriptObject Provider Service
  24. class ConfigScriptObjectSvc : public svc_scriptObjectI {
  25. public:
  26. ConfigScriptObjectSvc() {};
  27. virtual ~ConfigScriptObjectSvc() {};
  28. static const char *getServiceName() { return "Config maki object"; }
  29. virtual ScriptObjectController *getController(int n);
  30. static void addItemObject(ConfigItemObject *item);
  31. static void addAttrObject(ConfigAttributeObject *attr);
  32. static void removeItemObject(ConfigItemObject *item);
  33. static void removeAttrObject(ConfigAttributeObject *attr);
  34. };
  35. // -----------------------------------------------------------------------------------------------------
  36. // Script classes GUIDS
  37. // {593DBA22-D077-4976-B952-F4713655400B}
  38. static const GUID CONFIG_SCRIPTOBJECT_GUID =
  39. { 0x593dba22, 0xd077, 0x4976, { 0xb9, 0x52, 0xf4, 0x71, 0x36, 0x55, 0x40, 0xb } };
  40. // {D4030282-3AAB-4d87-878D-12326FADFCD5}
  41. static const GUID CONFIGITEM_SCRIPTOBJECT_GUID =
  42. { 0xd4030282, 0x3aab, 0x4d87, { 0x87, 0x8d, 0x12, 0x32, 0x6f, 0xad, 0xfc, 0xd5 } };
  43. // {24DEC283-B76E-4a36-8CCC-9E24C46B6C73}
  44. static const GUID CONFIGATTRIBUTE_SCRIPTOBJECT_GUID =
  45. { 0x24dec283, 0xb76e, 0x4a36, { 0x8c, 0xcc, 0x9e, 0x24, 0xc4, 0x6b, 0x6c, 0x73 } };
  46. // -----------------------------------------------------------------------------------------------------
  47. // ScriptObject Interfaces
  48. // Config
  49. class ConfigObject : public RootObjectInstance {
  50. public:
  51. ConfigObject();
  52. virtual ~ConfigObject();
  53. static scriptVar config_getItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar configitem_name);
  54. static scriptVar config_getItemByGuid(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar configitem_name);
  55. static scriptVar config_newItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar configitem_name, scriptVar guid);
  56. private:
  57. static ConfigItemObject *getItem(const wchar_t *nameorguid, ConfigObject *co);
  58. PtrList<ConfigItemObject> mylist;
  59. static PtrList<CfgItemI> ouraddeditems;
  60. static int numobjects;
  61. };
  62. // ConfigItem
  63. class ConfigItemObject : public RootObjectInstance {
  64. public:
  65. ConfigItemObject(CfgItem *item);
  66. virtual ~ConfigItemObject();
  67. ConfigAttributeObject *getAttribute(const wchar_t *name);
  68. const wchar_t *getGuid() { return guid; }
  69. ConfigAttributeObject *newAttribute(const wchar_t *name, const wchar_t *defval);
  70. CfgItem *getCfgItem() { return item; }
  71. static scriptVar configItem_getAttribute(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar attr_name);
  72. static scriptVar configItem_getGuid(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  73. static scriptVar configItem_newAttribute(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar attr_name, scriptVar defval);
  74. private:
  75. CfgItem *item;
  76. StringW guid;
  77. PtrList<ConfigAttributeObject> mylist;
  78. };
  79. // ConfigAttribute
  80. class ConfigAttributeObject : public RootObjectInstance, public DependentViewerTPtr<CfgItem> {
  81. public:
  82. ConfigAttributeObject(CfgItem *item, const wchar_t *attr, ConfigItemObject *parent);
  83. virtual ~ConfigAttributeObject();
  84. void setData(const wchar_t *data);
  85. const wchar_t *getData();
  86. ConfigItemObject *getParentItem() { return parent; }
  87. const wchar_t *getAttributeName() { return attr; }
  88. void setAutoDelete() { autodelete = 1; }
  89. virtual int viewer_onEvent(CfgItem *item, int event, intptr_t param, void *ptr, size_t ptrlen);
  90. static scriptVar configAttr_getData(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  91. static scriptVar configAttr_setData(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar val);
  92. static scriptVar configAttr_onDataChanged(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  93. static scriptVar configAttr_getParentItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  94. static scriptVar configAttr_getAttributeName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  95. private:
  96. CfgItem *item;
  97. StringW attr;
  98. ConfigItemObject *parent;
  99. int autodelete;
  100. };
  101. // -----------------------------------------------------------------------------------------------------
  102. // ScriptObjectControllers for our script classes
  103. // Config
  104. class ConfigScriptObjectController : public ScriptObjectControllerI {
  105. public:
  106. virtual const wchar_t *getClassName() { return L"Config"; }
  107. virtual const wchar_t *getAncestorClassName() { return L"Object"; }
  108. virtual ScriptObjectController *getAncestorController() { return NULL; }
  109. virtual int getNumFunctions();
  110. virtual const function_descriptor_struct *getExportedFunctions() { return exportedFunction; }
  111. virtual GUID getClassGuid() { return CONFIG_SCRIPTOBJECT_GUID; }
  112. virtual int getInstantiable() { return 0; }
  113. virtual int getReferenceable() { return 0; }
  114. virtual ScriptObject *instantiate();
  115. virtual void destroy(ScriptObject *o);
  116. virtual void *encapsulate(ScriptObject *o);
  117. virtual void deencapsulate(void *o);
  118. private:
  119. static function_descriptor_struct exportedFunction[];
  120. };
  121. // ConfigItem
  122. class ConfigItemScriptObjectController : public ScriptObjectControllerI {
  123. public:
  124. virtual const wchar_t *getClassName() { return L"ConfigItem"; }
  125. virtual const wchar_t *getAncestorClassName() { return L"Object"; }
  126. virtual ScriptObjectController *getAncestorController() { return NULL; }
  127. virtual int getNumFunctions();
  128. virtual const function_descriptor_struct *getExportedFunctions() { return exportedFunction; }
  129. virtual GUID getClassGuid() { return CONFIGITEM_SCRIPTOBJECT_GUID; }
  130. virtual int getInstantiable() { return 0; }
  131. virtual int getReferenceable() { return 1; }
  132. virtual ScriptObject *instantiate() { return NULL; };
  133. virtual void destroy(ScriptObject *o) { };
  134. virtual void *encapsulate(ScriptObject *o) { return NULL; };
  135. virtual void deencapsulate(void *o) { };
  136. private:
  137. static function_descriptor_struct exportedFunction[];
  138. };
  139. // ConfigAttribute
  140. class ConfigAttributeScriptObjectController : public ScriptObjectControllerI {
  141. public:
  142. virtual const wchar_t *getClassName() { return L"ConfigAttribute"; }
  143. virtual const wchar_t *getAncestorClassName() { return L"Object"; }
  144. virtual ScriptObjectController *getAncestorController() { return NULL; }
  145. virtual int getNumFunctions();
  146. virtual const function_descriptor_struct *getExportedFunctions() { return exportedFunction; }
  147. virtual GUID getClassGuid() { return CONFIGATTRIBUTE_SCRIPTOBJECT_GUID; }
  148. virtual int getInstantiable() { return 0; }
  149. virtual int getReferenceable() { return 1; }
  150. virtual ScriptObject *instantiate() { return NULL; };
  151. virtual void destroy(ScriptObject *o) { };
  152. virtual void *encapsulate(ScriptObject *o) { return NULL; };
  153. virtual void deencapsulate(void *o) { };
  154. private:
  155. static function_descriptor_struct exportedFunction[];
  156. };
  157. #endif