00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stlib/Object.h>
00025 #include <stlib/Character.h>
00026 #include <stlib/Collection.h>
00027 #include <stlib/String.h>
00028 #include <stlib/Stream.h>
00029 #include <stlib/Visitor.h>
00030 #include <stlib/WriteStream.h>
00031
00032 #include <stlib/Error.h>
00033 #include <stlib/NotFoundError.h>
00034
00035 #include <stdio.h>
00036
00037 static long objectCounter = 0;
00038
00039 Object::Object(void)
00040 {
00041 oid = objectCounter++;
00042 #if defined(DEBUG) && defined(VERBOSE)
00043 fprintf(stderr, "%ld created (%p)\n", oid, this);
00044 #endif
00045 }
00046
00047 Object::~Object(void)
00048 {
00049 #if defined(DEBUG) && defined(VERBOSE)
00050 fprintf(stderr, "%ld destroyed (%p)\n", oid, this);
00051 #endif
00052 }
00053
00054
00055 String *Object::className(void) const
00056 {
00057 return new String("Object");
00058 }
00059
00060
00061 void Object::error(String *message, String *selector, Object *parameter)
00062 {
00063 Error *ex = new Error(message, selector, parameter);
00064 ex->raiseFrom(this);
00065 }
00066
00067 void Object::shouldNotImplement(String *selector)
00068 {
00069 error(new String("Message is not appropriate for this object"), selector);
00070 }
00071
00072 void Object::shouldNotImplement(const char *selector)
00073 {
00074 shouldNotImplement(new String(selector));
00075 }
00076
00077
00078 long Object::hash(void) const
00079 {
00080 return (long) this;
00081 }
00082
00083 bool Object::isEqual(const Object *object) const
00084 {
00085 return isIdentical(object);
00086 }
00087
00088 bool Object::isEqual(const Object &object) const
00089 {
00090 return isEqual(&object);
00091 }
00092
00093 bool Object::isEqualToByteArray(const Object *object) const
00094 {
00095 return false;
00096 }
00097
00098 bool Object::operator==(const Object &object) const
00099 {
00100 return isEqual(&object);
00101 }
00102
00103 bool Object::isIdentical(const Object *object) const
00104 {
00105 return this == object;
00106 }
00107
00108 bool Object::isIdentical(const Object &object) const
00109 {
00110 return isIdentical(&object);
00111 }
00112
00113
00114 void Object::printOn(Stream *stream) const
00115 {
00116 String *title = className();
00117 if (((Character *) title->first())->isVowel())
00118 stream->nextPutAll("an ");
00119 else stream->nextPutAll("a ");
00120 stream->nextPutAll(title);
00121 }
00122
00123 String *Object::printString(void) const
00124 {
00125 WriteStream stream(new String(16));
00126 printOn(&stream);
00127 return (String *) stream.contents();
00128 }
00129
00130
00131 bool Object::isAssociation(void) const
00132 {
00133 return false;
00134 }
00135
00136 bool Object::isBoolean(void) const
00137 {
00138 return false;
00139 }
00140
00141 bool Object::isCharacter(void) const
00142 {
00143 return false;
00144 }
00145
00146 bool Object::isNumber(void) const
00147 {
00148 return false;
00149 }
00150
00151 bool Object::isString(void) const
00152 {
00153 return false;
00154 }
00155
00156 bool Object::isInstanceOf(String *className)
00157 {
00158 return(className->isEqual(this->className()));
00159 }
00160
00161 bool Object::isInstanceOf(const char* className)
00162 {
00163 return(this->isInstanceOf(new String(className)));
00164 }
00165
00166
00167 void Object::visitBy(Visitor *visitor)
00168 {
00169 visitor->visitObject(this);
00170 }