fifo.h

Go to the documentation of this file.
00001 
00007 #ifndef FIFO_H
00008 #define FIFO_H
00009 
00010 /* Get preprocessor macros this needs */
00011 #ifndef PP_H
00012 #include "pp.h"
00013 #endif
00014 
00031 #define FIFO_decl(type,count, label)\
00032     type    label[count+1];\
00033     type*   ppConcat(label,_add);\
00034     type*   ppConcat(label,_pop)
00035 
00038 #define FIFO_extern(type,count, label)\
00039     extern type     label[count+1];\
00040     extern type*    ppConcat(label,_add);\
00041     extern type*    ppConcat(label,_pop)
00042 
00047 #define FIFO_init(type, ilabel)         ( ppConcat(ilabel,_add) = ppConcat(ilabel,_pop) = ilabel )
00048 
00051 #define FIFO_auto(type,count, ilabel)\
00052     type    ilabel[count+1];\
00053     type*   ppConcat(ilabel,_add) = ilabel;\
00054     type*   ppConcat(ilabel,_pop) = ilabel
00055 
00058 #define FIFO_empty(type, ilabel)        ( ppConcat(ilabel,_add) == ppConcat(ilabel,_pop) )
00059 
00062 #define FIFO_next(type, ilabel, val)    ((val) == (ilabel) ? ((type*)((char*)ilabel+sizeof(ilabel))-1) : (val)-1)
00063 
00066 #define FIFO_full(type, ilabel)         ( FIFO_next(type, ilabel, ppConcat(ilabel,_add)) == ppConcat(ilabel,_pop) )
00067 
00073 #define FIFO_back(type, ilabel)         ( (ilabel)+ppConcat(ilabel,_add) )
00074 
00078 #define FIFO_front(type, ilabel)        ( (ilabel)+ppConcat(ilabel,_pop) )
00079 
00084 #define FIFO_add(type, ilabel)          ( ppConcat(ilabel,_add) = FIFO_next(type, ilabel, ppConcat(ilabel,_add)) )
00085 
00090 #define FIFO_pop(type, ilabel)          ( ppConcat(ilabel,_pop) = FIFO_next(type, ilabel, ppConcat(ilabel,_pop)) )
00091 
00099 #define FIFO_foreach(type, ilabel, iterator) \
00100     if( !FIFO_empty(type, ilabel) ) \
00101     for( iterator = FIFO_front(type, ilabel); iterator != FIFO_back(type, ilabel); iterator = FIFO_next(type, ilabel, iterator) )
00102 
00103 #endif /* FIFO_H */

Generated on Fri Jan 2 15:28:34 2009 for Squat by  doxygen 1.5.6