www.delorie.com/gnu/docs/xaos/xaos_23.html   search  
 
Buy GNU books!


An fast realtime interactive fractal zoomer

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3.1 Creating / destroing of instance

Functions getinstance and destroyinstance are equvivalents to constructor and desctructor in OOP. Getinstance is expected to create and fill following structure:

 
struct filter {
  struct filter *next,*previous;
  struct queue *queue;
  struct filteraction *action;
  struct image *image,*childimage;
  struct requirements req;
  struct fractal_context *fractalc;
  void *data;
  char *name;
  int flags;
  void (*wait_function) (struct filter *f);
  /*stuff for wait_function*/
  int pos,max,incalculation,readyforinterrupt,interrupt;
  char *pass;
};
Altrought this structure seems to be long and complex, most of fileds are unused at this time and rest of them are filled automatically by function:

Function: struct filter *createfilter (struct filteraction *fa);

That should be used to create instance. Only possibly interesting field is data. It's pointer reserved for filter's internal use. So it should be pointer to filter's internal variables if required. Following is example implementation of getinstance with allocating of such additional structure. In case nothing similiar is required you should use dirrectly createfilter at getinstance's place.

 
static struct filter *getinstance(struct filteraction *a)
{
      struct filter *f = createfilter(a);    /*create filter structure*/
      struct stereogramdata *i=calloc(sizeof(*i),1);
                                             /*allocate internal variables*/
      /*initialize your variables here*/
      f->data=i;                             /*add pointer to internal data*/
      return (f);
}

The destroyinstance is expected to free memory used by filter structure and all internal data of filter. To free filter structure use normal free(filter); So implementation of suchfunction should look like:
 
static void destroyinstance(struct filter *f)
{
     destroyinheredimage(f);
     free(f->data);
     free(f);
}
The meaning of destroyinheredimage will be described later.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003