1
0

objecttable.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef __OBJECTTABLE
  2. #define __OBJECTTABLE
  3. #ifdef __cplusplus
  4. #include <wasabicfg.h>
  5. #include <bfc/ptrlist.h>
  6. class ScriptObjectController;
  7. #ifdef _NOSTUDIO
  8. //CUT #include "../../scriptcompiler/compiler.h"
  9. //CUT #include "../../scriptcompiler/ctrlblock.h"
  10. #endif
  11. #endif
  12. #include <api/script/vcputypes.h>
  13. #define CLASS_ID_BASE 0x100
  14. #define MAKE_NEW_OBJECT(class, objclass) \
  15. case class: \
  16. s = new objclass; \
  17. objclass::instantiate((objclass *)s); \
  18. break;
  19. // For type names table
  20. typedef struct {
  21. wchar_t *name;
  22. int type;
  23. int instantiable;
  24. int referenceable;
  25. } typenames;
  26. // This is the table that link type names as they are
  27. // recognized in scripts to actual basic types.
  28. // Non instantiable means you can't do v = new <type>
  29. // Non referenceable means you can't do <type> v;
  30. // Not a ref means content is not a reference to an object but rather the actual
  31. // content itself
  32. // * special case for strings which is a ref to a char *, but not an object
  33. #define DEFINE_TYPES \
  34. typenames types[] = { \
  35. {L"", SCRIPT_VOID, 0, 0}, /* Non instantiable, non referenceable */ \
  36. {L"Event", SCRIPT_EVENT, 0, 0}, /* Non instantiable, non referenceable */ \
  37. {L"Int", SCRIPT_INT, 0, 1}, /* Not a ref */ \
  38. {L"Float", SCRIPT_FLOAT, 0, 1}, /* Not a ref */ \
  39. {L"Double", SCRIPT_DOUBLE, 0, 1}, /* Not a ref */ \
  40. {L"Boolean", SCRIPT_BOOLEAN, 0, 1}, /* Not a ref */ \
  41. {L"String", SCRIPT_STRING, 0, 1}, /* Not a ref (* special case) */ \
  42. {L"Any", SCRIPT_ANY, 0, 1}, /* Non instantiable, non referenceable */ \
  43. }; \
  44. int ntypes = sizeof(types)/sizeof(typenames);
  45. extern typenames types[];
  46. extern int ntypes;
  47. #define SVC_CLASS_BASE 1024
  48. #ifdef __cplusplus
  49. class class_entry {
  50. public:
  51. const wchar_t *classname;
  52. int classid;
  53. int ancestorclassid;
  54. ScriptObjectController *controller;
  55. GUID classGuid;
  56. int instantiable;
  57. int referenceable;
  58. int external;
  59. waServiceFactory *sf;
  60. };
  61. typedef struct {
  62. void *ptr;
  63. int nargs;
  64. void *host;
  65. } hostrefstruct;
  66. class SystemObject;
  67. class ObjectTable {
  68. public :
  69. static void start(); // initialize tables, internal objects...
  70. static void shutdown(); // free tables
  71. static void unloadExternalClasses(); // unload external classes
  72. static void loadExternalClasses(); // reload external classes
  73. static int registerClass(ScriptObjectController *c, waServiceFactory *sf = NULL); // returns classid. ancestorclass = 0 = Object
  74. // static void instantiate(ScriptObject *o, int classid);
  75. static int addrefDLF(VCPUdlfEntry *dlf, int id);
  76. static void delrefDLF(VCPUdlfEntry *dlf);
  77. static void resetDLF(VCPUdlfEntry *dlf);
  78. static int getClassFromName(const wchar_t *classname);
  79. static int getClassFromGuid(GUID g);
  80. static const wchar_t *getClassName(int classid);
  81. static int isExternal(int classid);
  82. static int getNumGuids();
  83. static GUID enumGuid(int i);
  84. static const wchar_t *enumClassName(int n);
  85. static int getClassEntryIdx(int classid);
  86. static int isDescendant(int class1, int classid);
  87. static int isClassInstantiable(int classid);
  88. static int isClassReferenceable(int classid);
  89. static ScriptObject *instantiate(int classid);
  90. static void *encapsulate(int classid, ScriptObject *o);
  91. static void destroy(ScriptObject *o);
  92. static void deencapsulate(int classid, void *o);
  93. static const wchar_t *getFunction(int dlfid, int *n, ScriptObjectController **p);
  94. static scriptVar callFunction(ScriptObject *obj, int dlfid, scriptVar **params);
  95. static int dlfAddRef(ScriptObjectController *o, const wchar_t *function_name, void *host);
  96. static int dlfAddRef(ScriptObjectController *o, int i, void *host);
  97. static void dlfAddClassRef(ScriptObjectController *o, void *host);
  98. static void dlfRemRef(void *host);
  99. static int checkScript(SystemObject *o);
  100. static ScriptObjectController *getController(GUID g);
  101. static class_entry *getClassEntry(int classid);
  102. static void unlinkClass(class_entry *e);
  103. #ifdef _NOSTUDIO
  104. static int validateMember(int classid, wchar_t *member, ControlBlock *parms, int *ret);
  105. #endif
  106. private:
  107. static PtrList < class_entry > classes;
  108. static PtrList < hostrefstruct > hostrefs;
  109. static int classidx;
  110. static int externalloaded;
  111. };
  112. #endif
  113. #endif