1996-03-22 00:37:53 +00:00
|
|
|
/* Basic functions for @XX@ structures.
|
|
|
|
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
|
|
|
|
* Created: Tue Dec 12 12:33:01 EST 1995
|
|
|
|
* Updated: Mon Mar 11 00:56:35 EST 1996
|
|
|
|
* Serial: 96.03.11.02
|
|
|
|
*
|
1996-05-12 00:56:10 +00:00
|
|
|
* This file is part of the GNUstep Base Library.
|
1996-03-22 00:37:53 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/**** Included Headers *******************************************************/
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
#include <config.h>
|
1996-03-22 00:37:53 +00:00
|
|
|
#include <Foundation/NSZone.h>
|
|
|
|
#include <Foundation/NSString.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/numbers.h>
|
|
|
|
#include <base/o_@XX@.h>
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/**** Type, Constant, and Macro Definitions **********************************/
|
|
|
|
|
|
|
|
#define __@XX@__ 1
|
|
|
|
|
|
|
|
/**** Function Implementations ***********************************************/
|
|
|
|
|
|
|
|
/** Magic numbers... **/
|
|
|
|
|
|
|
|
/* Returns XX's magic number. */
|
|
|
|
inline int
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_magic_number(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
return xx->magic_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Zones... **/
|
|
|
|
|
|
|
|
/* Returns the zone used to create and maintain XX. */
|
|
|
|
inline NSZone *
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_zone(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
1997-03-03 19:43:25 +00:00
|
|
|
return NSZoneFromPointer(xx);
|
1996-03-22 00:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Names... **/
|
|
|
|
|
|
|
|
/* Returns the name that was given to XX. */
|
|
|
|
inline NSString *
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_name(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
return xx->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Gives XX a name. */
|
|
|
|
inline void
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_set_name(o_@XX@_t *xx, NSString *name)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
[name retain];
|
|
|
|
[xx->name release];
|
|
|
|
xx->name = name;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Takes away XX's name. */
|
|
|
|
inline void
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_unset_name(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
[xx->name release];
|
|
|
|
xx->name = nil;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Number **/
|
|
|
|
|
|
|
|
/* Returns the (process-wide) unique serial number given to the
|
1996-04-17 19:01:22 +00:00
|
|
|
* structure XX. See <gnustep/base/numbers.h> for more info. */
|
1996-03-22 00:37:53 +00:00
|
|
|
inline size_t
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_serial_number(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
return xx->serial_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Gives XX a new (process-wide) unique number. Numbers are not
|
1996-04-17 19:01:22 +00:00
|
|
|
* reused. See <gnustep/base/numbers.h> for more info. */
|
1996-03-22 00:37:53 +00:00
|
|
|
inline size_t
|
1996-04-17 19:26:04 +00:00
|
|
|
_o_@XX@_set_serial_number(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
size_t old_number;
|
|
|
|
|
|
|
|
old_number = xx->serial_number;
|
1996-04-17 19:26:04 +00:00
|
|
|
xx->serial_number = (___o_number_serialized)++;
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
return old_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Extras **/
|
|
|
|
|
|
|
|
/* Sets the callbacks associated with XX's ``extra''. NOTE: This must
|
1996-04-17 19:26:04 +00:00
|
|
|
* be done before calling `o_@XX@_set_extra()', as these callbacks
|
1996-03-22 00:37:53 +00:00
|
|
|
* are used in that routine. */
|
1996-04-17 19:26:04 +00:00
|
|
|
inline o_callbacks_t
|
|
|
|
o_@XX@_set_extra_callbacks(o_@XX@_t *xx,
|
|
|
|
o_callbacks_t callbacks)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
1996-04-17 19:26:04 +00:00
|
|
|
o_callbacks_t old_callbacks;
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/* Remember the old callbacks for later. */
|
|
|
|
old_callbacks = xx->extra_callbacks;
|
|
|
|
|
|
|
|
/* Set the new callbacks. */
|
|
|
|
xx->extra_callbacks = callbacks;
|
|
|
|
|
|
|
|
/* Release the old contents. */
|
1996-04-17 19:26:04 +00:00
|
|
|
o_release(old_callbacks, (void *)(xx->extra), xx);
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/* Set the contents to something noticible. */
|
|
|
|
xx->extra = (xx->extra_callbacks).not_an_item_marker;
|
|
|
|
|
|
|
|
return old_callbacks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the callbacks associated with XX's ``extra''. */
|
1996-04-17 19:26:04 +00:00
|
|
|
inline o_callbacks_t
|
|
|
|
o_@XX@_extra_callbacks(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
return xx->extra_callbacks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns XX's ``extra'', a little extra space that each
|
|
|
|
* structure carries around with it. Its use is
|
|
|
|
* implementation-dependent. */
|
|
|
|
inline const void *
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_extra(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
return xx->extra;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets XX's ``extra'', a little extra space that each structure
|
|
|
|
* carries around with it. Its use is implementation-dependent. */
|
|
|
|
inline const void *
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_set_extra(o_@XX@_t *xx, const void *extra)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
const void *old_extra;
|
|
|
|
|
|
|
|
/* Out with the old, and in with the new. */
|
|
|
|
old_extra = xx->extra;
|
1996-04-17 19:26:04 +00:00
|
|
|
xx->extra = o_retain(xx->extra_callbacks, extra, xx);
|
|
|
|
o_release(xx->extra_callbacks, (void *)old_extra, xx);
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
return old_extra;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resets XX's ``extra''. */
|
|
|
|
inline void
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_unset_extra (o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
/* Release XX's extra. */
|
1996-04-17 19:26:04 +00:00
|
|
|
o_release(xx->extra_callbacks, (void *)(xx->extra), xx);
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/* Reset XX's extra. */
|
|
|
|
xx->extra = (xx->extra_callbacks).not_an_item_marker;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Low-level Creation and Destruction **/
|
|
|
|
|
|
|
|
/* Handles the universal, low-level allocation of structures. */
|
1996-04-17 19:26:04 +00:00
|
|
|
inline o_@XX@_t *
|
|
|
|
_o_@XX@_alloc_with_zone(NSZone *zone)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_t *xx;
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/* Try to allocate some space for XX. */
|
1996-04-17 19:26:04 +00:00
|
|
|
xx = (o_@XX@_t *) NSZoneMalloc(zone, sizeof(o_@XX@_t));
|
1996-03-22 00:37:53 +00:00
|
|
|
|
1996-04-17 19:26:04 +00:00
|
|
|
/* The `o_malloc()' was successful. */
|
1996-03-22 00:37:53 +00:00
|
|
|
if (xx != 0)
|
|
|
|
{
|
1996-04-17 19:26:04 +00:00
|
|
|
_o_@XX@_set_serial_number(xx);
|
1996-03-22 00:37:53 +00:00
|
|
|
xx->magic_number = _OBJECTS_MAGIC_@XX@;
|
|
|
|
xx->name = 0;
|
1996-04-17 19:26:04 +00:00
|
|
|
xx->extra_callbacks = o_callbacks_for_non_owned_void_p;
|
1996-03-22 00:37:53 +00:00
|
|
|
xx->extra = 0;
|
|
|
|
|
|
|
|
/* Increment the counter of allocated structures. */
|
1996-04-17 19:26:04 +00:00
|
|
|
++(___o_number_allocated);
|
1996-03-22 00:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return xx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handles the universal, low-level deallocation of @XX@ structures. */
|
|
|
|
inline void
|
1996-04-17 19:26:04 +00:00
|
|
|
_o_@XX@_dealloc(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
|
|
|
/* Make sure XX is valid. */
|
|
|
|
if (xx != 0)
|
|
|
|
{
|
|
|
|
/* Free up any space we needed to keep track of XX's name. */
|
|
|
|
if (xx->name != 0)
|
1996-04-17 19:26:04 +00:00
|
|
|
NSZoneFree(o_@XX@_zone(xx), (char *)(xx->name));
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/* Release XX's extra. */
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_unset_extra(xx);
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/* Free up XX itself. */
|
1996-04-17 19:26:04 +00:00
|
|
|
NSZoneFree(o_@XX@_zone(xx), xx);
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/* Increment the counter of deallocated structures. */
|
1996-04-17 19:26:04 +00:00
|
|
|
++(___o_number_deallocated);
|
1996-03-22 00:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handles the low-level copying of structures. */
|
1996-04-17 19:26:04 +00:00
|
|
|
inline o_@XX@_t *
|
|
|
|
_o_@XX@_copy_with_zone(o_@XX@_t *xx, NSZone *zone)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_t *new;
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/* Create a new structure. */
|
1996-04-17 19:26:04 +00:00
|
|
|
new = _o_@XX@_alloc_with_zone(zone);
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
if (new != 0)
|
|
|
|
{
|
|
|
|
/* Copy over XX's name. */
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_set_name(new, o_@XX@_name(xx));
|
1996-03-22 00:37:53 +00:00
|
|
|
|
|
|
|
/* Copy over XX's extras. */
|
1996-04-17 19:26:04 +00:00
|
|
|
o_@XX@_set_extra_callbacks(new, o_@XX@_extra_callbacks(xx));
|
|
|
|
o_@XX@_set_extra(new, o_@XX@_extra(xx));
|
1996-03-22 00:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NSString *
|
1996-04-17 19:26:04 +00:00
|
|
|
_o_@XX@_description(o_@XX@_t *xx)
|
1996-03-22 00:37:53 +00:00
|
|
|
{
|
1996-05-27 15:00:24 +00:00
|
|
|
return [NSString
|
|
|
|
stringWithFormat: @"magic_number = %#x;\nserial_number = %d;\n"
|
|
|
|
@"name = %s;\nextra = %s;\nzone = %s;\n",
|
|
|
|
o_@XX@_magic_number(xx),
|
|
|
|
o_@XX@_serial_number(xx),
|
1998-09-30 07:42:38 +00:00
|
|
|
[o_@XX@_name(xx) cString],
|
1996-05-27 15:00:24 +00:00
|
|
|
[o_describe(o_@XX@_extra_callbacks(xx), o_@XX@_extra(xx), xx)
|
1998-09-30 07:42:38 +00:00
|
|
|
cString],
|
|
|
|
[NSZoneName(o_@XX@_zone(xx)) cString]];
|
1996-03-22 00:37:53 +00:00
|
|
|
}
|