Indentation fix, cleanup.
[AROS.git] / rom / oop / newobject.c
blob9011295234a63ae03b3faeed122216dcce55f666
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create a new OOP object
6 Lang: english
7 */
9 #include <aros/atomic.h>
10 #include <exec/lists.h>
11 #include <proto/exec.h>
12 #include "intern.h"
13 #include "hash.h"
14 #include <aros/debug.h>
15 #define MD(x) ((struct metadata *)x)
17 /*****************************************************************************
19 NAME */
20 #include <proto/oop.h>
22 AROS_LH3(APTR, OOP_NewObject,
24 /* SYNOPSIS */
25 AROS_LHA(struct OOP_IClass *, classPtr, A0),
26 AROS_LHA(CONST_STRPTR , classID, A1),
27 AROS_LHA(struct TagItem *, tagList, A2),
29 /* LOCATION */
30 struct Library *, OOPBase, 5, OOP)
32 /* FUNCTION
33 Creates a new object of given class based on the TagItem
34 parameters passed.
36 INPUTS
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
43 object should have.
46 RESULT
47 Pointer to the new object, or NULL if object creation failed.
49 NOTES
50 You should supply one of classPtr and classID, never
51 both. Use NULL for the unspecified one.
53 EXAMPLE
55 BUGS
57 SEE ALSO
58 OOP_DisposeObject()
60 INTERNALS
62 HISTORY
63 29-10-95 digulla automatically created from
64 intuition_lib.fd and clib/intuition_protos.h
66 *****************************************************************************/
68 AROS_LIBFUNC_INIT
70 struct pRoot_New p;
71 OOP_Object *o;
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));
77 if (!classPtr)
79 /* If a public ID was given, find pointer to class */
80 if (classID)
81 classPtr = OOP_FindClass(classID);
84 if (!classPtr)
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);
118 AROS_LIBFUNC_EXIT
119 } /* OOP_NewObject */