#include <person.h>
Public Member Functions | |
Person (string firstName, string lastName) | |
Person (const Person &orig) | |
virtual | ~Person () |
string | getFirstName () |
void | setFirstName (string name) |
string | getLastName () |
void | setLastName (string name) |
virtual int | compareKeyTo (const Entity &second) const |
Compare this Entity with second. | |
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("Person") |
Protected Member Functions | |
virtual string * | generateKeyAsString () const |
Private Member Functions | |
Person () | |
Private Attributes | |
string | firstName |
string | lastName |
Person is used to test SortedLinkedList and also provides an example of how to create a sub-class of Entity. The Person class' implementation of compareKeyTo results in an alphabetical sort order by last name, using the first name as a tie breaker.
container_test::Person::Person | ( | string | firstName, | |
string | lastName | |||
) |
container_test::Person::Person | ( | const Person & | orig | ) |
Object * container_test::Person::clone | ( | bool | deepCopy = false |
) | const [virtual] |
A polymorphic copy constructor.
Reimplemented from container::Entity.
00110 { 00111 // Alwasy does a deep copy. 00112 return new Person(*this); 00113 }
int container_test::Person::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 from container::Entity.
00079 { 00080 if (&second == NULL) { 00081 return COMPARE_KEY_TO_NULL_RVAL; 00082 } 00083 00084 int delta = typeInfo()->typeName.compare(second.typeInfo()->typeName); 00085 if (delta != 0) { 00086 return delta; 00087 } 00088 00089 const Person& p2 = (Person&)second; 00090 delta = lastName.compare(p2.lastName); 00091 if (delta != 0) { 00092 return delta; 00093 } 00094 00095 return firstName.compare(p2.firstName); 00096 }
string * container_test::Person::generateKeyAsString | ( | ) | const [protected, virtual] |
string container_test::Person::getFirstName | ( | ) |
string container_test::Person::getLastName | ( | ) |
void container_test::Person::setFirstName | ( | string | name | ) |
00063 { 00064 firstName = name; 00065 invalidateKeyAsString(); 00066 }
void container_test::Person::setLastName | ( | string | name | ) |
00072 { 00073 lastName = name; 00074 invalidateKeyAsString(); 00075 }
const Object::Info * container_test::Person::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::Entity.
00106 { 00107 return TYPE_INFO; 00108 }
string container_test::Person::firstName [private] |
string container_test::Person::lastName [private] |
const Object::Info *const container_test::Person::TYPE_INFO = Object::typeInfoFactory("Person") [static] |
Reimplemented from container::Entity.