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

Core::Association Class Reference

This class represents key - value relation betwen two Objects. More...

#include <Association.h>

Inheritance diagram for Core::Association:

Inheritance graph
[legend]
Collaboration diagram for Core::Association:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Association (Object *key, Object *value)
virtual StringclassName (void) const
 Answer receiver class name.
 Association (const Association &origin)
virtual Objectkey (void)
virtual void key (Object *)
virtual Objectvalue (void)
virtual void value (Object *)
virtual long hash (void) const
 Answer object hash value.
virtual bool isEqual (const Object *object) const
 Compare receiver with given object.
virtual Objectcopy (void)
 Answer copy of the receiver.
virtual void printOn (Stream *stream) const
 Print object identification into the stream.
virtual bool isAssociation (void) const
 Answer if the receiver is an Association.
virtual void visitBy (Visitor *visitor)

Protected Attributes

Object_key
 Relation key.
Object_value
 Relation value associated with the key.

Detailed Description

This class represents key - value relation betwen two Objects.

It's used mainly by Dictionary.

Definition at line 38 of file Association.h.


Constructor & Destructor Documentation

Association::Association Object key,
Object value
 

Definition at line 29 of file Association.cc.

References _key, and _value.

Referenced by copy().

00030 {
00031     _key = key;
00032     _value = value;
00033 }

Association::Association const Association origin  ) 
 

Definition at line 36 of file Association.cc.

References _key, and _value.

00037   : Object(origin)
00038 {
00039     _key = origin._key;
00040     _value = origin._value;
00041 }


Member Function Documentation

String * Association::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 from Core::Object.

Definition at line 44 of file Association.cc.

00045 {
00046     return new String("Association");
00047 }

Object * Association::copy void   )  [virtual]
 

Answer copy of the receiver.

Return value is definitely an Association.

Definition at line 87 of file Association.cc.

References Association().

00088 {
00089     return new Association(*this);
00090 }

long Association::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 from Core::Object.

Definition at line 71 of file Association.cc.

References _key, Core::Object::hash(), and nil.

00072 {
00073     if (_key == nil) return Object::hash();
00074                 else return _key->hash();
00075 }

bool Association::isAssociation void   )  const [virtual]
 

Answer if the receiver is an Association.

Reimplemented from Core::Object.

Definition at line 102 of file Association.cc.

00103 {
00104     return true;
00105 }

bool Association::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 from Core::Object.

Definition at line 77 of file Association.cc.

References _key, _value, Core::Object::isAssociation(), and Core::Object::isEqual().

00078 {
00079     if (object->isAssociation() && Object::isEqual(object)) {
00080         return _key == ((Association *) object)->key() &&
00081                _value == ((Association *) object)->value();
00082     }
00083     return false;
00084 }

void Association::key Object  )  [virtual]
 

Definition at line 50 of file Association.cc.

References _key.

00051 {
00052     _key = object;
00053 }

Object * Association::key void   )  [virtual]
 

Definition at line 55 of file Association.cc.

References _key.

Referenced by Core::Dictionary::findKeyOrNil(), Core::Dictionary::fixCollisionsFrom(), and Core::Visitor::visitAssociation().

00056 {
00057     return _key;
00058 }

void Association::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 from Core::Object.

Definition at line 93 of file Association.cc.

References _key, _value, Core::Stream::nextPutAll(), nil, and Core::Stream::print().

00094 {
00095     stream->print(_key);
00096     stream->nextPutAll("->");
00097     if (_value == nil) stream->nextPutAll("nil");
00098                   else stream->print(_value);
00099 }

void Association::value Object  )  [virtual]
 

Definition at line 60 of file Association.cc.

References _value.

00061 {
00062     _value = object;
00063 }

Object * Association::value void   )  [virtual]
 

Definition at line 65 of file Association.cc.

References _value.

Referenced by Core::Dictionary::add(), Core::Dictionary::at(), Core::Dictionary::put(), Core::Dictionary::removeKey(), Core::Character::value(), and Core::Visitor::visitAssociation().

00066 {
00067     return _value;
00068 }

void Association::visitBy Visitor visitor  )  [virtual]
 

Reimplemented from Core::Object.

Definition at line 108 of file Association.cc.

References Core::Visitor::visitAssociation().

00109 {
00110     visitor->visitAssociation(this);
00111 }


Member Data Documentation

Object* Core::Association::_key [protected]
 

Relation key.

Definition at line 41 of file Association.h.

Referenced by Association(), hash(), isEqual(), key(), and printOn().

Object* Core::Association::_value [protected]
 

Relation value associated with the key.

Definition at line 42 of file Association.h.

Referenced by Association(), isEqual(), printOn(), and value().


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