sbitlist.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include <precomp.h>
  2. #include "sbitlist.h"
  3. #include <bfc/bitlist.h>
  4. #include <api/script/script.h>
  5. #include <api/script/scriptmgr.h>
  6. // {87C65778-E743-49fe-85F9-09CC532AFD56}
  7. static const GUID bitlistGuid =
  8. { 0x87c65778, 0xe743, 0x49fe, { 0x85, 0xf9, 0x9, 0xcc, 0x53, 0x2a, 0xfd, 0x56 } };
  9. BitlistScriptController _bitlistController;
  10. BitlistScriptController *bitlistController = &_bitlistController;
  11. // -- Functions table -------------------------------------
  12. function_descriptor_struct BitlistScriptController::exportedFunction[] = {
  13. {L"getItem", 1, (void*)SBitlist::script_vcpu_getitem },
  14. {L"setItem", 2, (void*)SBitlist::script_vcpu_setitem },
  15. {L"setSize", 1, (void*)SBitlist::script_vcpu_setsize },
  16. {L"getSize", 0, (void*)SBitlist::script_vcpu_getsize },
  17. };
  18. // --------------------------------------------------------
  19. const wchar_t *BitlistScriptController::getClassName() {
  20. return L"BitList";
  21. }
  22. const wchar_t *BitlistScriptController::getAncestorClassName() {
  23. return L"Object";
  24. }
  25. ScriptObject *BitlistScriptController::instantiate() {
  26. SBitlist *bl = new SBitlist;
  27. ASSERT(bl != NULL);
  28. return bl->getScriptObject();
  29. }
  30. void BitlistScriptController::destroy(ScriptObject *o)
  31. {
  32. // TODO?
  33. SBitlist *bl = static_cast<SBitlist *>(o->vcpu_getInterface(bitlistGuid));
  34. }
  35. void *BitlistScriptController::encapsulate(ScriptObject *o) {
  36. return NULL; // no encapsulation for bitlist yet
  37. }
  38. void BitlistScriptController::deencapsulate(void *o) {
  39. }
  40. int BitlistScriptController::getNumFunctions() {
  41. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  42. }
  43. const function_descriptor_struct *BitlistScriptController::getExportedFunctions() {
  44. return exportedFunction;
  45. }
  46. GUID BitlistScriptController::getClassGuid() {
  47. return bitlistGuid;
  48. }
  49. //-------------------------------------------------------------------------------------------------------------
  50. SBitlist::SBitlist() {
  51. list = new BitList;
  52. getScriptObject()->vcpu_setInterface(bitlistGuid, (void *)static_cast<SBitlist *>(this));
  53. getScriptObject()->vcpu_setClassName(L"BitList");
  54. getScriptObject()->vcpu_setController(bitlistController);
  55. }
  56. SBitlist::~SBitlist() {
  57. delete list;
  58. }
  59. BitList *SBitlist::getBitList() {
  60. return list;
  61. }
  62. scriptVar SBitlist::script_vcpu_getitem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar n) {
  63. SCRIPT_FUNCTION_INIT;
  64. ASSERT(SOM::isNumeric(&n)); // Compiler shouldn't do this
  65. scriptVar r;
  66. r = SOM::makeVar(SCRIPT_INT);
  67. SBitlist *bl = static_cast<SBitlist *>(o->vcpu_getInterface(bitlistGuid));
  68. if (bl) SOM::assign(&r, bl->getBitList()->getitem(SOM::makeInt(&n)));
  69. return r;
  70. }
  71. scriptVar SBitlist::script_vcpu_setitem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar n, scriptVar v) {
  72. SCRIPT_FUNCTION_INIT;
  73. ASSERT(SOM::isNumeric(&n)); // Compiler shouldn't do this
  74. ASSERT(SOM::isNumeric(&v)); // Compiler shouldn't do this
  75. SBitlist *bl = static_cast<SBitlist *>(o->vcpu_getInterface(bitlistGuid));
  76. if (bl) bl->getBitList()->setitem(SOM::makeInt(&n), SOM::makeBoolean(&v));
  77. RETURN_SCRIPT_VOID;
  78. }
  79. scriptVar SBitlist::script_vcpu_setsize(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar newsize) {
  80. SCRIPT_FUNCTION_INIT;
  81. ASSERT(SOM::isNumeric(&newsize)); // Compiler shouldn't do this
  82. SBitlist *bl = static_cast<SBitlist *>(o->vcpu_getInterface(bitlistGuid));
  83. if (bl) bl->getBitList()->setSize(SOM::makeInt(&newsize));
  84. RETURN_SCRIPT_VOID;
  85. }
  86. scriptVar SBitlist::script_vcpu_getsize(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  87. SCRIPT_FUNCTION_INIT;
  88. scriptVar r;
  89. r = SOM::makeVar(SCRIPT_INT);
  90. SBitlist *bl = static_cast<SBitlist *>(o->vcpu_getInterface(bitlistGuid));
  91. if (bl) SOM::assign(&r, bl->getBitList()->getsize());
  92. return r;
  93. }