bag.temp.h
00001
00002
00003
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
00016 #error bag_count, the maximum capacity of a bag must be defined to manufacture this template.
00017 #endif
00018
00019
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);
00027
00028
00029 #define Bag_begin( self ) ((self)->m_array)
00030
00031
00032 #define Bag_end( self ) ((self)->m_array + (self)->m_count)
00033
00034
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
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 );