Jump to content
  • Advertisement

Archived

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

Luctus

Ugly callbacks and function pointers

This topic is 5799 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
{
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]

Share this post


Link to post
Share on other sites
Advertisement
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.

regards

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!