bag.temp.h

00001 /*
00002  * Bag.temp.h
00003  * C template example
00004  */
00005 
00006 #ifndef bag_label
00007 #error bag_label, the name we're giving this template type, must be defined to manufacture this template.
00008 #endif
00009 
00010 #ifndef bag_T
00011 #error bag_T, the type of Bag we're manufacturing, must be defined to manufacture this template.
00012 #endif
00013 
00014 #ifndef bag_count
00015 /* #define bag_count 100 - You can make defaults. */
00016 #error bag_count, the maximum capacity of a bag must be defined to manufacture this template.
00017 #endif
00018 
00019 /* Declare a simple container template and some accessories for it. */
00020 typedef struct bag_label
00021 {
00022     bag_T*  m_array[bag_count];
00023     size_t  m_count;
00024 } bag_label;
00025 
00026 typedef bag_T ppCat(bag_label,_type); /* Make bag type accessible */
00027 
00028 /* Get first bag item */
00029 #define Bag_begin( self )   ((self)->m_array)
00030 
00031 /* Get last bag item+1 (note: self is evaluated twice!) */
00032 #define Bag_end( self )     ((self)->m_array + (self)->m_count)
00033 
00034 /* Iterate bag members */
00035 #define Bag_foreach( bag_label, self, iterator ) \
00036 ppCat(bag_label,_type)** ppCat(iterator,_curr) = Bag_begin( self );\
00037 const ppCat(bag_label,_type)* const * ppCat(iterator,_last) = Bag_end( self );\
00038 ppCat(bag_label,_type)* iterator = *ppCat(iterator,_curr);\
00039     for( ; ppCat(iterator,_curr) < (ppCat(bag_label,_type)**)ppCat(iterator,_last); iterator = *++ppCat(iterator,_curr) )
00040 
00041 /* Forward declare bag functions */
00042 void ppCat(bag_label,_init)( bag_label* self );
00043 void ppCat(bag_label,_destroy)( bag_label* self );
00044 void ppCat(bag_label,_add)( bag_label* self, bag_T* item );
00045 void ppCat(bag_label,_remove)( bag_label* self, bag_T* item );

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