#include <entity.h>
Public Member Functions | |
Entity () | |
Entity (int key) | |
Constructor for creating an Entity with a specific key. | |
Entity (const Entity &pattern) | |
virtual | ~Entity () |
Entity & | operator= (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 Info * | typeInfo () const |
Return the instance of Object::Info that describes the class of this object. | |
virtual Object * | clone (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 |
container::Entity::Entity | ( | ) |
00054 : defaultKey(nextDefaultKey++), keyAsString(NULL) { }
container::Entity::Entity | ( | int | key | ) |
Constructor for creating an Entity with a specific key.
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] |
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 }
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.
Zero if: this == second
An integer greater than zero if: this > second
Reimplemented in container_test::Person.
00092 { 00093 if (&second == NULL) { 00094 return COMPARE_KEY_TO_NULL_RVAL; 00095 } 00096 return defaultKey - second.defaultKey; 00097 }
string * container::Entity::generateKeyAsString | ( | ) | const [protected, virtual] |
Reimplemented in container_test::Person.
00116 { 00117 return new string(util::toString(defaultKey)); 00118 }
int container::Entity::getDefaultKey | ( | ) | [inline, protected] |
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 }
void container::Entity::invalidateKeyAsString | ( | ) | [protected] |
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.
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 }
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 }
const int container::Entity::COMPARE_KEY_TO_NULL_RVAL = -1 [static, protected] |
int container::Entity::defaultKey [private] |
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] |