as_scriptobject.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2012 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. // Modified by Lasse Öörni for Urho3D
  24. //
  25. // as_scriptobject.h
  26. //
  27. // A generic class for handling script declared structures
  28. //
  29. #ifndef AS_SCRIPTOBJECT_H
  30. #define AS_SCRIPTOBJECT_H
  31. #include "as_config.h"
  32. #include "as_atomic.h"
  33. BEGIN_AS_NAMESPACE
  34. class asCObjectType;
  35. // TODO: Add const overload for GetAddressOfProperty
  36. class asCScriptObject : public asIScriptObject
  37. {
  38. public:
  39. //===================================
  40. // From asIScriptObject
  41. //===================================
  42. asIScriptEngine *GetEngine() const;
  43. // Memory management
  44. int AddRef() const;
  45. int Release() const;
  46. // Type info
  47. int GetTypeId() const;
  48. asIObjectType *GetObjectType() const;
  49. // Class properties
  50. asUINT GetPropertyCount() const;
  51. int GetPropertyTypeId(asUINT prop) const;
  52. const char *GetPropertyName(asUINT prop) const;
  53. void *GetAddressOfProperty(asUINT prop);
  54. int CopyFrom(asIScriptObject *other);
  55. // Urho3D: added userdata
  56. void *SetUserData(void *data);
  57. void *GetUserData() const;
  58. //====================================
  59. // Internal
  60. //====================================
  61. asCScriptObject(asCObjectType *objType, bool doInitialize = true);
  62. virtual ~asCScriptObject();
  63. asCScriptObject &operator=(const asCScriptObject &other);
  64. // GC methods
  65. void Destruct();
  66. int GetRefCount();
  67. void SetFlag();
  68. bool GetFlag();
  69. void EnumReferences(asIScriptEngine *engine);
  70. void ReleaseAllHandles(asIScriptEngine *engine);
  71. // Used for properties
  72. void *AllocateObject(asCObjectType *objType, asCScriptEngine *engine, bool doInitialize);
  73. void FreeObject(void *ptr, asCObjectType *objType, asCScriptEngine *engine);
  74. void CopyObject(void *src, void *dst, asCObjectType *objType, asCScriptEngine *engine);
  75. void CopyHandle(asPWORD *src, asPWORD *dst, asCObjectType *objType, asCScriptEngine *engine);
  76. void CallDestructor();
  77. asCObjectType *objType;
  78. protected:
  79. mutable asCAtomic refCount;
  80. mutable bool gcFlag;
  81. bool isDestructCalled;
  82. // Urho3D: added userdata
  83. void* userData;
  84. };
  85. void ScriptObject_Construct(asCObjectType *objType, asCScriptObject *self);
  86. asCScriptObject &ScriptObject_Assignment(asCScriptObject *other, asCScriptObject *self);
  87. void ScriptObject_ConstructUnitialized(asCObjectType *objType, asCScriptObject *self);
  88. void ScriptObject_Construct_Generic(asIScriptGeneric *gen);
  89. void ScriptObject_Assignment_Generic(asIScriptGeneric *gen);
  90. void RegisterScriptObject(asCScriptEngine *engine);
  91. asIScriptObject *ScriptObjectFactory(const asCObjectType *objType, asCScriptEngine *engine);
  92. END_AS_NAMESPACE
  93. #endif