source: trunk/src/gcc/libobjc/Object.m@ 46

Last change on this file since 46 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 8.0 KB
Line 
1/* The implementation of class Object for Objective-C.
2 Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU CC is distributed in the hope that it will be useful, but WITHOUT
12ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21/* As a special exception, if you link this library with files compiled
22 with GCC to produce an executable, this does not cause the resulting
23 executable to be covered by the GNU General Public License. This
24 exception does not however invalidate any other reasons why the
25 executable file might be covered by the GNU General Public License. */
26
27#include <stdarg.h>
28#include "objc/Object.h"
29#include "objc/Protocol.h"
30#include "objc/objc-api.h"
31
32extern int errno;
33
34#define MAX_CLASS_NAME_LEN 256
35
36@implementation Object
37
38+ initialize
39{
40 return self;
41}
42
43- init
44{
45 return self;
46}
47
48+ new
49{
50 return [[self alloc] init];
51}
52
53+ alloc
54{
55 return class_create_instance(self);
56}
57
58- free
59{
60 return object_dispose(self);
61}
62
63- copy
64{
65 return [[self shallowCopy] deepen];
66}
67
68- shallowCopy
69{
70 return object_copy(self);
71}
72
73- deepen
74{
75 return self;
76}
77
78- deepCopy
79{
80 return [self copy];
81}
82
83- (Class)class
84{
85 return object_get_class(self);
86}
87
88- (Class)superClass
89{
90 return object_get_super_class(self);
91}
92
93- (MetaClass)metaClass
94{
95 return object_get_meta_class(self);
96}
97
98- (const char *)name
99{
100 return object_get_class_name(self);
101}
102
103- self
104{
105 return self;
106}
107
108- (unsigned int)hash
109{
110 return (size_t)self;
111}
112
113- (BOOL)isEqual:anObject
114{
115 return self==anObject;
116}
117
118- (int)compare:anotherObject;
119{
120 if ([self isEqual:anotherObject])
121 return 0;
122 // Ordering objects by their address is pretty useless,
123 // so subclasses should override this is some useful way.
124 else if (self > anotherObject)
125 return 1;
126 else
127 return -1;
128}
129
130- (BOOL)isMetaClass
131{
132 return NO;
133}
134
135- (BOOL)isClass
136{
137 return object_is_class(self);
138}
139
140- (BOOL)isInstance
141{
142 return object_is_instance(self);
143}
144
145- (BOOL)isKindOf:(Class)aClassObject
146{
147 Class class;
148
149 for (class = self->isa; class!=Nil; class = class_get_super_class(class))
150 if (class==aClassObject)
151 return YES;
152 return NO;
153}
154
155- (BOOL)isMemberOf:(Class)aClassObject
156{
157 return self->isa==aClassObject;
158}
159
160- (BOOL)isKindOfClassNamed:(const char *)aClassName
161{
162 Class class;
163
164 if (aClassName!=NULL)
165 for (class = self->isa; class!=Nil; class = class_get_super_class(class))
166 if (!strcmp(class_get_class_name(class), aClassName))
167 return YES;
168 return NO;
169}
170
171- (BOOL)isMemberOfClassNamed:(const char *)aClassName
172{
173 return ((aClassName!=NULL)
174 &&!strcmp(class_get_class_name(self->isa), aClassName));
175}