as_property.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. //
  24. // as_property.h
  25. //
  26. // A class for storing object property information
  27. //
  28. #ifndef AS_PROPERTY_H
  29. #define AS_PROPERTY_H
  30. #include "as_string.h"
  31. #include "as_datatype.h"
  32. #include "as_atomic.h"
  33. #include "as_scriptfunction.h"
  34. #include "as_symboltable.h"
  35. BEGIN_AS_NAMESPACE
  36. struct asSNameSpace;
  37. class asCObjectProperty
  38. {
  39. public:
  40. asCObjectProperty() {accessMask = 0xFFFFFFFF;}
  41. asCString name;
  42. asCDataType type;
  43. int byteOffset;
  44. bool isPrivate;
  45. asDWORD accessMask;
  46. };
  47. class asCGlobalProperty
  48. {
  49. public:
  50. asCGlobalProperty();
  51. ~asCGlobalProperty();
  52. void AddRef();
  53. void Release();
  54. int GetRefCount();
  55. void *GetAddressOfValue();
  56. void AllocateMemory();
  57. void SetRegisteredAddress(void *p);
  58. void *GetRegisteredAddress() const;
  59. asCString name;
  60. asCDataType type;
  61. asUINT id;
  62. asSNameSpace *nameSpace;
  63. void SetInitFunc(asCScriptFunction *initFunc);
  64. asCScriptFunction *GetInitFunc();
  65. static void RegisterGCBehaviours(asCScriptEngine *engine);
  66. //protected:
  67. void SetGCFlag();
  68. bool GetGCFlag();
  69. void EnumReferences(asIScriptEngine *);
  70. void ReleaseAllHandles(asIScriptEngine *);
  71. void Orphan(asCModule *module);
  72. // This is only stored for registered properties, and keeps the pointer given by the application
  73. void *realAddress;
  74. bool memoryAllocated;
  75. void *memory;
  76. asQWORD storage;
  77. asCScriptFunction *initFunc;
  78. asDWORD accessMask;
  79. // The global property structure is reference counted, so that the
  80. // engine can keep track of how many references to the property there are.
  81. asCAtomic refCount;
  82. bool gcFlag;
  83. };
  84. class asCCompGlobPropType : public asIFilter
  85. {
  86. public:
  87. const asCDataType &m_type;
  88. asCCompGlobPropType(const asCDataType &type) : m_type(type) {}
  89. bool operator()(const void *p) const
  90. {
  91. const asCGlobalProperty* prop = reinterpret_cast<const asCGlobalProperty*>(p);
  92. return prop->type == m_type;
  93. }
  94. private:
  95. // The assignment operator is required for MSVC9, otherwise it will complain that it is not possible to auto generate the operator
  96. asCCompGlobPropType &operator=(const asCCompGlobPropType &) {return *this;}
  97. };
  98. END_AS_NAMESPACE
  99. #endif