#include <identity.hh>
Classes | |
| class | Class |
Public Member Functions | |
| IdentifiableObject () | |
| virtual void | intoStringBuffer (misc::StringBuffer *sb) |
| Store a textual representation of the object in a misc::StringBuffer. | |
| int | getClassId () |
| Returns the class identifier. | |
| const char * | getClassName () |
| Return the name, under which the class of this object was registered. | |
| bool | instanceOf (int otherClassId) |
| Returns, whether this class is an instance of the class, given by otherClassId, or of a sub class of this class. | |
Protected Member Functions | |
| void | registerName (const char *className, int *classId) |
| This method must be called in the constructor for the sub class. See class comment for details. | |
Private Attributes | |
| int | classId |
Static Private Attributes | |
| static container::typed::HashTable < object::ConstString, Class > * | classesByName |
| static container::typed::Vector < Class > * | classesById |
| static Class * | currentlyConstructedClass |
Since e.g. dw::Textblock is a sub class of IdentifiableObject, and implemented in the correct way (as described below), for any given IdentifiableObject the following test can be done:
identity::IdentifiableObject *o; // ... bool isATextblock = o->instanceOf(dw::Textblock::CLASS_ID);
isATextblock is true, when o is an instance of dw::Textblock, or of a sub class of dw::Textblock. Otherwise, isATextblock is false.
It is also possible to get the class identifier of an identity::IdentifiableObject, e.g.
bool isOnlyATextblock = o->getClassId() == dw::Textblock::CLASS_ID;
would result in true, if o is an instance of dw::Textblock, but not an instance of a sub class of dw::Textblock.
Each direct or indirect sub class of IdentifiableObject must
After this, classCLASS_ID refers to a number, which denotes the class. (If this is still -1, since the class has not yet been instantiated, any test will fail, which is correct.)
If there are some classes like this:
and first, an instance of A, and then an instance of C is created, there will be the following calls of functions and constructors:
From this, the class hierarchy above can easily constructed, and stored in identity::IdentifiableObject::classesByName and in identity::IdentifiableObject::classesById. See the code for details.
N.b. Multiple inheritance is not supported, the construction of the tree would become confused.
| lout::identity::IdentifiableObject::IdentifiableObject | ( | ) |
References currentlyConstructedClass.
| int lout::identity::IdentifiableObject::getClassId | ( | ) | [inline] |
Returns the class identifier.
This is rarely used, rather, tests with identity::IdentifiableObject::instanceOf are done.
References classId.
| const char* lout::identity::IdentifiableObject::getClassName | ( | ) | [inline] |
Return the name, under which the class of this object was registered.
References classesById, classId, lout::identity::IdentifiableObject::Class::className, and lout::container::typed::Vector< T >::get().
Referenced by intoStringBuffer().
| bool lout::identity::IdentifiableObject::instanceOf | ( | int | otherClassId | ) |
Returns, whether this class is an instance of the class, given by otherClassId, or of a sub class of this class.
References classesById, classId, lout::container::typed::Vector< T >::get(), and lout::identity::IdentifiableObject::Class::parent.
Referenced by dw::Table::getCellRef().
| void lout::identity::IdentifiableObject::intoStringBuffer | ( | misc::StringBuffer * | sb | ) | [virtual] |
Store a textual representation of the object in a misc::StringBuffer.
This is used by object::Object::toString.
Reimplemented from lout::object::Object.
References lout::misc::StringBuffer::append(), and getClassName().
| void lout::identity::IdentifiableObject::registerName | ( | const char * | className, | |
| int * | classId | |||
| ) | [protected] |
This method must be called in the constructor for the sub class. See class comment for details.
References classesById, classesByName, currentlyConstructedClass, lout::container::typed::HashTable< K, V >::get(), lout::identity::IdentifiableObject::Class::id, lout::container::typed::Vector< T >::put(), lout::container::typed::HashTable< K, V >::put(), and lout::container::typed::Vector< T >::size().
Referenced by dw::AlignedTextblock::AlignedTextblock(), dw::core::ui::Embed::Embed(), dw::Image::Image(), dw::ListItem::ListItem(), dw::Table::Table(), dw::TableCell::TableCell(), dw::Textblock::Textblock(), and dw::core::Widget::Widget().
Vector< IdentifiableObject::Class > * lout::identity::IdentifiableObject::classesById [static, private] |
Initial value:
new Vector <IdentifiableObject::Class> (16, false)
Referenced by getClassName(), instanceOf(), and registerName().
HashTable< ConstString, IdentifiableObject::Class > * lout::identity::IdentifiableObject::classesByName [static, private] |
Initial value:
new HashTable<ConstString, IdentifiableObject::Class> (true, true)
Referenced by registerName().
int lout::identity::IdentifiableObject::classId [private] |
Referenced by getClassId(), getClassName(), and instanceOf().
IdentifiableObject::Class * lout::identity::IdentifiableObject::currentlyConstructedClass [static, private] |
Referenced by IdentifiableObject(), and registerName().
1.5.9