| 1 | /* The implementation of class Object for Objective-C.
|
|---|
| 2 | Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU CC.
|
|---|
| 5 |
|
|---|
| 6 | GNU CC is free software; you can redistribute it and/or modify it
|
|---|
| 7 | under the terms of the GNU General Public License as published by the
|
|---|
| 8 | Free Software Foundation; either version 2, or (at your option) any
|
|---|
| 9 | later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU CC is distributed in the hope that it will be useful, but WITHOUT
|
|---|
| 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|---|
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|---|
| 14 | License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU CC; see the file COPYING. If not, write to
|
|---|
| 18 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
|---|
| 19 | Boston, 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 |
|
|---|
| 32 | extern 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 | }
|
|---|
|
|---|