Re: [AD] object oriented AL_SYSTEM

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Sat, 2006-08-26 at 19:43 -0600, Thomas Fjellstrom wrote:
> On Saturday 26 August 2006 4:12 am, Elias Pschernig wrote:
> > How would a base structure like below look?
> >
> > struct AL_SYSTEM_DRIVER
> > {
> >    ...variables + methods
> > };
> >
> > struct AL_SYSTEM
> > {
> >    AL_SYSTEM_DRIVER *driver;
> >    ... variables
> > };
> >
> > ... for each driver XXX
> > struct AL_SYSTEM_XXX
> > {
> >    AL_SYSTEM *system;
> >    ... variables
> > }
> >
...
> >
> 
> I think it should go something like:
> 
> struct AL_SYSTEM {
> 	...
> };
> 
> struct AL_SYSTEM_FOO {
> 	AL_SYSTEM base;
> }
> 
> AL_SYSTEM_FOO can now be cast as a AL_SYSTEM just fine, and AL_SYSTEM_FOO can 
> add anything it wants.

Yes, that's just what I meant :) So internal functions could just cast
the object to what they expect (and also ASSERT on the right ->driver),
something like:

_al_x11_line(AL_DISPLAY *display...)
{
   AL_ASSERT(display->driver == _al_display_x11_driver());
   AL_DISPLAY_X11 *x11 = (AL_DISPLAY_X11 *)display;

   _al_lock_mutex(x11->xmutex);
   XLine(x11->xdisplay, x11->xwindow, ...);
   _al_unlock_mutex(x11->xmutex);
}

All without the need of accessing a void * pointer (like is currently
done e.g. with BITMAP and FONT, possible others), and _xwin (which
already is a similar idea) would be a proper object instead of just
grouped global variables.

-- 
Elias Pschernig





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/