1 /* 2 AngelCode Scripting Library 3 Copyright (c) 2003-2017 Andreas Jonsson 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any 7 damages arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any 10 purpose, including commercial applications, and to alter it and 11 redistribute it freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you 14 must not claim that you wrote the original software. If you use 15 this software in a product, an acknowledgment in the product 16 documentation would be appreciated but is not required. 17 18 2. Altered source versions must be plainly marked as such, and 19 must not be misrepresented as being the original software. 20 21 3. This notice may not be removed or altered from any source 22 distribution. 23 24 The original version of this library can be located at: 25 http://www.angelcode.com/angelscript/ 26 27 Andreas Jonsson 28 andreas@angelcode.com 29 */ 30 31 32 33 // 34 // as_objecttype.h 35 // 36 // A class for storing object type information 37 // 38 39 40 41 #ifndef AS_OBJECTTYPE_H 42 #define AS_OBJECTTYPE_H 43 44 #include "as_property.h" 45 #include "as_array.h" 46 #include "as_scriptfunction.h" 47 #include "as_typeinfo.h" 48 49 BEGIN_AS_NAMESPACE 50 51 struct asSTypeBehaviour 52 { asSTypeBehaviourasSTypeBehaviour53 asSTypeBehaviour() 54 { 55 factory = 0; 56 listFactory = 0; 57 copyfactory = 0; 58 construct = 0; 59 copyconstruct = 0; 60 destruct = 0; 61 copy = 0; 62 addref = 0; 63 release = 0; 64 gcGetRefCount = 0; 65 gcSetFlag = 0; 66 gcGetFlag = 0; 67 gcEnumReferences = 0; 68 gcReleaseAllReferences = 0; 69 templateCallback = 0; 70 getWeakRefFlag = 0; 71 } 72 73 int factory; 74 int listFactory; // Used for initialization lists only 75 int copyfactory; 76 int construct; 77 int copyconstruct; 78 int destruct; 79 int copy; 80 int addref; 81 int release; 82 int templateCallback; 83 84 // GC behaviours 85 int gcGetRefCount; 86 int gcSetFlag; 87 int gcGetFlag; 88 int gcEnumReferences; 89 int gcReleaseAllReferences; 90 91 // Weakref behaviours 92 int getWeakRefFlag; 93 94 asCArray<int> factories; 95 asCArray<int> constructors; 96 }; 97 98 class asCScriptEngine; 99 struct asSNameSpace; 100 101 class asCObjectType : public asCTypeInfo 102 { 103 public: 104 asITypeInfo *GetBaseType() const; 105 bool DerivesFrom(const asITypeInfo *objType) const; 106 int GetSubTypeId(asUINT subtypeIndex = 0) const; 107 asITypeInfo *GetSubType(asUINT subtypeIndex = 0) const; 108 asUINT GetSubTypeCount() const; 109 asUINT GetInterfaceCount() const; 110 asITypeInfo *GetInterface(asUINT index) const; 111 bool Implements(const asITypeInfo *objType) const; 112 asUINT GetFactoryCount() const; 113 asIScriptFunction *GetFactoryByIndex(asUINT index) const; 114 asIScriptFunction *GetFactoryByDecl(const char *decl) const; 115 asUINT GetMethodCount() const; 116 asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual) const; 117 asIScriptFunction *GetMethodByName(const char *name, bool getVirtual) const; 118 asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual) const; 119 asUINT GetPropertyCount() const; 120 int GetProperty(asUINT index, const char **name, int *typeId, bool *isPrivate, bool *isProtected, int *offset, bool *isReference, asDWORD *accessMask, int *compositeOffset, bool *isCompositeIndirect) const; 121 const char *GetPropertyDeclaration(asUINT index, bool includeNamespace = false) const; 122 asUINT GetBehaviourCount() const; 123 asIScriptFunction *GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const; 124 asUINT GetChildFuncdefCount() const; 125 asITypeInfo *GetChildFuncdef(asUINT index) const; 126 127 public: 128 asCObjectType(asCScriptEngine *engine); 129 ~asCObjectType(); 130 void DestroyInternal(); 131 132 void ReleaseAllFunctions(); 133 134 bool IsInterface() const; 135 136 asCObjectProperty *AddPropertyToClass(const asCString &name, const asCDataType &dt, bool isPrivate, bool isProtected, bool isInherited); 137 void ReleaseAllProperties(); 138 139 #ifdef WIP_16BYTE_ALIGN 140 int alignment; 141 #endif 142 asCArray<asCObjectProperty*> properties; 143 asCArray<int> methods; 144 145 // TODO: These are not used by template types. Should perhaps create a derived class to save memory on ordinary object types 146 asCArray<asCObjectType*> interfaces; 147 asCArray<asUINT> interfaceVFTOffsets; 148 asCObjectType * derivedFrom; 149 asCArray<asCScriptFunction*> virtualFunctionTable; 150 151 // Used for funcdefs declared as members of class. 152 // TODO: child funcdef: Should be possible to enumerate these from application 153 asCArray<asCFuncdefType*> childFuncDefs; 154 155 asSTypeBehaviour beh; 156 157 // Used for template types 158 asCArray<asCDataType> templateSubTypes; // increases refCount for typeinfo held in datatype 159 bool acceptValueSubType; 160 bool acceptRefSubType; 161 162 protected: 163 friend class asCScriptEngine; 164 friend class asCConfigGroup; 165 friend class asCModule; 166 asCObjectType(); 167 }; 168 169 END_AS_NAMESPACE 170 171 #endif 172