Dillo v3.1.1-120-g540bad94
|
Instances of classes, which are sub classes of this class, may be identified at run-time. More...
#include <identity.hh>
Classes | |
class | Class |
Public Member Functions | |
IdentifiableObject () | |
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. | |
Public Member Functions inherited from lout::object::Object | |
virtual | ~Object () |
The destructor is defined as virtual (but not abstract), so that destruction of Object's works properly. | |
virtual bool | equals (Object *other) |
Returns, whether two objects are equal. | |
virtual int | hashValue () |
Return a hash value for the object. | |
virtual Object * | clone () |
Return an exact copy of the object. | |
const char * | toString () |
Use object::Object::intoStringBuffer to return a textual representation of the object. | |
virtual size_t | sizeOf () |
Return the number of bytes, this object totally uses. | |
Protected Member Functions | |
void | registerName (const char *className, int *classId) |
This method must be called in the constructor for the sub class. | |
Private Attributes | |
int | classId |
Static Private Attributes | |
static container::typed::HashTable< object::ConstString, Class > * | classesByName |
static container::typed::Vector< Class > * | classesById |
static Class * | currentlyConstructedClass |
Instances of classes, which are sub classes of this class, may be identified at run-time.
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:
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.
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, class::CLASS_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.
Definition at line 98 of file identity.hh.
lout::identity::IdentifiableObject::IdentifiableObject | ( | ) |
Definition at line 65 of file identity.cc.
References currentlyConstructedClass.
|
inline |
Returns the class identifier.
This is rarely used, rather, tests with identity::IdentifiableObject::instanceOf are done.
Definition at line 134 of file identity.hh.
References classId.
|
inline |
Return the name, under which the class of this object was registered.
Definition at line 140 of file identity.hh.
References classesById, and classId.
Referenced by dw::core::Widget::correctReqAspectRatio(), dw::oof::OOFAwareWidget::getWidgetAtPointLevel(), dw::core::Content::intoStringBuffer(), dw::core::Iterator::intoStringBuffer(), and 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.
Definition at line 105 of file identity.cc.
References classesById, and classId.
Referenced by dw::Textblock::addWidget(), dw::oof::OOFPosRelMgr::calcWidgetRefSize(), dw::Table::getCellRef(), dw::Textblock::getGeneratorWidth(), dw::Textblock::handOverBreak(), and dw::oof::OOFAwareWidget::isOOFContainer().
|
virtual |
Store a textual representation of the object in a misc::StringBuffer.
This is used by object::Object::toString.
Reimplemented from lout::object::Object.
Definition at line 70 of file identity.cc.
References lout::misc::StringBuffer::append(), lout::misc::StringBuffer::appendPointer(), and getClassName().
Referenced by dw::Textblock::TextblockIterator::highlight(), dw::oof::OOFAwareWidget::OOFAwareWidgetIterator::next(), dw::oof::OOFAwareWidget::OOFAwareWidgetIterator::prev(), and dw::Textblock::TextblockIterator::unhighlight().
|
protected |
This method must be called in the constructor for the sub class.
See class comment for details.
Definition at line 83 of file identity.cc.
References classesById, classesByName, classId, currentlyConstructedClass, and lout::identity::IdentifiableObject::Class::id.
Referenced by dw::AlignedTableCell::AlignedTableCell(), dw::AlignedTextblock::AlignedTextblock(), dw::core::ui::Embed::Embed(), dw::ListItem::ListItem(), dw::oof::OOFAwareWidget::OOFAwareWidget(), dw::RegardingBorder::RegardingBorder(), dw::Ruler::Ruler(), dw::SimpleContainer::SimpleContainer(), dw::SimpleTableCell::SimpleTableCell(), dw::Table::Table(), dw::Textblock::Textblock(), and dw::core::Widget::Widget().
|
staticprivate |
Definition at line 115 of file identity.hh.
Referenced by getClassName(), instanceOf(), and registerName().
|
staticprivate |
Definition at line 114 of file identity.hh.
Referenced by registerName().
|
private |
Definition at line 118 of file identity.hh.
Referenced by getClassId(), getClassName(), instanceOf(), and registerName().
|
staticprivate |
Definition at line 116 of file identity.hh.
Referenced by IdentifiableObject(), and registerName().