1999-04-12 12:53:30 +00:00
|
|
|
/*
|
|
|
|
* GSUnion.h
|
|
|
|
* File to set up a typedef for a union capable of containing various types.
|
|
|
|
* Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
* Created: Apr 1999
|
|
|
|
*
|
|
|
|
* This file is part of the GNUstep Base Library.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1999-04-12 12:53:30 +00:00
|
|
|
* License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
* version 2 of the License, or (at your option) any later version.
|
1999-04-12 12:53:30 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2007-09-14 11:36:11 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1999-04-12 12:53:30 +00:00
|
|
|
* License along with this library; if not, write to the Free
|
2006-09-13 10:20:49 +00:00
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02111 USA. */
|
1999-04-12 12:53:30 +00:00
|
|
|
|
2008-06-16 15:33:05 +00:00
|
|
|
/* Need Foundation/NSObjCRuntime.h for type declarations.
|
|
|
|
*/
|
|
|
|
#import <Foundation/NSObjCRuntime.h>
|
|
|
|
|
2009-02-16 23:04:30 +00:00
|
|
|
/* These are not defined in older Mac OS X systems */
|
|
|
|
#ifndef NSINTEGER_DEFINED
|
2010-03-08 06:43:14 +00:00
|
|
|
typedef intptr_t NSInteger;
|
|
|
|
typedef uintptr_t NSUInteger;
|
2009-02-16 23:04:30 +00:00
|
|
|
#define NSINTEGER_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
1999-04-12 12:53:30 +00:00
|
|
|
/*
|
|
|
|
* Definitions for bitmap mask of types of element in union.
|
|
|
|
*/
|
|
|
|
#ifndef GSUNION_OBJ
|
|
|
|
|
|
|
|
#define GSUNION_OBJ 0x0001
|
|
|
|
#define GSUNION_CLS 0x0002
|
|
|
|
#define GSUNION_SEL 0x0004
|
|
|
|
#define GSUNION_PTR 0x0080
|
2010-03-08 06:43:14 +00:00
|
|
|
#define GSUNION_NSINT 0x1000
|
1999-04-12 12:53:30 +00:00
|
|
|
|
2010-03-08 06:43:14 +00:00
|
|
|
#define GSUNION_ALL 0x1fff
|
1999-04-12 12:53:30 +00:00
|
|
|
|
|
|
|
#endif /* GSUNION_OBJ */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Produce a typedef for a union with name 'GSUNION' containing elements
|
|
|
|
* specified in the GSUNION_TYPES mask, and optionally with an extra
|
|
|
|
* element 'ext' of the type specified in GSUNION_EXTRA
|
|
|
|
*
|
|
|
|
* You can include this file more than once in order to produce different
|
|
|
|
* typedefs as long as you redefine 'GSUNION' before each inclusion.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(GSUNION) && defined(GSUNION_TYPES)
|
|
|
|
|
|
|
|
typedef union {
|
2011-03-29 08:16:02 +00:00
|
|
|
NSUInteger addr; /* Always present */
|
2002-02-20 08:32:08 +00:00
|
|
|
#if ((GSUNION_TYPES) & GSUNION_OBJ)
|
1999-04-12 12:53:30 +00:00
|
|
|
id obj;
|
|
|
|
NSObject *nso;
|
|
|
|
#endif
|
2002-02-20 08:32:08 +00:00
|
|
|
#if ((GSUNION_TYPES) & GSUNION_CLS)
|
1999-04-12 12:53:30 +00:00
|
|
|
Class cls;
|
|
|
|
#endif
|
2002-02-20 08:32:08 +00:00
|
|
|
#if ((GSUNION_TYPES) & GSUNION_SEL)
|
1999-04-12 12:53:30 +00:00
|
|
|
SEL sel;
|
|
|
|
#endif
|
2011-03-29 08:16:02 +00:00
|
|
|
#if ((GSUNION_TYPES) & GSUNION_NSINT)
|
|
|
|
NSInteger nsi;
|
|
|
|
NSUInteger nsu;
|
|
|
|
#endif
|
|
|
|
#if ((GSUNION_TYPES) & GSUNION_PTR)
|
|
|
|
void *ptr;
|
|
|
|
const void *cptr;
|
|
|
|
char *str;
|
|
|
|
const char *cstr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Warning ... if this value is declared in the union, and its type is not
|
|
|
|
* the same size as a pointer, then care must be taken in case of confusion
|
|
|
|
* caused when an assignment to a variable using one of the union's types
|
|
|
|
* causes part of the variable to ebe left with undefined content from the
|
|
|
|
* point of view of another of the union's types.
|
|
|
|
*/
|
1999-04-12 12:53:30 +00:00
|
|
|
#if defined(GSUNION_EXTRA)
|
|
|
|
GSUNION_EXTRA ext;
|
|
|
|
#endif
|
|
|
|
} GSUNION;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|