bag.temp.c

00001 /*
00002  * Bag.temp.c
00003  * C template example
00004  */
00005 
00006 #ifndef bag_T
00007 #error bag_T, the type of Bag we're manufacturing, must be defined to manufacture this template.
00008 #endif
00009 
00010 #ifndef bag_count
00011 /* #define bag_count 100 - You could make defaults. */
00012 #error bag_count, the maximum capacity of a bag must be defined to manufacture this template.
00013 #endif
00014 
00015 /* Construct bag */
00016 void ppCat(bag_label,_init)( bag_label* self )
00017 {
00018     self->m_count = 0;
00019     memset( self->m_array, 0, sizeof( self->m_array ) );
00020 }
00021 
00022 /* Destroy bag */
00023 void ppCat(bag_label,_destroy)( bag_label* self )
00024 {
00025     m_count = 0;
00026 }
00027 
00028 /* Add an item */
00029 void ppCat(bag_label,_add)( bag_label* self, bag_T* item )
00030 {
00031     if( self->m_count < bag_count )
00032     {
00033          self->m_array[self->m_count++] = item;
00034     }
00035     else
00036     {
00037         /* Some sort of 'full' handler */
00038     }
00039 }
00040 
00041 /* Remove an item */
00042 void ppCat(bag_label,_remove)( bag_label* self, bag_T* item )
00043 {
00044     bag_T** search = begin();
00045     bag_T** last = search + m_count;
00046     while( search < last )
00047     {
00048         if( *search == thisOne )
00049         {
00050             *search = --*last;
00051             *last = NULL;
00052             --m_count;
00053             /* Search through whole bag for duplicates */
00054         }
00055     }
00056 }

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