[SDL] Re: C++ wrapper of SDL ???

Bruno Martínez br1 at internet.com.uy
Sat Nov 19 18:03:30 PST 2005


On Sat, 19 Nov 2005 23:48:33 -0200, Asmodehn Shade <asmodehn at gmail.com>  
wrote:

> Hi everyone...
>
> I plan to write some libs on top of SDL, and I was wondering if some
> of you guys are aware of up-to-date and living SDL C++ wrapper ?
>
> I am thinking of a basic wrapper, doing nothing more than SDL
> functions, but still implementing most of the documented requirements
> (call this function before this one, this flag is not used in this
> function, etc.)
>
> I had a look around, googled, etc. but I cant find anything (SDLmm
> looks nice, but looks like it has been inactive for a long time
> now...)
> It looks like everyone is writing his own with its own goals, so I
> started doing the same :-(
>
> Is there any "common" effort somewhere to develop a C++ wrapper ? or
> is this useless ?

I find that a wrapper is not necesary.  The most anoying thing from a  
C++ perspective is remembering to clean up after your surfaces.  With  
Boost's intrusive_ptr or shared_ptr this can be solved:

#include <SDL.h>
#include <boost/intrusive_ptr.hpp>

// We tell intrusive_ptr how to deal with SDL_Surface*
void intrusive_ptr_add_ref(SDL_Surface* p)
{
     p->refcount++;
}

void intrusive_ptr_release(SDL_Surface* p)
{
     SDL_FreeSurface(p);
}


void foo()
{
     // We pass false to the constructor because refcount==1 already.
     boost::intrusive_ptr<SDL_Surface> sfc(IMG_Load(file), false);
     ...
}

HTH,
Bruno





More information about the SDL mailing list