~ubuntu-branches/ubuntu/breezy/gnustep-base/breezy

« back to all changes in this revision

Viewing changes to Headers/gnustep/base/NSObjCRuntime.h

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (4 hoary)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Interface to ObjC runtime for GNUStep
2
 
   Copyright (C) 1995, 1997, 2000 Free Software Foundation, Inc.
3
 
 
4
 
   Written by:  Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
5
 
   Date: 1995
6
 
   
7
 
   This file is part of the GNUstep Base Library.
8
 
 
9
 
   This library is free software; you can redistribute it and/or
10
 
   modify it under the terms of the GNU Library General Public
11
 
   License as published by the Free Software Foundation; either
12
 
   version 2 of the License, or (at your option) any later version.
13
 
   
14
 
   This library is distributed in the hope that it will be useful,
15
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 
   Library General Public License for more details.
18
 
   
19
 
   You should have received a copy of the GNU Library General Public
20
 
   License along with this library; if not, write to the Free
21
 
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
22
 
   */ 
23
 
 
24
 
#ifndef __NSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
25
 
#define __NSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
26
 
 
27
 
#include <objc/objc.h>
28
 
#include <objc/objc-api.h>
29
 
#include <stdarg.h>
30
 
 
31
 
#if BUILD_libgnustep_base_DLL
32
 
#  define GS_EXPORT  __declspec(dllexport)
33
 
#  define GS_DECLARE __declspec(dllexport)
34
 
#elif libgnustep_base_ISDLL
35
 
#  define GS_EXPORT  extern __declspec(dllimport)
36
 
#  define GS_DECLARE __declspec(dllimport)
37
 
#else
38
 
#  define GS_EXPORT extern
39
 
#  define GS_DECLARE
40
 
#endif
41
 
 
42
 
@class  NSObject;
43
 
@class  NSString;
44
 
 
45
 
GS_EXPORT NSString      *NSStringFromSelector(SEL aSelector);
46
 
GS_EXPORT SEL           NSSelectorFromString(NSString *aSelectorName);
47
 
GS_EXPORT Class         NSClassFromString(NSString *aClassName);
48
 
GS_EXPORT NSString      *NSStringFromClass(Class aClass);
49
 
GS_EXPORT const char    *NSGetSizeAndAlignment(const char *typePtr,
50
 
  unsigned int *sizep, unsigned int *alignp);
51
 
 
52
 
/* Logging */
53
 
/* OpenStep spec states that log messages go to stderr, but just in case
54
 
   someone wants them to go somewhere else, they can implement a function
55
 
   like this */
56
 
typedef void NSLog_printf_handler (NSString* message);
57
 
GS_EXPORT NSLog_printf_handler  *_NSLog_printf_handler;
58
 
 
59
 
GS_EXPORT void                  NSLog (NSString* format, ...);
60
 
GS_EXPORT void                  NSLogv (NSString* format, va_list args);
61
 
 
62
 
#ifndef YES
63
 
#define YES             1
64
 
#endif
65
 
#ifndef NO
66
 
#define NO              0
67
 
#endif
68
 
#ifndef nil
69
 
#define nil             0
70
 
#endif
71
 
 
72
 
#define FOUNDATION_EXPORT
73
 
#define FOUNDATION_STATIC_INLINE static inline
74
 
 
75
 
#ifndef NO_GNUSTEP
76
 
/*
77
 
 * Functions for accessing instance variables directly -
78
 
 * We can copy an ivar into arbitrary data,
79
 
 * Get the type encoding for a named ivar,
80
 
 * and copy a value into an ivar.
81
 
 */
82
 
GS_EXPORT BOOL GSFindInstanceVariable(id obj, const char *name,
83
 
  const char **type, unsigned int *size, int *offset);
84
 
GS_EXPORT void GSGetVariable(id obj, int offset, unsigned int size, void *data);
85
 
GS_EXPORT void GSSetVariable(id obj, int offset, unsigned int size,
86
 
  const void *data);
87
 
 
88
 
/*
89
 
 * Functions for key-value encoding ... they access values in an object
90
 
 * either by selector or directly, but do so using NSNumber for the
91
 
 * scalar types of data.
92
 
 */
93
 
GS_EXPORT id GSGetValue(NSObject *self, NSString *key, SEL sel,
94
 
  const char *type, unsigned size, int offset);
95
 
GS_EXPORT void GSSetValue(NSObject *self, NSString *key, id val, SEL sel,
96
 
  const char *type, unsigned size, int offset);
97
 
 
98
 
/*
99
 
 * The following three functions are deprecated and will be removed in future
100
 
 */
101
 
GS_EXPORT BOOL GSInstanceVariableInfo(id obj, NSString *iVarName,
102
 
  const char **type, unsigned *size, unsigned *offset);
103
 
GS_EXPORT BOOL GSGetInstanceVariable(id obj, NSString *name, void* data);
104
 
GS_EXPORT BOOL GSSetInstanceVariable(id obj, NSString *name, const void* data);
105
 
 
106
 
#include <base/objc-gnu2next.h>
107
 
 
108
 
/*
109
 
 * GSObjCClass() return the class of an instance.
110
 
 * The argument to this function must NOT be nil.
111
 
 */
112
 
FOUNDATION_STATIC_INLINE Class
113
 
GSObjCClass(id obj)
114
 
{
115
 
  return obj->class_pointer;
116
 
}
117
 
 
118
 
/*
119
 
 * GSObjCIsInstance() tests to see if an id is an instance.
120
 
 * The argument to this function must NOT be nil.
121
 
 */
122
 
FOUNDATION_STATIC_INLINE BOOL
123
 
GSObjCIsInstance(id obj)
124
 
{
125
 
  return CLS_ISCLASS(obj->class_pointer);
126
 
}
127
 
 
128
 
/*
129
 
 * GSObjCIsKindOf() tests to see if a class inherits from another class
130
 
 * The argument to this function must NOT be nil.
131
 
 */
132
 
FOUNDATION_STATIC_INLINE BOOL
133
 
GSObjCIsKindOf(Class this, Class other)
134
 
{
135
 
  while (this != Nil)
136
 
    {
137
 
      if (this == other)
138
 
        {
139
 
          return YES;
140
 
        }
141
 
      this = class_get_super_class(this);
142
 
    }
143
 
  return NO;
144
 
}
145
 
 
146
 
/** ## deprecated ##
147
 
 */
148
 
FOUNDATION_STATIC_INLINE const char*
149
 
GSObjCName(Class this)
150
 
{
151
 
  return class_get_class_name(this);
152
 
}
153
 
 
154
 
/** ## deprecated ##
155
 
 */
156
 
FOUNDATION_STATIC_INLINE const char*
157
 
GSObjCSelectorName(SEL this)
158
 
{
159
 
  if (this == 0)
160
 
    return 0;
161
 
  return sel_get_name(this);
162
 
}
163
 
 
164
 
/** ## deprecated ##
165
 
 */
166
 
FOUNDATION_STATIC_INLINE const char*
167
 
GSObjCSelectorTypes(SEL this)
168
 
{
169
 
  return sel_get_type(this);
170
 
}
171
 
 
172
 
 
173
 
 
174
 
 
175
 
/**
176
 
 * Given a class name, return the corresponding class or
177
 
 * a nul pointer if the class cannot be found. <br />
178
 
 * If the argument is nil, return a nul pointer.
179
 
 */
180
 
FOUNDATION_STATIC_INLINE Class
181
 
GSClassFromName(const char *name)
182
 
{
183
 
  if (name == 0)
184
 
    return 0;
185
 
  return objc_lookup_class(name);
186
 
}
187
 
 
188
 
/**
189
 
 * Return the name of the supplied class, or a nul pointer if no class
190
 
 * was supplied.
191
 
 */
192
 
FOUNDATION_STATIC_INLINE const char*
193
 
GSNameFromClass(Class this)
194
 
{
195
 
  if (this == 0)
196
 
    return 0;
197
 
  return class_get_class_name(this);
198
 
}
199
 
 
200
 
/**
201
 
 * Return the name of the supplied selector, or a nul pointer if no selector
202
 
 * was supplied.
203
 
 */
204
 
FOUNDATION_STATIC_INLINE const char*
205
 
GSNameFromSelector(SEL this)
206
 
{
207
 
  if (this == 0)
208
 
    return 0;
209
 
  return sel_get_name(this);
210
 
}
211
 
 
212
 
/**
213
 
 * Return a selector matching the specified name, or nil if no name is
214
 
 * supplied.  The returned selector could be any one with the name.<br />
215
 
 * If no selector exists, returns nil.
216
 
 */
217
 
FOUNDATION_STATIC_INLINE SEL
218
 
GSSelectorFromName(const char *name)
219
 
{
220
 
  if (name == 0)
221
 
    {
222
 
      return 0;
223
 
    }
224
 
  else
225
 
    {
226
 
      return sel_get_any_uid(name);
227
 
    }
228
 
}
229
 
 
230
 
/**
231
 
 * Return the selector for the specified name and types.  Returns a nul
232
 
 * pointer if the name is nul.  Uses any available selector if the types
233
 
 * argument is nul. <br />
234
 
 * Creates a new selector if necessary.
235
 
 */
236
 
FOUNDATION_STATIC_INLINE SEL
237
 
GSSelectorFromNameAndTypes(const char *name, const char *types)
238
 
{
239
 
  if (name == 0)
240
 
    {
241
 
      return 0;
242
 
    }
243
 
  else
244
 
    {
245
 
      SEL       s;
246
 
 
247
 
      if (types == 0)
248
 
        {
249
 
          s = sel_get_any_typed_uid(name);
250
 
        }
251
 
      else
252
 
        {
253
 
          s = sel_get_typed_uid(name, types);
254
 
        }
255
 
      if (s == 0)
256
 
        {
257
 
          if (types == 0)
258
 
            {
259
 
              s = sel_register_name(name);
260
 
            }
261
 
          else
262
 
            {
263
 
              s = sel_register_typed_name(name, types);
264
 
            }
265
 
        }
266
 
      return s;
267
 
    }
268
 
 
269
 
}
270
 
 
271
 
/**
272
 
 * Return the type information from the specified selector.
273
 
 * May return a nul pointer if the selector was a nul pointer or if it
274
 
 * was not typed.
275
 
 */
276
 
FOUNDATION_STATIC_INLINE const char*
277
 
GSTypesFromSelector(SEL this)
278
 
{
279
 
  if (this == 0)
280
 
    return 0;
281
 
  return sel_get_type(this);
282
 
}
283
 
 
284
 
 
285
 
FOUNDATION_STATIC_INLINE Class
286
 
GSObjCSuper(Class this)
287
 
{
288
 
  return class_get_super_class(this);
289
 
}
290
 
 
291
 
FOUNDATION_STATIC_INLINE int
292
 
GSObjCVersion(Class this)
293
 
{
294
 
  return class_get_version(this);
295
 
}
296
 
 
297
 
/*
298
 
 * Return the zone in which an object belongs, without using the zone method
299
 
 */
300
 
#include        <Foundation/NSZone.h>
301
 
GS_EXPORT NSZone *GSObjCZone(NSObject *obj);
302
 
 
303
 
/*
304
 
 * Quickly return autoreleased data.
305
 
 */
306
 
void    *_fastMallocBuffer(unsigned size);
307
 
 
308
 
/* Getting a system error message on a variety of systems */
309
 
GS_EXPORT const char *GSLastErrorStr(long error_id);
310
 
 
311
 
#endif
312
 
 
313
 
#endif /* __NSObjCRuntime_h_GNUSTEP_BASE_INCLUDE */