container::Entity Class Reference

The base class of all items that can be stored in a Container. More...

#include <entity.h>

Inheritance diagram for container::Entity:

Inheritance graph
[legend]
Collaboration diagram for container::Entity:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Entity ()
 Entity (int key)
 Constructor for creating an Entity with a specific key.
 Entity (const Entity &pattern)
virtual ~Entity ()
Entityoperator= (const Entity &second)
virtual int compareKeyTo (const Entity &second) const
 Compare this Entity with second.
const string & getKeyAsString () const
 Return an Entity object's key in a string representation.
virtual ostream & renderState (ostream &os) const
 Write the state of an Object for debugging and demonstration.
virtual const InfotypeInfo () const
 Return the instance of Object::Info that describes the class of this object.
virtual Objectclone (bool deepCopy=false) const
 A polymorphic copy constructor.

Static Public Attributes

static const Info *const TYPE_INFO = Object::typeInfoFactory("Entity")

Protected Member Functions

int getDefaultKey ()
void invalidateKeyAsString ()
virtual string * generateKeyAsString () const

Static Protected Attributes

static const int COMPARE_KEY_TO_NULL_RVAL = -1

Private Attributes

int defaultKey
string * keyAsString

Static Private Attributes

static int nextDefaultKey = 0


Detailed Description

The base class of all items that can be stored in a Container.

Constructor & Destructor Documentation

container::Entity::Entity (  ) 

00054 : defaultKey(nextDefaultKey++), keyAsString(NULL) { }

Here is the caller graph for this function:

container::Entity::Entity ( int  key  ) 

Constructor for creating an Entity with a specific key.

Postcondition:
Does not reference or change nextDefaultKey
00056 : defaultKey(key), keyAsString(NULL) { }

container::Entity::Entity ( const Entity pattern  ) 

00058                                    : defaultKey(pattern.defaultKey) {
00059    if (pattern.keyAsString == NULL) {
00060       this->keyAsString = NULL;
00061    } else {
00062       this->keyAsString = new string(*(pattern.keyAsString));
00063    }
00064 }

container::Entity::~Entity (  )  [virtual]

00066                 {
00067    if (keyAsString != NULL) {
00068       delete keyAsString;
00069    }
00070 }


Member Function Documentation

Object * container::Entity::clone ( bool  deepCopy = false  )  const [virtual]

A polymorphic copy constructor.

Implements container::Object.

Reimplemented in container_test::Person.

00135                                          {
00136    return new Entity(*this);
00137 }

Here is the call graph for this function:

Here is the caller graph for this function:

int container::Entity::compareKeyTo ( const Entity second  )  const [virtual]

Compare this Entity with second.

Used to determine the sort order of a collection of Entity objects. Sub-classes should override compareKeyTo to provide their own concept of less-than, equal, and greater-than. This method is used by Container classes to sort Entity objects and to determine whether two instances are duplicates.

Returns:
An integer less than zero if: this < second

Zero if: this == second

An integer greater than zero if: this > second

Precondition:
second is the same type as this Entity
Postcondition:
Neither Entity has changed state

Reimplemented in container_test::Person.

00092                                                    {
00093    if (&second == NULL) {
00094       return COMPARE_KEY_TO_NULL_RVAL;
00095    }
00096    return defaultKey - second.defaultKey;
00097 }

Here is the caller graph for this function:

string * container::Entity::generateKeyAsString (  )  const [protected, virtual]

Reimplemented in container_test::Person.

00116                                           {
00117    return new string(util::toString(defaultKey));
00118 }

Here is the call graph for this function:

Here is the caller graph for this function:

int container::Entity::getDefaultKey (  )  [inline, protected]

00108                                  {
00109    return defaultKey;
00110 }

const string & container::Entity::getKeyAsString (  )  const

Return an Entity object's key in a string representation.

The key itself may be of a single type or a combination of member variables. For the sake of efficiency the string representation will be generated lazily and stored for future reference. getKeyAsString should not be overridden by sub-classes. This method calls the protected member generateKeyAsString to allow sub-classes of Entity to control the string representation.

00099                                            {
00100    if (keyAsString == NULL) {
00101       keyAsString = generateKeyAsString();
00102    }
00103    return *keyAsString;
00104 }

Here is the call graph for this function:

Here is the caller graph for this function:

void container::Entity::invalidateKeyAsString (  )  [protected]

00112                                    {
00113    keyAsString = NULL;
00114 }

Here is the caller graph for this function:

Entity & container::Entity::operator= ( const Entity second  ) 

00072                                               {
00073    if (this != &second) { // make sure not same object
00074       defaultKey = second.defaultKey;
00075       // delete allocated item(s)
00076       if (keyAsString != NULL) {
00077          delete keyAsString;
00078       }
00079 
00080       if (second.keyAsString == NULL) {
00081          keyAsString = NULL;
00082       } else {
00083          keyAsString = new string(*(second.keyAsString));
00084       }
00085    }
00086 
00087    return *this; // Return ref for multiple assignment
00088 }

ostream & container::Entity::renderState ( ostream &  os  )  const [virtual]

Write the state of an Object for debugging and demonstration.

This method must not change the state of an Object; adding or removing debug statements should not change the behavior of a class. The implementation must be robust, e.g., NULL safe, etc. and work without an unrecoverable error for any state, excluding an Object's time of construction and destruction. It is not required for the implementation to be thread safe.

Precondition:
The Object has been fully constructed and is not in the process of destruction
Postcondition:
The state of the Object is unchanged

Reimplemented from container::Object.

00122                                                {
00123    if (Entity::TYPE_INFO == this->typeInfo()) {
00124       return os << typeInfo()->typeName << " defaultKey(" << defaultKey << ") keyAsString(" +
00125             ((keyAsString == NULL) ? "NULL" : *(keyAsString)) << ")";
00126    } else {
00127       return os << typeInfo()->typeName << "(" << getKeyAsString() << ")";
00128    }
00129 }

Here is the call graph for this function:

const Object::Info * container::Entity::typeInfo (  )  const [virtual]

Return the instance of Object::Info that describes the class of this object.

Instantiation of Object::Info is controlled by the protected method Object::typeInfoFactory(const string&). Each sub-class of Object should create one and only one instance of Object::Info.

Reimplemented from container::Object.

Reimplemented in container_test::Person.

00131                                          {
00132    return TYPE_INFO;
00133 }

Here is the caller graph for this function:


Member Data Documentation

const int container::Entity::COMPARE_KEY_TO_NULL_RVAL = -1 [static, protected]

string* container::Entity::keyAsString [mutable, private]

int container::Entity::nextDefaultKey = 0 [static, private]

const Object::Info *const container::Entity::TYPE_INFO = Object::typeInfoFactory("Entity") [static]

Reimplemented from container::Object.

Reimplemented in container_test::Person.


The documentation for this class was generated from the following files:

Generated on Tue Jun 16 23:12:58 2009 by  doxygen 1.5.9