I'm trying to add a bit more of a cheap RTTI for fltk through macros and
without add new fields to any widget only new methods, some static and some
virtual.
The idea is that any widget (first idea) will have 2 new methods one static
"static const char *className(void) {return #class_name;};" and one virtual
"virtual const char *classId(void) {return class_name::className();};", and
with the help of the macro shown bellow we don't need to write manually the new
classes.
With that we can check the class type at runtime with little overhead and no
increase in size (at least in respect to the dynamic allocated part) with a
code like this:
Fl_Widget *ptrWidget = someInheritedWidget;
if (ptrWidget->classId() == Fl_Input::className())
//we are dealing with a Fl_input class
else
//we shouldn't try cast ptrWidget to Fl_input
-------------
#define DECLARE_CLASS_CHEAP_RTTI_1(class_name)
DECLARE_CLASS_CHEAP_RTTI_00(class_name, /*nop*/, /*nop*/)
#define DECLARE_CLASS_CHEAP_RTTI_2(class_name, inheritage)
DECLARE_CLASS_CHEAP_RTTI_00(class_name, :, inheritage)
#define DECLARE_CLASS_CHEAP_RTTI_00(class_name, sep, inheritage) \
class FL_EXPORT class_name sep inheritage {\
public:\
static const char *className(void) {return #class_name;}; \
virtual const char *classId(void) {return class_name::className();};\
private:
To use this macro we shoulf instead of:
class FL_EXPORT Fl_Widget {
..
class FL_EXPORT Fl_Input : public Fl_Input_ {
..
use
DECLARE_CLASS_CHEAP_RTTI_1(Fl_Widget)
..
DECLARE_CLASS_CHEAP_RTTI_2(Fl_Input, public Fl_Input_)
..
Using a macro we can easily add more methods to all widgets in only one place
and recompile then.
Ideally we should also implement a way to see if the class belong/inherits from
some other class, but I don't know how to do it right now.
Obs: I'm suggesting this to try replicate the standard template library and
don't create dependency of it on fltk.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk