5 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
10 # include <exec/types.h>
14 # include <exec/nodes.h>
17 #ifndef EXEC_LIBRARIES_H
18 # include <exec/libraries.h>
21 #ifndef UTILITY_TAGITEM_H
22 # include <utility/tagitem.h>
25 #define AROSOOP_NAME "oop.library"
27 typedef ULONG OOP_Object
;
29 typedef ULONG OOP_MethodID
;
30 typedef ULONG OOP_AttrID
;
32 typedef ULONG OOP_AttrBase
;
34 typedef ULONG OOP_AttrCheck
;
36 #define GOT_ATTR(code, pre_tag, pre_ac) \
37 ((pre_ac ## _attrcheck & (1L << pre_tag ## _ ## code)) == (1L << pre_tag ## _ ## code))
39 #define FOUND_ATTR(code, pre_tag, pre_ac) \
40 pre_ac ## _attrcheck |= (1L << pre_tag ## _ ## code)
42 #define DECLARE_ATTRCHECK(pre_tag) \
43 OOP_AttrCheck pre_tag ## _attrcheck = 0UL
45 #define ATTRCHECK(pre_tag) \
49 ooperr_ParseAttrs_TooManyAttrs
= 1
52 typedef OOP_MethodID
* OOP_Msg
;
57 CONST_STRPTR interfaceID
;
58 OOP_AttrBase
*attrBase
;
61 typedef struct OOP_IClass OOP_Class
;
65 /* Array of pointers to methodtables for this class */
66 struct Node ClassNode
;
67 struct IntOOPBase
*OOPBasePtr
;
70 IPTR (*cl_DoMethod
)(OOP_Object
*, OOP_Msg
);
71 IPTR (*cl_CoerceMethod
)(OOP_Class
*, OOP_Object
*, OOP_Msg
);
72 IPTR (*cl_DoSuperMethod
)(OOP_Class
*, OOP_Object
*, OOP_Msg
);
73 OOP_Class
*superclass
;
88 #define OOP_BASEOBJECT(obj) ((OOP_Object *)(_OOP_OBJ(obj) + 1))
89 #define _OOP_OBJECT(obj) (_OOP_OBJ(obj) - 1)
90 #define _OOP_OBJ(obj) ((struct _OOP_Object *)(obj))
92 #define OOP_INST_DATA(cl, obj) \
93 ((APTR)(((UBYTE *)obj) + (cl)->InstOffset))
95 #define OOP_OCLASS(obj) \
96 (_OOP_OBJECT(obj)->o_Class)
98 #define OOP_OOPBASE(obj) \
99 (OOP_OCLASS(obj)->OOPBasePtr)
101 #define OOP_DoMethod(o, msg) ( (OOP_OCLASS(o))->cl_DoMethod((o), (msg)) )
102 #define OOP_DoSuperMethod(cl, o, msg) ((cl)->cl_DoSuperMethod(cl, o, msg))
103 #define OOP_CoerceMethod(cl, o, msg) ((cl)->cl_CoerceMethod(cl, o, msg))
105 #define OOP_GET(o, attr) ({IPTR _val; OOP_GetAttr(o, attr, &_val); _val;})
107 #define OOP_METHODDEF(x) (IPTR (*)())x
109 #define IS_IF_ATTR(attr, idx, attrbase, numifattrs) ( ((idx) = (attr) - (attrbase)) < (numifattrs) )
111 struct OOP_InterfaceDescr
113 const struct OOP_MethodDescr
*MethodTable
;
114 CONST_STRPTR InterfaceID
;
115 ULONG NumMethods
; /* Number of methods in the methodtable */
118 typedef IPTR (*OOP_MethodFunc
)(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
);
120 struct OOP_MethodDescr
122 OOP_MethodFunc MethodFunc
;
127 /* Some basic interfaces and classes */
129 /*********************
131 *********************/
133 #define IID_Root "Root"
134 #define CLID_Root "rootclass"
151 struct TagItem
*attrList
;
154 struct pRoot_Dispose
{
161 struct TagItem
*attrList
;
171 /**************************
172 ** meta interface defs **
173 **************************/
175 #define IID_Meta "Meta"
177 #define MetaAttrBase (__IMeta)
187 aoMeta_InterfaceDescr
,
193 aoMeta_DoSuperMethod
,
198 #define aMeta_SuperID (MetaAttrBase + aoMeta_SuperID)
199 #define aMeta_InterfaceDescr (MetaAttrBase + aoMeta_InterfaceDescr)
200 #define aMeta_ID (MetaAttrBase + aoMeta_ID)
201 #define aMeta_SuperPtr (MetaAttrBase + aoMeta_SuperPtr)
202 #define aMeta_InstSize (MetaAttrBase + aoMeta_InstSize)
203 #define aMeta_DoMethod (MetaAttrBase + aoMeta_DoMethod)
204 #define aMeta_CoerceMethod (MetaAttrBase + aoMeta_CoerceMethod)
205 #define aMeta_DoSuperMethod (MetaAttrBase + aoMeta_DoSuperMethod)
207 /***********************
208 ** methodclass defs **
209 ***********************/
211 extern ULONG __IMethod
;
213 #define IID_Method "Method"
215 #define CLID_Method "methodclass"
217 #define MethodAttrBase (__IMethod)
219 #define OOP_CallMethod(m) ( (m)->methodFunc((m)->methodClass, (m)->targetObject, (m)->message) )
222 aoMethod_TargetObject
= 0,
229 #define aMethod_TargetObject (MethodAttrBase + aoMethod_TargetObject)
230 #define aMethod_Message (MethodAttrBase + aoMethod_Message)
231 #define aMethod_MethodID (MethodAttrBase + aoMethod_MethodID)
235 OOP_Object
*targetObject
;
237 OOP_Class
*methodClass
;
238 OOP_MethodFunc methodFunc
;
242 /**************************
243 ** interfaceclass defs **
244 **************************/
246 extern ULONG __IInterface
;
248 #define IID_Interface "Interface"
250 #define CLID_Interface "interfaceclass"
252 #define InterfaceAttrBase (__IInterface)
256 aoInterface_TargetObject
= 0,
257 aoInterface_InterfaceID
,
262 #define aInterface_TargetObject (InterfaceAttrBase + aoInterface_TargetObject)
263 #define aInterface_InterfaceID (InterfaceAttrBase + aoInterface_InterfaceID)
266 typedef struct OOP_InterfaceStruct
268 IPTR (*callMethod
)(struct OOP_InterfaceStruct
*, OOP_Msg
);
269 OOP_Object
*targetObject
;
274 /***********************
275 ** Some metaclasses **
276 ***********************/
278 #define CLID_MIMeta "mimetaclass" /* Supports multiple interfaces */
279 #define CLID_SIMeta "simetaclass" /* Supports only single intefaces */
283 #endif /* OOP_OOP_H */