2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
9 #include <proto/exec.h>
10 #include <proto/oop.h>
11 #include <proto/utility.h>
12 #include <exec/memory.h>
18 #include "basemetaclass.h"
24 #include <aros/debug.h>
26 /*****************************************************************************************
35 Root class is the base class of all classes.
36 One can create new baseclasses, but all classes must implement the root interface.
38 *****************************************************************************************/
40 /*****************************************************************************************
46 See OOP_NewObject() doc.
49 Creates a new object of some class. Class users should use OOP_NewObject() to
52 *****************************************************************************************/
54 /*****************************************************************************************
60 See OOP_DisposeObject() doc.
63 Used internally to dispose of an object previously
64 created using the moRoot_New method.
66 *****************************************************************************************/
68 /*****************************************************************************************
74 OOP_SetAttrs() (OOP_Object *object, struct TagItem *attrs);
77 Set an attribute of an object.
79 *****************************************************************************************/
81 /*****************************************************************************************
87 OOP_GetAttr(OOP_Object *object, ULONG attrID, IPTR *storage);
90 Get the value for an object attribute.
91 The attribute value will be stored in *storage.
97 OOP_GetAttr(list, aList_NumMembers, &num_members);
99 *****************************************************************************************/
101 /************************
102 ** Rootclass methods **
103 ************************/
108 OOP_Object
*root_new(OOP_Class
*root_cl
, OOP_Class
*cl
, struct pRoot_New
*param
)
110 struct _OOP_Object
*o
;
112 EnterFunc(bug("Root::New(cl=%s, param = %p)\n",
113 cl
->ClassNode
.ln_Name
, param
));
115 /* Allocate memory for the object */
116 D(bug("Object size: %ld\n", MD(cl
)->public.InstOffset
+ MD(cl
)->instsize
+ sizeof (struct _OOP_Object
)));
117 o
= AllocVec(MD(cl
)->public.InstOffset
+ MD(cl
)->instsize
+ sizeof (struct _OOP_Object
), MEMF_ANY
|MEMF_CLEAR
);
120 D(bug("Mem allocated: %p\n", o
));
121 o
->o_Class
= (OOP_Class
*)cl
;
123 /* Class has one more object */
124 MD(cl
)->objectcount
++;
126 ReturnPtr ("Root::New", OOP_Object
*, OOP_BASEOBJECT(o
) );
129 ReturnPtr ("Root::New", OOP_Object
*, NULL
);
135 static VOID
root_dispose(OOP_Class
*root_cl
, OOP_Object
*o
, OOP_Msg msg
)
137 EnterFunc(bug("Root::Dispose(o=%p, oclass=%s)\n", o
, _OOP_OBJECT(o
)->o_Class
->ClassNode
.ln_Name
));
139 MD(OOP_OCLASS(o
))->objectcount
--;
140 D(bug("Object mem: %p, size: %ld\n", _OOP_OBJECT(o
), ((ULONG
*)_OOP_OBJECT(o
))[-1] ));
142 /* Free object's memory */
143 FreeVec(_OOP_OBJECT(o
));
145 ReturnVoid("Root::Dispose");
148 static VOID
root_get(OOP_Class
*root_cl
, OOP_Object
*p
, struct pRoot_Get
*msg
)
151 D(bug("!!! Get() METHOD REACHED ROOTCLASS !!!\n"));
155 /**********************
156 ** init_rootclass() **
157 **********************/
158 BOOL
init_rootclass(struct IntOOPBase
*OOPBase
)
161 struct rootclassobject
*rco
;
162 OOP_Class
*rootclass
;
167 EnterFunc(bug("init_rootclass()\n"));
169 rco
= &(OOPBase
->ob_RootClassObject
);
170 rootclass
= &(rco
->inst
.data
.public);
172 /* Its class is the metaobject */
173 rco
->oclass
= &(OOPBase
->ob_BaseMetaObject
.inst
.data
.public);
175 rco
->inst
.data
.public.ClassNode
.ln_Name
= CLID_Root
;
176 rco
->inst
.data
.public.OOPBasePtr
= OOPBase
;
177 rco
->inst
.data
.public.InstOffset
= 0;
178 rco
->inst
.data
.public.UserData
= (APTR
)OOPBase
;
180 rco
->inst
.data
.public.cl_DoSuperMethod
= basemeta_dosupermethod
;
181 rco
->inst
.data
.public.cl_CoerceMethod
= basemeta_coercemethod
;
182 rco
->inst
.data
.public.cl_DoMethod
= basemeta_domethod
;
184 D(bug("Root stuff: dosupermethod %p, coeremethod %p, domethod %p\n",
185 basemeta_dosupermethod
, basemeta_coercemethod
, basemeta_domethod
));
187 rco
->inst
.data
.public.superclass
= NULL
;
188 rco
->inst
.data
.subclasscount
= 0UL;
189 rco
->inst
.data
.objectcount
= 0UL;
190 rco
->inst
.data
.instsize
= 0UL;
191 rco
->inst
.data
.numinterfaces
= 1UL;
193 /* Initialize methodtable */
195 rco
->inst
.rootif
[moRoot_New
].MethodFunc
= (IPTR (*)())root_new
;
196 rco
->inst
.rootif
[moRoot_New
].mClass
= rootclass
;
198 rco
->inst
.rootif
[moRoot_Dispose
].MethodFunc
= (IPTR (*)())root_dispose
;
199 rco
->inst
.rootif
[moRoot_Dispose
].mClass
= rootclass
;
201 rco
->inst
.rootif
[moRoot_Get
].MethodFunc
= (IPTR (*)())root_get
;
202 rco
->inst
.rootif
[moRoot_Get
].mClass
= rootclass
;
204 /* Important: IID_Root interface ID MUST be the first one
205 initialized, so that it gets the value 0UL. This is
206 because it's used as rootclass both for IFMeta and HIDDMeta classes
209 success
= init_mi_methodbase(IID_Root
, &mbase
, OOPBase
);
213 OOP_AddClass(rootclass
);
216 ReturnBool ("init_rootclass", success
);
219 /* Below is rootclass DoMethod and CoerceMethod. They are hardly useful,
220 cause you would never create an object of rootclass
224 #define ROOT_CALLMETHOD(cl, o, m) \
226 register struct IFMethod *ifm; \
227 ifm = &(RI(cl)->rootif[msg->MethodID]); \
228 return ifm->MethodFunc(ifm->mClass, o, msg); \
231 #define RI(cl) ((struct rootinst *)cl)
233 static IPTR root_domethod(OOP_Object *o, OOP_Msg msg)
238 ROOT_CALLMETHOD(cl, o, msg);
241 static IPTR root_coercemethod(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
243 ROOT_CALLMETHOD(cl, o, msg);