Hello, Some time ago I wrote for fltk-2.0 a feature called Widget Associations. It was merged into fltk-2.0. I have finally ported this to fltk-1.3. And would be interested to get it merged into fltk.
What exactly is this? This feature makes it possible for the fltk-user to add any additional data to each widget. Without the need to change the base class. And without multiple inheritance. How does it work? The data is not actual part of the widget but resides in a table together with a pointer to the widget that it is attached to and also with a pointer that identifies the type of the data. This pointer is actually a pointer to an instance of a special class. This class on one side serves as the unique identifier and on the other side also has a function that is used to free the associated data. This way it is possible to assign allocated data and free it on the destruction of the widget. If someone now wants to get data of a certain type associated with a certain widget, all that needs to be done is look through that table and find an instance. Advantage: - Flexibility: it is not necessary to change the base class or to do multiple inheritance to add a new data field - Sparse memory: if only very few widgets actually use the new data field the new table doesn't waste memory - The base class stays small Disadvantage: - If nearly all widgets use the association is requires more memory - Assigning and lookup is slower I have prepared the code. It probably doesn't (yet) meet the programming conventions. But it works. I also included a little example. I removed the tooltip_ pointer from the widget baseclass and replaced it by an association. How can we go on with this? Is there any interest to get this into fltk? If so where can I upload the code for review? Andreas _______________________________________________ fltk-dev mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk-dev
