Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Core::Object Class Reference

This is the main class of the library. More...

#include <Object.h>

Inheritance diagram for Core::Object:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 Object (void)
virtual ~Object (void)
virtual StringclassName (void) const
 Answer receiver class name.
virtual void error (String *message, String *selector=nil, Object *parameter=nil)
 Raise an Error with specified arguments.
virtual void shouldNotImplement (String *selector)
 Raise an Error saying that method should not be implemented.
virtual void shouldNotImplement (const char *selector)
virtual long hash (void) const
 Answer object hash value.
virtual bool isEqual (const Object *object) const
 Compare receiver with given object.
virtual bool isEqual (const Object &object) const
 Compare receiver with given object.
virtual bool isEqualToByteArray (const Object *array) const
virtual bool operator== (const Object &object) const
 Compare receiver with given object.
virtual bool isIdentical (const Object *object) const
 Answer if the parameter is identical with the receiver.
virtual bool isIdentical (const Object &object) const
 Answer if the parameter is identical with the receiver.
virtual void printOn (Stream *stream) const
 Print object identification into the stream.
virtual StringprintString (void) const
 Print object identification.
virtual bool isAssociation (void) const
 Answer if the receiver is an Association.
virtual bool isBoolean (void) const
 Answer if the receiver is a Boolean.
virtual bool isCharacter (void) const
 Answer if the receiver is a Character.
virtual bool isNumber (void) const
 Answer if the receiver is a Number.
virtual bool isString (void) const
 Answer if the receiver is a String.
virtual bool isInstanceOf (String *className)
 Test the receiver to be an instance of class of the given name.
virtual bool isInstanceOf (const char *className)
 Test the receiver to be an instance of class of the given name.
virtual void visitBy (Visitor *visitor)

Protected Attributes

long oid
 Object ID.

Detailed Description

This is the main class of the library.

Every class inherits from this one. It provides some basic features like comparing and testing facilities, simplified exception raising or stream printing.

Object class inherits from gc_cleanup class which provides garbage collecting (using Boehms conservative garbage collecting algorithm).

See also:
http://www.hpl.hp.com/personal/Hans_Boehm/gc/

Definition at line 70 of file Object.h.


Constructor & Destructor Documentation

Object::Object void   ) 
 

Definition at line 39 of file Object.cc.

References objectCounter, and oid.

00040 {
00041     oid = objectCounter++;
00042 #if defined(DEBUG) && defined(VERBOSE)
00043     fprintf(stderr, "%ld created (%p)\n", oid, this);
00044 #endif
00045 }

Object::~Object void   )  [virtual]
 

Definition at line 47 of file Object.cc.

References oid.

00048 {
00049 #if defined(DEBUG) && defined(VERBOSE)
00050     fprintf(stderr, "%ld destroyed (%p)\n", oid, this);
00051 #endif
00052 }


Member Function Documentation

String * Object::className void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented in Core::Array, Core::Association, Core::Boolean, Core::ByteArray, Core::ByteCharacterEncoder, Core::ByteStreamEncoder, Core::ByteString, Core::Character, Core::CharacterArray, Core::CharacterEncoder, Core::Collection, Core::CollectionIterator, Core::Date, Core::Dictionary, Core::EncodedStream, Core::EncodedStreamFactory, Core::Error, External::ExternalObjectNotFoundError, External::LibraryNotFoundError, Core::ExternalEncodedStreamFactory, Core::ExternalReadAppendStream, Core::ExternalReadStream, Core::ExternalStream, Core::ExternalWriteStream, Core::FileAccessor, Core::FileOpenFailed, Core::GenericException, Core::IncompleteNextCountError, Core::Integer, Core::InternalEncodedStreamFactory, Core::InternalStream, Core::IOAccessor, Core::IOBuffer, Core::KeysAndValuesIterator, Core::KeyNotFoundError, Core::Locale, Net::IPSocketAddress, Net::SocketAccessor, Net::URL, Core::NotFoundError, Core::Number, Core::OrderedCollection, OS::Promise, OS::SharedQueue, OS::Thread, OS::UnixPipe, Core::OSError, Core::PositionOutOfBoundsError, Core::PositionableStream, Core::ReadAppendStream, Core::ReadStream, Core::Real, Core::SearchTreeNode, Core::Set, Core::SubscriptOutOfBoundsError, Core::StreamEncoder, Core::String, Core::Time, Core::Timestamp, Tools::CommandLineMissingArgument, Tools::CommandLineParser, Tools::CommandLineParserError, Tools::CommandLineUnknownArgument, Tools::CommandLineUnsufficientParameters, Tools::Configuration, Tools::FileEncodedStreamFactory, Tools::Filename, Tools::HierarchicalConfigurationReader, Core::TwoByteString, Core::UCS2StreamEncoder, Core::UTF8StreamEncoder, Core::ValueNotFoundError, Core::Visitor, and Core::WriteStream.

Definition at line 55 of file Object.cc.

Referenced by Core::Time::isEqual(), Tools::Filename::isEqual(), and printOn().

00056 {
00057     return new String("Object");
00058 }

void Object::error String message,
String selector = nil,
Object parameter = nil
[virtual]
 

Raise an Error with specified arguments.

Definition at line 61 of file Object.cc.

References Core::GenericException::raiseFrom().

Referenced by Core::StringImpl::asByteString(), Core::StringImpl::asTwoByteString(), Tools::Filename::beCurrentDirectory(), Core::ByteCharacterEncoder::decode(), Core::UTF8StreamEncoder::decodeFrom(), Core::ByteStreamEncoder::decodeFrom(), Core::Collection::emptyCheck(), Core::ByteCharacterEncoder::encode(), Core::UCS2StreamEncoder::encodeTo(), Tools::Filename::erase(), Core::FileAccessor::FileAccessor(), OS::Environment::getEnv(), Core::KeysAndValuesIterator::key(), Tools::Filename::makeDirectory(), Tools::HierarchicalConfigurationReader::parseBlockOpenning(), Core::ExternalWriteStream::position(), Core::String::put(), Core::FileAccessor::readInto(), Core::SequenceableCollection::replace(), shouldNotImplement(), Core::KeysAndValuesIterator::value(), and OS::MessageQueue::writeFrom().

00062 {
00063     Error *ex = new Error(message, selector, parameter);
00064     ex->raiseFrom(this);
00065 }

long Object::hash void   )  const [virtual]
 

Answer object hash value.

The value should be same for objects found equal with isEqual() method. So if you rewrite this method you should rewrite isEqual() method too.

Reimplemented in Core::Association, Core::Boolean, Core::ByteArray, Core::Character, Core::Date, Core::Integer, Core::Real, Core::String, Core::Time, Core::Timestamp, and Tools::Filename.

Definition at line 78 of file Object.cc.

Referenced by Core::Set::findElementOrNil(), and Core::Association::hash().

00079 {
00080     return (long) this;
00081 }

bool Object::isAssociation void   )  const [virtual]
 

Answer if the receiver is an Association.

Reimplemented in Core::Association.

Definition at line 131 of file Object.cc.

Referenced by Core::Association::isEqual(), Core::KeysAndValuesIterator::key(), and Core::KeysAndValuesIterator::value().

00132 {
00133     return false;
00134 }

bool Object::isBoolean void   )  const [virtual]
 

Answer if the receiver is a Boolean.

Reimplemented in Core::Boolean.

Definition at line 136 of file Object.cc.

Referenced by Core::Boolean::isEqual().

00137 {
00138     return false;
00139 }

bool Object::isCharacter void   )  const [virtual]
 

Answer if the receiver is a Character.

Reimplemented in Core::Character.

Definition at line 141 of file Object.cc.

Referenced by Core::String::put(), Core::Stream::skipSeparators(), and Core::Stream::upToSeparator().

00142 {
00143     return false;
00144 }

bool Object::isEqual const Object object  )  const [virtual]
 

Compare receiver with given object.

Do not rewrite this method. It just a sugar for Object::isEqual(Object *).

  • object - object to compare receiver with

Reimplemented in Core::Boolean, Core::ByteArray, Core::Character, Core::Date, Core::Integer, Core::Number, Core::Real, Core::String, Core::Time, Core::Timestamp, and Tools::Filename.

Definition at line 88 of file Object.cc.

References isEqual().

00089 {
00090     return isEqual(&object);
00091 }

bool Object::isEqual const Object object  )  const [virtual]
 

Compare receiver with given object.

This method could compare objects with more sophisticated algorithm (eg. based on instance variables comparing or so).

If you rewrite this method you should rewrite hash() too.

  • object - object to compare receiver with

Reimplemented in Core::Association, Core::Boolean, Core::ByteArray, Core::Character, Core::Date, Core::Integer, Core::Number, Core::Real, Core::String, Core::Time, Core::Timestamp, and Tools::Filename.

Definition at line 83 of file Object.cc.

References isIdentical().

Referenced by Core::Set::findElementOrNil(), Core::Timestamp::isEqual(), Core::Time::isEqual(), Core::String::isEqual(), isEqual(), Core::Number::isEqual(), Core::Date::isEqual(), Core::Character::isEqual(), Core::ByteArray::isEqual(), Core::Boolean::isEqual(), Core::Association::isEqual(), Core::SequenceableCollection::nextIndexOf(), Core::LineEndConvertor::nextPut(), operator==(), Core::PositionableStream::peekFor(), Core::SequenceableCollection::prevIndexOf(), Core::Stream::upTo(), and Core::Stream::upToAll().

00084 {
00085     return isIdentical(object);
00086 }

bool Object::isEqualToByteArray const Object array  )  const [virtual]
 

Reimplemented in Core::ByteArray.

Definition at line 93 of file Object.cc.

Referenced by Core::ByteArray::isEqual().

00094 {
00095     return false;
00096 }

bool Object::isIdentical const Object object  )  const [virtual]
 

Answer if the parameter is identical with the receiver.

Do not rewrite this method. It just a sugar for Object::isIdentical(Object *).

  • object - object to compare receiver with

Definition at line 108 of file Object.cc.

References isIdentical().

00109 {
00110     return isIdentical(&object);
00111 }

bool Object::isIdentical const Object object  )  const [virtual]
 

Answer if the parameter is identical with the receiver.

In fact every object is identical only with itself.

  • object - object to compare receiver with

Definition at line 103 of file Object.cc.

Referenced by isEqual(), and isIdentical().

00104 {
00105     return this == object;
00106 }

bool Object::isInstanceOf const char *  className  )  [virtual]
 

Test the receiver to be an instance of class of the given name.

Do not rewrite this method. It just a sugar for Object::isInstanceOf(String *).

  • className - name of class the receiver might be an instance of

Definition at line 161 of file Object.cc.

References isInstanceOf().

00162 {
00163     return(this->isInstanceOf(new String(className)));
00164 }

bool Object::isInstanceOf String className  )  [virtual]
 

Test the receiver to be an instance of class of the given name.

  • className - name of class the receiver might be an instance of

Definition at line 156 of file Object.cc.

References Core::String::isEqual().

Referenced by isInstanceOf().

00157 {
00158     return(className->isEqual(this->className()));
00159 }

bool Object::isNumber void   )  const [virtual]
 

Answer if the receiver is a Number.

Reimplemented in Core::Number.

Definition at line 146 of file Object.cc.

Referenced by Core::ByteArray::checkObject().

00147 {
00148     return false;
00149 }

bool Object::isString void   )  const [virtual]
 

Answer if the receiver is a String.

Reimplemented in Core::String.

Definition at line 151 of file Object.cc.

Referenced by Core::String::isEqual().

00152 {
00153     return false;
00154 }

bool Object::operator== const Object object  )  const [virtual]
 

Compare receiver with given object.

By default this calls isEqual() method. But some classes (numbers) may overload it to avoid type matching.

Definition at line 98 of file Object.cc.

References isEqual().

00099 {
00100     return isEqual(&object);
00101 }

void Object::printOn Stream stream  )  const [virtual]
 

Print object identification into the stream.

Object identification is formed from its className() by default. But complicated classes (eg. collections) may print some other information.

  • stream - stream to print to.

Reimplemented in Core::Association, Core::Boolean, Core::Character, Core::Collection, Core::Date, Core::Integer, Net::IPSocketAddress, Net::URL, Core::Real, Core::String, Core::Time, Core::Timestamp, and Tools::Configuration.

Definition at line 114 of file Object.cc.

References className(), Core::SequenceableCollection::first(), and Core::Stream::nextPutAll().

Referenced by Tools::Application::defaultExceptionHandler(), and printString().

00115 {
00116     String *title = className();   // self class printString
00117     if (((Character *) title->first())->isVowel())
00118         stream->nextPutAll("an ");
00119     else stream->nextPutAll("a ");
00120     stream->nextPutAll(title);
00121 }

String * Object::printString void   )  const [virtual]
 

Print object identification.

Definition at line 123 of file Object.cc.

References Core::WriteStream::contents(), and printOn().

Referenced by Core::ExternalWriteStream::closeConnection().

00124 {
00125     WriteStream stream(new String(16));
00126     printOn(&stream);
00127     return (String *) stream.contents();
00128 }

void Object::shouldNotImplement const char *  selector  )  [virtual]
 

Definition at line 72 of file Object.cc.

References shouldNotImplement().

00073 {
00074     shouldNotImplement(new String(selector));
00075 }

void Object::shouldNotImplement String selector  )  [virtual]
 

Raise an Error saying that method should not be implemented.

This is called in situation when the method has no sense in the class but has to be implemented somehow (eg. to break class abstraction).

  • selector - name of the method which should not be implemented.
    See also:
    WriteStream::next

Definition at line 67 of file Object.cc.

References error().

Referenced by Core::String::add(), Core::ByteArray::add(), Core::Array::add(), Core::SequenceableCollection::asByteArray(), Core::SequenceableCollection::asString(), Core::IOAccessor::changeDescriptorTo(), Core::Callback< void >::execute(), Core::Callback< Object * >::execute(), Core::ReadStream::flush(), Core::WriteStream::next(), Core::ExternalWriteStream::next(), Core::ReadStream::nextPut(), Core::ExternalReadStream::nextPut(), Core::SequenceableCollection::remove(), Core::Dictionary::remove(), OS::UnixPipe::seekTo(), Net::SocketAccessor::seekTo(), OS::MessageQueue::seekTo(), and shouldNotImplement().

00068 {
00069     error(new String("Message is not appropriate for this object"), selector);
00070 }

void Object::visitBy Visitor visitor  )  [virtual]
 

Reimplemented in Core::Association, Core::Boolean, Core::Character, Core::Collection, Core::Dictionary, Core::GenericException, Core::Number, and Core::String.

Definition at line 167 of file Object.cc.

References Core::Visitor::visitObject().

00168 {
00169     visitor->visitObject(this);
00170 }


Member Data Documentation

long Core::Object::oid [protected]
 

Object ID.

Every object got its unique number.

Definition at line 76 of file Object.h.

Referenced by Object(), and ~Object().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:51:46 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2