Advertisement Jump to content


This topic is now archived and is closed to further replies.


Ugly callbacks and function pointers

This topic is 5895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
  // Lot's of private things

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

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

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

  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]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Hi there ..

so you have multiple Png classes running ? (strange)

if you like to use multiple "whatevers" in your class and you dont know how much "whatevers" there are at compiletime just use a linked list of your "whatevers" inside your class and create as much "whatevers" as needed so every "whatever" have its own set of functions ..

if you need those classes outside just use a (baseclass)pointer and get through the whole linked list.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!