Skip to main content
gamedev.net
🔒 Locked

Ugly callbacks and function pointers

Started by Luctus 1 reply 200+ views
Original Post
Luctus
Luctus
This is a pure design issue, I have this thing that my code should _look_ nice and don't just work nice (which it does as it is but..) First I have a base-class with two virtual callback functions which is called whenever the class needs bytes from file(or whatever the data comes from) and when the buffer is full and it needs to output data..
    
class Deflate
{
private:
  // Lot's of private things

protected:
  virtual void Get( void *data, long size ) = 0;
  virtual void Put( void *data, long size ) = 0;
public:
  // Some public stuff

}
  
Then I have the class that actually needs to decompress data as a sub-class..
  
class Png : public Deflate
{
private:
  typedef void (cPngImage::*ZFunc)( void *, long );
  ZFunc			_GetFunction;
  ZFunc			_PutFunction;

  void Get( void *data, long size );
  void Put( void *data, long size );

public:
  bool Load( char *filename );
  void Free( void );
}

    
however, since there is multiple deflate datastreams in a png file and I must treat those different I use function pointers to choose between different Get and Put functions..but it doesn't _look_ very nice to have those function pointers =p, is it any faster/cleaner way to do it?
/* Everything IMHO */ -Luctus [edited by - Luctus on December 5, 2002 8:26:45 AM]
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.