Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

killer.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006    
00007 #ifndef _MCW_KILLER_H_
00008 #define _MCW_KILLER_H_
00009 
00010 /******
00011    Header file to manipulate "kill lists":
00012     A way to maintain a list of data that should be deleted when necessary.
00013     The pointers should be from XtMalloc, not malloc.
00014 *******/
00015 
00016 /** to get mcw_malloc stuff **/
00017 
00018 #include "mcw_malloc.h"
00019 
00020 /** structure to hold kill list **/
00021 
00022 typedef struct {
00023    int     num , nalloc ;
00024    char ** kill ;
00025 } KILL_list ;
00026 
00027 #define KILL_INC 32
00028 
00029 /** initialize a new kill list **/
00030 
00031 #define INIT_KILL(kl) ((kl).num=0, (kl).nalloc=0, (kl).kill=NULL)
00032 
00033 /** add a pointer to be killed **/
00034 
00035 #define ADDTO_KILL(kl,p)                                           \
00036  {  if( (kl).num == (kl).nalloc ){                                 \
00037        (kl).nalloc += KILL_INC ;                                   \
00038        (kl).kill    = (char **) XtRealloc( (char *) (kl).kill ,    \
00039                                   sizeof(char *) * (kl).nalloc ) ; \
00040     }                                                              \
00041     (kl).kill[(kl).num++] = (char *) p ;                           \
00042  }
00043 
00044 /** kill the data in a single pointer in the kill list,
00045     but keep the rest of the data in the list intact   **/
00046 
00047 #define SINGLE_KILL(kl,p)                                   \
00048    {  char * cp = (char *) (p) ;                            \
00049       int qwer ;                                            \
00050       for( qwer=0 ; qwer < (kl).num ; qwer++ )              \
00051          if( cp == (kl).kill[qwer] ){                       \
00052             myXtFree(cp) ; (kl).kill[qwer] = NULL ; break ; \
00053          }                                                  \
00054    }
00055 
00056 /** remove a pointer from the kill list, without deleting its data **/
00057 
00058 #define REMOVEFROM_KILL(kl,p)                  \
00059    {  char * cp = (char *) (p) ;               \
00060       int qwer ;                               \
00061       for( qwer=0 ; qwer < (kl).num ; qwer++ ) \
00062          if( cp == (kl).kill[qwer] ){          \
00063             (kl).kill[qwer] = NULL ; break ;   \
00064          }                                     \
00065    }
00066 
00067 /** replace a pointer in the kill list (perhaps it was XtRealloc-ed).
00068     If it doesn't exist, add it to the kill list.                     **/
00069 
00070 #define REPLACE_KILL(kl,pold,pnew)                   \
00071    {  char * cpold = (char *) (pold) ;               \
00072       char * cpnew = (char *) (pnew) ;               \
00073       int qwer ;                                     \
00074       for( qwer=0 ; qwer < (kl).num ; qwer++ )       \
00075          if( cpold == (kl).kill[qwer] ){             \
00076             (kl).kill[qwer] = cpnew ; break ;        \
00077          }                                           \
00078       if( qwer == (kl).num ) ADDTO_KILL((kl),pnew) ; \
00079    }
00080 
00081 /** kill all the data in the kill list! **/
00082 
00083 #define KILL_KILL(kl) {                                                    \
00084       int qwer ;                                                           \
00085       for( qwer=0 ; qwer < (kl).num ; qwer++ ) myXtFree((kl).kill[qwer]) ; \
00086       myXtFree( (kl).kill) ;                                               \
00087       INIT_KILL(kl) ;                                                      \
00088    }
00089 
00090 #endif /* _MCW_KILLER_H_ */
 

Powered by Plone

This site conforms to the following standards: