as_scriptobject.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2011 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. [email protected]
  22. */
  23. //
  24. // as_scriptobject.h
  25. //
  26. // A generic class for handling script declared structures
  27. //
  28. #ifndef AS_SCRIPTOBJECT_H
  29. #define AS_SCRIPTOBJECT_H
  30. #include "as_config.h"
  31. #include "as_atomic.h"
  32. BEGIN_AS_NAMESPACE
  33. class asCObjectType;
  34. // TODO: Add const overload for GetAddressOfProperty
  35. class asCScriptObject : public asIScriptObject
  36. {
  37. public:
  38. //===================================
  39. // From asIScriptObject
  40. //===================================
  41. asIScriptEngine *GetEngine() const;
  42. // Memory management
  43. int AddRef() const;
  44. int Release() const;
  45. // Type info
  46. int GetTypeId() const;
  47. asIObjectType *GetObjectType() const;
  48. // Class properties
  49. asUINT GetPropertyCount() const;
  50. int GetPropertyTypeId(asUINT prop) const;
  51. const char *GetPropertyName(asUINT prop) const;
  52. void *GetAddressOfProperty(asUINT prop);
  53. int CopyFrom(asIScriptObject *other);
  54. //====================================
  55. // Internal
  56. //====================================
  57. asCScriptObject(asCObjectType *objType);
  58. virtual ~asCScriptObject();
  59. asCScriptObject &operator=(const asCScriptObject &other);
  60. // GC methods
  61. void Destruct();
  62. int GetRefCount();
  63. void SetFlag();
  64. bool GetFlag();
  65. void EnumReferences(asIScriptEngine *engine);
  66. void ReleaseAllHandles(asIScriptEngine *engine);
  67. // Used for properties
  68. void *AllocateObject(asCObjectType *objType, asCScriptEngine *engine);
  69. void FreeObject(void *ptr, asCObjectType *objType, asCScriptEngine *engine);
  70. void CopyObject(void *src, void *dst, asCObjectType *objType, asCScriptEngine *engine);
  71. void CopyHandle(asPWORD *src, asPWORD *dst, asCObjectType *objType, asCScriptEngine *engine);
  72. void CallDestructor();
  73. asCObjectType *objType;
  74. protected:
  75. mutable asCAtomic refCount;
  76. mutable bool gcFlag;
  77. bool isDestructCalled;
  78. };
  79. void ScriptObject_Construct(asCObjectType *objType, asCScriptObject *self);
  80. asCScriptObject &ScriptObject_Assignment(asCScriptObject *other, asCScriptObject *self);
  81. void ScriptObject_Construct_Generic(asIScriptGeneric *gen);
  82. void ScriptObject_Assignment_Generic(asIScriptGeneric *gen);
  83. void RegisterScriptObject(asCScriptEngine *engine);
  84. asIScriptObject *ScriptObjectFactory(const asCObjectType *objType, asCScriptEngine *engine);
  85. END_AS_NAMESPACE
  86. #endif