2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
5 Desc: Create a new OOP object
9 #include <aros/atomic.h>
10 #include <exec/lists.h>
11 #include <proto/exec.h>
14 #include <aros/debug.h>
15 #define MD(x) ((struct metadata *)x)
17 /*****************************************************************************
20 #include <proto/oop.h>
22 AROS_LH3(APTR
, OOP_NewObject
,
25 AROS_LHA(struct OOP_IClass
*, classPtr
, A0
),
26 AROS_LHA(CONST_STRPTR
, classID
, A1
),
27 AROS_LHA(struct TagItem
*, tagList
, A2
),
30 struct Library
*, OOPBase
, 5, OOP
)
33 Creates a new object of given class based on the TagItem
37 classPtr - pointer to a class. Use this if the class to
38 create an instance of is private.
39 classID - Public ID of the class to create an instance of.
40 Use this if the class is public.
41 tagList - List of TagItems (creation time attributes),
42 that specifies what initial properties the new
47 Pointer to the new object, or NULL if object creation failed.
50 You should supply one of classPtr and classID, never
51 both. Use NULL for the unspecified one.
63 29-10-95 digulla automatically created from
64 intuition_lib.fd and clib/intuition_protos.h
66 *****************************************************************************/
73 // bug("OOP_NewObject(class=%s, classptr=%p, tags=%p)\n", classID, classPtr, tagList);
74 EnterFunc(bug("OOP_NewObject(classPtr=%p, classID=%s, tagList=%p)\n",
75 classPtr
, ((classID
!= (CONST_STRPTR
)NULL
) ? classID
: "(null)"), tagList
));
79 /* If a public ID was given, find pointer to class */
81 classPtr
= OOP_FindClass(classID
);
85 ReturnPtr ("OOP_NewObject[No classPtr]", OOP_Object
*, NULL
);
88 * We don't want the class to be freed while we work on it,
89 * so we temporarily increment reference count.
90 * Note that real instance counting happens inside rootclass,
91 * where it allocates and frees the memory.
93 AROS_ATOMIC_INC(MD(classPtr
)->objectcount
);
95 /* Create a new instance */
97 D(bug("Creating new instance\n"));
99 p
.mID
= OOP_GetMethodID(IID_Root
, moRoot_New
);
100 p
.attrList
= tagList
;
102 /* print_table(GetOBase(OOPBase)->ob_IIDTable, GetOBase(OOPBase));
104 D(bug("mid=%ld\n", p
.mID
));
106 /* Call the New() method of the specified class */
108 o
= (OOP_Object
*)OOP_CoerceMethod(classPtr
, (OOP_Object
*)classPtr
, (OOP_Msg
)&p
);
110 /* Release our temporary lock */
111 AROS_ATOMIC_DEC(MD(classPtr
)->objectcount
);
113 /* print_table(GetOBase(OOPBase)->ob_IIDTable, GetOBase(OOPBase));
115 ReturnPtr ("OOP_NewObject", OOP_Object
*, o
);
119 } /* OOP_NewObject */