2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * File: scoop.c $XConsortium: scoop.c /main/3 1995/10/26 15:38:19 rswiston $
27 * (c) Copyright 1988, Hewlett-Packard Company, all rights reserved.
29 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
30 * (c) Copyright 1993, 1994 International Business Machines Corp. *
31 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
32 * (c) Copyright 1993, 1994 Novell, Inc. *
35 #include <bms/sbport.h> /* This must be the first file included */
36 #include <bms/scoop.h>
38 static void system_class_init (object_clasp to_do, object_clasp on_behalf_of);
39 static void system_object_init (object_clasp c, object *p);
40 static void root_class_init (object_clasp c);
41 static void root_object_init (object *p);
42 static object *root_clone (object *this_ptr, object *clone);
43 static object *root_new (object_clasp c);
44 static void root_free (object *p);
46 /*--------------------------------------------------------------------------+*/
47 void object_destroy (object *p)
48 /*--------------------------------------------------------------------------+*/
50 memf (p->, free_obj, (p)) ;
53 /*--------------------------------------------------------------------------+*/
54 object *object_create (object_clasp c)
55 /*--------------------------------------------------------------------------+*/
59 if (! c->init) { system_class_init (c, c) ; }
60 p = (*(c->new_obj))(c) ;
66 /*--------------------------------------------------------------------------+*/
67 void object_init (object_clasp c, object *p)
68 /*--------------------------------------------------------------------------+*/
70 if (! c->init) { system_class_init (c, c) ; }
72 system_object_init (c, p) ;
75 /*--------------------------------------------------------------------------+*/
76 static void system_class_init (object_clasp to_do, object_clasp on_behalf_of)
77 /*--------------------------------------------------------------------------+*/
81 if ( on_behalf_of && to_do && ! on_behalf_of->init )
86 if (to_do == on_behalf_of && to_do != root_class)
87 { on_behalf_of->base = *((object_clasp *) (on_behalf_of->base)) ;
90 system_class_init (base, base) ;
91 system_class_init (base, on_behalf_of) ;
93 if (to_do == on_behalf_of)
94 { to_do->object_init = root_object_init ;
95 to_do->new_obj = root_new ;
96 to_do->free_obj = root_free ;
100 printf ("-> '%s' class for '%s'\n",
101 to_do->name, on_behalf_of->name) ;
102 #endif /* GLSDEBUG */
104 (*(to_do->class_init))(on_behalf_of);
105 if (to_do == on_behalf_of) on_behalf_of->init = TRUE ;
108 /*--------------------------------------------------------------------------+*/
109 static void system_object_init (object_clasp c, object *p)
110 /*--------------------------------------------------------------------------+*/
115 printf (" '%s' object for '%s'\n", c->name, p->class_ptr->name) ;
116 #endif /* GLSDEBUG */
118 system_object_init (c->base, p) ;
121 printf ("-> '%s' object for '%s'\n", c->name, p->class_ptr->name) ;
122 #endif /* GLSDEBUG */
124 (*(c->object_init))(p) ;
127 /*--------------------------------------------------------------------------+*/
128 static void root_class_init (object_clasp c)
129 /*--------------------------------------------------------------------------+*/
131 c->clone = root_clone ;
134 /*--------------------------------------------------------------------------+*/
135 static void root_object_init (object * UNUSED_PARM(p))
136 /*--------------------------------------------------------------------------+*/
141 The clone (second) argument to the clone method may be either NULL or an
142 object pointer. If NULL, a space of the size necessary for an object of
143 the same class as the primary object (this) will be allocated. If the
144 input argument is not null, it is assumed that the caller has verified
145 there is sufficient space for a copy of the original object.
146 If the clone procedure does allocate the space for the clone, it only
147 allocates the space. It does not do object initialization.
149 /*--------------------------------------------------------------------------+*/
150 static object *root_clone (object *this_ptr, object *clone)
151 /*--------------------------------------------------------------------------+*/
153 XeString orig = (XeString) this_ptr ;
156 object_clasp o_class = this_ptr->class_ptr ;
157 OSizeType size = o_class->object_size ;
160 clone = (*(o_class->new_obj))(o_class) ;
162 copy = (XeString) clone ;
169 /*--------------------------------------------------------------------------+*/
170 static object *root_new (object_clasp c)
171 /*--------------------------------------------------------------------------+*/
172 { object *p = (object *)malloc((unsigned) c->object_size) ;
174 /* Don't use XeMalloc here, we want to be able to grab our Edit */
175 /* widget without the rest of the world being pulled in. */
178 fprintf(stderr, "scoop: malloc in root_new failed, out of memory!\n");
185 /*--------------------------------------------------------------------------+*/
186 static void root_free (object *p)
187 /*--------------------------------------------------------------------------+*/
189 if (p) free ((char *)p) ;
192 struct root_class root_class_struct = {
193 (object_clasp) NULL, /* root has no base class */
194 "root", /* class name */
200 object_clasp root_class = & root_class_struct ;