update copyright
[AROS.git] / rom / oop / include / oop.h
blobf388817d3018d6f27a4613cf9a061954f20b90f5
1 #ifndef OOP_OOP_H
2 #define OOP_OOP_H
4 /*
5 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 $Id$
7 */
9 #ifndef EXEC_TYPES_H
10 # include <exec/types.h>
11 #endif
13 #ifndef EXEC_NODES_H
14 # include <exec/nodes.h>
15 #endif
17 #ifndef EXEC_LIBRARIES_H
18 # include <exec/libraries.h>
19 #endif
21 #ifndef UTILITY_TAGITEM_H
22 # include <utility/tagitem.h>
23 #endif
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) \
46 pre_tag ## _attrcheck
48 enum {
49 ooperr_ParseAttrs_TooManyAttrs = 1
52 typedef OOP_MethodID * OOP_Msg;
55 struct OOP_ABDescr
57 CONST_STRPTR interfaceID;
58 OOP_AttrBase *attrBase;
61 typedef struct OOP_IClass OOP_Class;
63 struct OOP_IClass
65 /* Array of pointers to methodtables for this class */
66 struct Node ClassNode;
67 struct IntOOPBase *OOPBasePtr;
68 ULONG InstOffset;
69 APTR UserData;
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;
78 struct _OOP_Object
80 OOP_Class *o_Class;
85 /* Macros */
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;
123 ULONG MethodIdx;
127 /* Some basic interfaces and classes */
129 /*********************
130 ** rootclass defs **
131 *********************/
133 #define IID_Root "Root"
134 #define CLID_Root "rootclass"
137 enum
139 moRoot_New = 0,
140 moRoot_Dispose,
141 moRoot_Set,
142 moRoot_Get,
144 num_Root_Methods
148 struct pRoot_New
150 OOP_MethodID mID;
151 struct TagItem *attrList;
154 struct pRoot_Dispose {
155 OOP_MethodID mID;
158 struct pRoot_Set
160 OOP_MethodID mID;
161 struct TagItem *attrList;
164 struct pRoot_Get
166 OOP_MethodID mID;
167 ULONG attrID;
168 IPTR *storage;
171 /**************************
172 ** meta interface defs **
173 **************************/
175 #define IID_Meta "Meta"
177 #define MetaAttrBase (__IMeta)
180 enum
182 num_Meta_Methods
185 enum {
186 aoMeta_SuperID = 0,
187 aoMeta_InterfaceDescr,
188 aoMeta_ID,
189 aoMeta_SuperPtr,
190 aoMeta_InstSize,
191 aoMeta_DoMethod,
192 aoMeta_CoerceMethod,
193 aoMeta_DoSuperMethod,
195 num_Meta_Attrs
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) )
221 enum {
222 aoMethod_TargetObject= 0,
223 aoMethod_Message,
224 aoMethod_MethodID,
226 num_Method_Attrs
229 #define aMethod_TargetObject (MethodAttrBase + aoMethod_TargetObject)
230 #define aMethod_Message (MethodAttrBase + aoMethod_Message)
231 #define aMethod_MethodID (MethodAttrBase + aoMethod_MethodID)
233 typedef struct
235 OOP_Object *targetObject;
236 OOP_Msg message;
237 OOP_Class *methodClass;
238 OOP_MethodFunc methodFunc;
239 } OOP_Method;
242 /**************************
243 ** interfaceclass defs **
244 **************************/
246 extern ULONG __IInterface;
248 #define IID_Interface "Interface"
250 #define CLID_Interface "interfaceclass"
252 #define InterfaceAttrBase (__IInterface)
255 enum {
256 aoInterface_TargetObject= 0,
257 aoInterface_InterfaceID,
259 NUM_A_Interface
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;
271 } OOP_Interface;
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 */