Don't get OOPBase in this ugly way.
[tangerine.git] / rom / intuition / newobjecta.c
blobd659a97ed1da294b1bfa681ccc7d1be29bdf211d
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
6 Create a new BOOPSI object.
7 */
9 #include <exec/lists.h>
10 #include <intuition/classes.h>
11 #include <proto/exec.h>
12 #include <proto/alib.h>
13 #include <proto/utility.h>
14 #include "intuition_intern.h"
16 /*****************************************************************************
18 NAME */
19 #include <intuition/classusr.h>
20 #include <proto/intuition.h>
22 AROS_LH3(APTR, NewObjectA,
24 /* SYNOPSIS */
25 AROS_LHA(struct IClass *, classPtr, A0),
26 AROS_LHA(UBYTE *, classID, A1),
27 AROS_LHA(struct TagItem *, tagList, A2),
29 /* LOCATION */
30 struct IntuitionBase *, IntuitionBase, 106, Intuition)
32 /* FUNCTION
33 Use this function to create BOOPSI objects (BOOPSI stands for
34 "Basic Object Oriented Programming System for Intuition).
36 You may specify a class either by it's name (if it's a public class)
37 or by a pointer to its definition (if it's a private class). If
38 classPtr is NULL, classID is used.
40 INPUTS
41 classPtr - Pointer to a private class (or a public class if you
42 happen to have a pointer to it)
43 classID - Name of a public class
44 tagList - Initial attributes. Read the documentation of the class
45 carefully to find out which attributes must be specified
46 here and which can.
48 RESULT
49 A BOOPSI object which can be manipulated with general functions and
50 which must be disposed with DisposeObject() later.
52 NOTES
53 This functions send OM_NEW to the dispatcher of the class.
55 EXAMPLE
57 BUGS
59 SEE ALSO
60 DisposeObject(), SetAttrs(), GetAttr(), MakeClass(),
61 "Basic Object-Oriented Programming System for Intuition" and
62 "boopsi Class Reference" Dokument.
64 *****************************************************************************/
66 AROS_LIBFUNC_INIT
67 AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
69 Object *object;
70 struct opSet method;
72 DEBUG_NEWOBJECT(dprintf("NewObject[%x]: Class 0x%lx <%s> TagList 0x%lx\n",
73 &method, /* some unique id to see matching debug info */
74 classPtr,
75 classID ? classID : (classPtr->cl_ID ? classPtr->cl_ID : "NULL"),
76 tagList));
78 EnterFunc(bug("intuition::NewObjectA()\n"));
80 #if 1
81 if (tagList)
83 DEBUG_NEWOBJECT(
84 APTR state = tagList;
85 struct TagItem *tag;
87 while (tag = NextTagItem(&state))
89 dprintf("\t%08lx %08lx\n", tag->ti_Tag, tag->ti_Data);
93 #endif
95 ObtainSemaphoreShared (&GetPrivIBase(IntuitionBase)->ClassListLock);
97 /* No classPtr ? */
98 if (!classPtr)
99 classPtr = FindClass (classID);
101 /* Make sure the class doesn't go away while we create the object */
102 if (classPtr)
104 AROS_ATOMIC_INC(classPtr->cl_ObjectCount);
107 ReleaseSemaphore (&GetPrivIBase(IntuitionBase)->ClassListLock);
109 if (!classPtr)
110 return (NULL); /* Nothing found */
112 D(bug("classPtr: %p\n", classPtr));
114 /* Try to create a new object */
115 method.MethodID = OM_NEW;
116 method.ops_AttrList = tagList;
117 method.ops_GInfo = NULL;
118 object = (Object *) CoerceMethodA (classPtr, (Object *)classPtr, (Msg)&method);
120 /* Release the lock on the class. Rootclass also has increased this count. */
121 AROS_ATOMIC_DEC(classPtr->cl_ObjectCount);
123 DEBUG_NEWOBJECT(dprintf("NewObject[%x]: return 0x%lx\n", &method, object));
125 ReturnPtr("intuition::NewObjectA()", Object *, object);
127 AROS_LIBFUNC_EXIT
128 } /* NewObjectA() */