Add new strings.
[AROS.git] / rom / oop / newobject.c
blob9503e524009d95f030dce48dc1709af836fcd79d
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(UBYTE *, 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 != NULL) ? classID : (UBYTE *)"(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);
87 AROS_ATOMIC_INC(MD(classPtr)->objectcount); /* We don't want the class to be freed while we work on it */
89 /* Create a new instance */
91 D(bug("Creating new instance\n"));
93 p.mID = OOP_GetMethodID(IID_Root, moRoot_New);
94 p.attrList = tagList;
96 /* print_table(GetOBase(OOPBase)->ob_IIDTable, GetOBase(OOPBase));
97 */
98 D(bug("mid=%ld\n", p.mID));
100 /* Call the New() method of the specified class */
102 D(bug("OOP_Coercemethod: %p\n", classPtr->CoerceMethod));
103 o = (OOP_Object *)OOP_CoerceMethod(classPtr, (OOP_Object *)classPtr, (OOP_Msg)&p);
104 if (!o)
106 AROS_ATOMIC_DEC(MD(classPtr)->objectcount); /* Object creation failed, release lock */
108 /* print_table(GetOBase(OOPBase)->ob_IIDTable, GetOBase(OOPBase));
110 ReturnPtr ("OOP_NewObject", OOP_Object *, o);
113 AROS_LIBFUNC_EXIT
114 } /* OOP_NewObject */