as_property.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2017 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. andreas@angelcode.com
  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() : byteOffset(0), accessMask(0xFFFFFFFF), compositeOffset(0), isCompositeIndirect(false), isPrivate(false), isProtected(false), isInherited(false) {}
  41. asCObjectProperty(const asCObjectProperty &o) : name(o.name), type(o.type), byteOffset(o.byteOffset), accessMask(o.accessMask), compositeOffset(o.compositeOffset), isCompositeIndirect(o.isCompositeIndirect), isPrivate(o.isPrivate), isProtected(o.isProtected), isInherited(o.isInherited) {}
  42. asCString name;
  43. asCDataType type;
  44. int byteOffset;
  45. asDWORD accessMask;
  46. int compositeOffset;
  47. bool isCompositeIndirect;
  48. bool isPrivate;
  49. bool isProtected;
  50. bool isInherited;
  51. };
  52. class asCGlobalProperty
  53. {
  54. public:
  55. asCGlobalProperty();
  56. ~asCGlobalProperty();
  57. void AddRef();
  58. void Release();
  59. void DestroyInternal();
  60. void *GetAddressOfValue();
  61. void AllocateMemory();
  62. void SetRegisteredAddress(void *p);
  63. void *GetRegisteredAddress() const;
  64. asCString name;
  65. asCDataType type;
  66. asUINT id;
  67. asSNameSpace *nameSpace;
  68. void SetInitFunc(asCScriptFunction *initFunc);
  69. asCScriptFunction *GetInitFunc();
  70. //protected:
  71. // This is only stored for registered properties, and keeps the pointer given by the application
  72. void *realAddress;
  73. bool memoryAllocated;
  74. void *memory;
  75. asQWORD storage;
  76. asCScriptFunction *initFunc;
  77. asDWORD accessMask;
  78. // The global property structure is reference counted, so that the
  79. // engine can keep track of how many references to the property there are.
  80. asCAtomic refCount;
  81. };
  82. class asCCompGlobPropType : public asIFilter
  83. {
  84. public:
  85. const asCDataType &m_type;
  86. asCCompGlobPropType(const asCDataType &type) : m_type(type) {}
  87. bool operator()(const void *p) const
  88. {
  89. const asCGlobalProperty* prop = reinterpret_cast<const asCGlobalProperty*>(p);
  90. return prop->type == m_type;
  91. }
  92. private:
  93. // The assignment operator is required for MSVC9, otherwise it will complain that it is not possible to auto generate the operator
  94. asCCompGlobPropType &operator=(const asCCompGlobPropType &) {return *this;}
  95. };
  96. END_AS_NAMESPACE
  97. #endif