serial.temp.h

00001 
00008 #ifndef ctl_declarations
00009 #error The 'ctl_declarations' template parameter was not defined.  It should be a string to pass to #include.
00010 #endif
00011 
00012 /*
00013  * Clean up the namespace from dg_patterns.h
00014  */
00015 #define UNDEF_ALL
00016 #include "ctl/dg/blank.h"
00017 
00018 
00019 #ifndef NO_RECORD_SERIAL
00020 
00021 /****************************************************************************
00022  * \ingroup Patterns
00023  * Measure Serial Data
00024  *
00025  * Generate code to determine *precisely* how many bytes a serialized record
00026  * will need.
00027  *
00028  ****************************************************************************/
00029 
00030 /*
00031  * Make protocol wrapper
00032  */
00033 #define protocol_begin( label )
00034 
00035 /*
00036  * Make enumeration
00037  */
00038 #define enum_begin( label )                         size_t ppConcat(label,_serial_size)( const label* self ) { return int16_serial_size(self); }
00039 #define enum_item( label )
00040 #define enum_end( label )
00041 
00042 /*
00043  * Make record serial_size 
00044  * 
00045  * Note the odd syntax for adding this up makes it clear to even the dumbest 
00046  * compilers that we're adding a bunch of constants, so simple records with 
00047  * all scalar contents will generally boil down to sticking a size_t on the
00048  * stack or in a register and returning.
00049  */
00050 #define record_begin(label)                         size_t ppConcat(label,_serial_size)( const label* self ) \
00051                                                     {\
00052                                                         size_t result;\
00053                                                         assertobjconst(self); /* Assert: valid inputs */\
00054                                                         result = 0
00055 #define record_var(label,type,val)                      + ppConcat(type,_serial_size)(&self->label)
00056 #define record_varok(label,type,val,min,max)            + ppConcat(type,_serial_size)(&self->label)
00057 #define record_array(label,type,alen,val)               + ppConcat(type,_serial_sizearray)(self->label,alen)
00058 #define record_arrayok(label,type,alen,val,min,max)     + ppConcat(type,_serial_sizearray)(self->label,alen)
00059 #define record_objarray(label,type,alen)                ; {\
00060                                                             array_foreach_const(type,self->label, curr ) \
00061                                                                 result += ppConcat(type,_serial_size)( curr ); \
00062                                                         }\
00063                                                         result += ctl_serial_size_size( alen )
00064 #define record_achar(label,type,alen,val)               + ppConcat(type,_serial_size_string)(self->label,alen)
00065 #define record_string(label,type)                       + ppConcat(type,_serial_size_gstring)( &self->label )
00066 #define record_obj(label,type)                          + ctl_serial_size_size_size( ppConcat(type,_serial_size)( &self->label ) )
00067 #define record_ref(label,type)                          + ctl_serial_size_size_size( self->label ? ppConcat(type,_serial_size)( self->label ) : 0 )
00068 #define record_preref(label,type)                       record_ref(label,type)
00069 #define record_enum(label,enum,val)                     + ppConcat(enum,_serial_size)( &self->label )
00070 #define record_serial(label)                            + ctl_serial_calc_size( &self->label )
00071 #define record_serialref(label)                         record_serial(label);
00072 #define record_member(stuff)
00073 #define record_atinit(stuff)
00074 #define record_atdestroy(stuff)
00075 #define record_atcopy(stuff)
00076 #define record_atmove(stuff)
00077 #define record_atswap(stuff)
00078 #define record_end(label)                               ; return result;\
00079                                                     }
00080 #define record_alias(label,type)
00081 
00082 #define union_begin(label,etype)            size_t ppConcat(label,_serial_size)( const label* self ) \
00083                                             {\
00084                                                 size_t result;\
00085                                                 assertobjconst(self); /* Assert: valid inputs */\
00086                                                 result = ppConcat(etype,_serial_size)( &self->type );\
00087                                                 switch(self->type)\
00088                                                 {
00089 #define     union_alias(type,enum)              case enum:
00090 #define     union_member(label,type,enum)       case enum:\
00091                                                     result += ppConcat(type,_serial_size)( &self->obj.label );\
00092                                                     result += ctl_serial_size_size(0);\
00093                                                     break;
00094 #define union_end(label,etype)                  default:\
00095                                                     throwassert(ppTokStr(ppConcat(label,_serial_size)) ":Unknown type");\
00096                                                     break;\
00097                                                 }\
00098                                                 return result;\
00099                                             }
00100 
00101 #define container_array(label,type,size)
00102 #define container_vector(label,type)
00103 #define container_list( label, type )
00104 #define container_map( label, keytype, type )
00105 #define container_multimap( label, keytype, type )
00106 #define container_set( label, type )
00107 #define container_multiset( label, type )
00108 
00109 #define protocol_end( label )
00110 
00111 /* Run definitions through translation */
00112 #include ctl_declarations
00113 
00114 /*
00115  * Clean up the namespace 
00116  */
00117 #define UNDEF_ALL
00118 #include "ctl/dg/blank.h"
00119 
00120 
00121 /****************************************************************************
00122  * \ingroup Patterns
00123  * Serial Writer
00124  *
00125  * Generate code to serialize a record
00126  *
00127  * 'Stingy' data is meant for serial packets where bandwidth  is at a  
00128  * premium and records will not be saved for long term retrieval, such as 
00129  * over a network connection.
00130  *
00131  ****************************************************************************/
00132 
00133 /*
00134  * Make protocol wrapper
00135  */
00136 #define protocol_begin( label )
00137 
00138 /*
00139  * Make enumeration
00140  */
00141 #define enum_begin( label )                         void ppConcat(label,_serial_write)( const label* self, ctl_serial* serial ) \
00142                                                     { \
00143                                                         assertobjconst(self);\
00144                                                         assertobjptr(serial);\
00145                                                         {\
00146                                                             int16 tmp = (uint16)*self;\
00147                                                             int16_serial_write( &tmp, serial );\
00148                                                         }\
00149                                                     }
00150 #define enum_item( label )
00151 #define enum_end( label )
00152 
00153 /*
00154  * Make record
00155  */
00156 #define record_begin(label)                         void ppConcat(label,_serial_write)( const label* self, ctl_serial* serial ) \
00157                                                     {\
00158                                                         assertobjconst(self);\
00159                                                         assertobjptr(serial);
00160 #define record_var(label,type,val)                      ppConcat(type,_serial_write)( &self->label, serial );
00161 #define record_varok(label,type,val,min,max)            ppConcat(type,_serial_write)( &self->label, serial );
00162 #define record_array(label,type,alen,val)               ppConcat(type,_serial_writearray)( self->label, alen, serial );
00163 #define record_arrayok(label,type,alen,val,min,max)     ppConcat(type,_serial_writearray)( self->label, alen, serial );
00164 #define record_objarray(label,type,alen)                { \
00165                                                             ctl_serial_writesize( alen, serial ); \
00166                                                             {\
00167                                                                 array_foreach_const( type, self->label, curr )\
00168                                                                     ppConcat(type,_serial_write)(curr,serial);\
00169                                                             }\
00170                                                         }
00171 #define record_achar(label,type,alen,val)               ppConcat(type,_serial_write_string)( self->label, alen, serial );
00172 #define record_string(label,type)                       ppConcat(type,_serial_write_string)( self->label.begin, ctl_gstring_size(type,&self->label), serial );
00173 #define record_obj(label,type)                          { \
00174                                                             ctl_serial_writesize( ppConcat(type,_serial_size)(&self->label), serial ); \
00175                                                             ppConcat(type,_serial_write)( &self->label, serial ); \
00176                                                         }
00177 #define record_ref(label,type)                          if( self->label ) \
00178                                                         {\
00179                                                             ctl_serial_writesize( ppConcat(type,_serial_size)(self->label), serial );\
00180                                                             ppConcat(type,_serial_write)( self->label, serial );\
00181                                                         }\
00182                                                         else\
00183                                                         {\
00184                                                             ctl_serial_writesize( 0, serial );\
00185                                                         }
00186 #define record_preref(label,type)                       record_ref(label,type)
00187 #define record_enum(label,enum,val)                     ppConcat(enum,_serial_write)( &self->label, serial );
00188 #define record_serial(label)                            ctl_serial_write_serial( serial, &self->label );
00189 #define record_serialref(label)                         record_serial(label)
00190 #define record_member(stuff)                            
00191 #define record_atinit(stuff)
00192 #define record_atdestroy(stuff)
00193 #define record_atcopy(stuff)
00194 #define record_atmove(stuff)
00195 #define record_atswap(stuff)
00196 #define record_end(label)                           }
00197 
00198 #define record_alias(label,type)
00199 
00200 #define union_begin(label,etype)            void ppConcat(label,_serial_write)( const label* self, ctl_serial* serial ) \
00201                                             {\
00202                                                 assertobjconst(self);\
00203                                                 assertobjptr(serial);\
00204                                                 ppConcat(etype,_serial_write)( &self->type, serial );\
00205                                                 switch( self->type )\
00206                                                 {
00207 #define     union_alias(type,enum)              case enum:
00208 #define     union_member(label,type,enum)       case enum:\
00209                                                     ctl_serial_writesize( ppConcat(type,_serial_size)(&self->obj.label), serial ); \
00210                                                     ppConcat(type,_serial_write)( &self->obj.label, serial );\
00211                                                     break;
00212 #define union_end(label,etype)                  default:\
00213                                                     throwassert(ppTokStr(ppConcat(label,_serial_write)) ":Unknown type");\
00214                                                     break;\
00215                                                 }\
00216                                             }
00217 
00218 #define container_array(label,type,size)
00219 #define container_vector(label,type)
00220 #define container_list( label, type )
00221 #define container_map( label, keytype, type )
00222 #define container_multimap( label, keytype, type )
00223 #define container_set( label, type )
00224 #define container_multiset( label, type )
00225 
00226 #define protocol_end( label )
00227 
00228 /* Run definitions through translation */
00229 #include ctl_declarations
00230 
00231 /*
00232  * Clean up the namespace 
00233  */
00234 #define UNDEF_ALL
00235 #include "ctl/dg/blank.h"
00236 
00237 /****************************************************************************
00238  * \ingroup Patterns
00239  * Serial Reader
00240  *
00241  * Generate code to read a record from serial data
00242  *
00243  ****************************************************************************/
00244 
00245 /*
00246  * Make protocol wrapper
00247  */
00248 #define protocol_begin( label )
00249 
00250 /*
00251  * Make enumeration
00252  */
00253 #define enum_begin( label )                         void ppConcat(label,_serial_read)( label* self, ctl_serial* serial )\
00254                                                     { \
00255                                                         int16 tmp;\
00256                                                         int16_serial_read( &tmp, serial );\
00257                                                         *self = (label)tmp;\
00258                                                     }
00259 #define enum_item( label )
00260 #define enum_end( label )
00261 
00262 /*
00263  * Make record
00264  */
00265 #define record_begin(label)                         void ppConcat(label,_serial_read)( label* self, ctl_serial* serial ) \
00266                                                     {\
00267                                                         assertobjptr(self);\
00268                                                         assertobjptr(serial);
00269 #define record_var(label,type,val)                      ppConcat(type,_serial_read)( &self->label, serial );
00270 #define record_varok(label,type,val,min,max)            ppConcat(type,_serial_read)( &self->label, serial );
00271 #define record_array(label,type,alen,val)               ppConcat(type,_serial_readarray)( self->label, alen, serial );
00272 #define record_arrayok(label,type,alen,val,min,max)     ppConcat(type,_serial_readarray)( self->label, alen, serial );
00273 #define record_objarray(label,type,alen)                { \
00274                                                             size_t readsize = ctl_serial_readsize( serial ); \
00275                                                             if( readsize == (alen) )\
00276                                                             {\
00277                                                                 array_foreach( type, self->label, curr )\
00278                                                                     ppConcat(type,_serial_read)(curr,serial);\
00279                                                             }\
00280                                                             else\
00281                                                             {\
00282                                                                 ctl_serial_except( serial, "Record array: size mismatch" );\
00283                                                             }\
00284                                                         }
00285 #define record_achar(label,type,alen,val)               ppConcat(type,_serial_read_string)( self->label, alen, serial );
00286 #define record_string(label,type)                       ppConcat(type,_serial_read_gstring)( &self->label, serial );
00287 #define record_obj(label,type)                          { \
00288                                                             size_t ssize = ctl_serial_readsize( serial ); \
00289                                                             ctl_serial tmp = *serial;\
00290                                                             tmp.end = tmp.curr + ssize;\
00291                                                             ppConcat(type,_serial_read)(&self->label, &tmp ); \
00292                                                             serial->curr = tmp.curr;\
00293                                                         }
00294 #define record_ref(label,type)                          { \
00295                                                             size_t ssize = ctl_serial_readsize( serial );\
00296                                                             if( ssize )\
00297                                                             {\
00298                                                                 ctl_delete(self->label);\
00299                                                                 ctl_new(self->label,type);\
00300                                                                 {\
00301                                                                     ctl_serial tmp = *serial;\
00302                                                                     tmp.end = tmp.curr + ssize;\
00303                                                                     ppConcat(type,_serial_read)(self->label,&tmp);\
00304                                                                     serial->curr = tmp.curr;\
00305                                                                 }\
00306                                                             }\
00307                                                         }
00308 #define record_preref(label,type)                       record_ref(label,type)
00309 #define record_enum(label,enum,val)                     ppConcat(enum,_serial_read)( &self->label, serial );
00310 #define record_serial(label)                            ctl_serial_read_serial( &self->label, serial ); ctl_serial_deref(&self->label);
00311 #define record_serialref(label)                         ctl_serial_read_serial( &self->label, serial ); 
00312 
00313 #define record_member(stuff)
00314 #define record_atinit(stuff)
00315 #define record_atdestroy(stuff)
00316 #define record_atcopy(stuff)
00317 #define record_atmove(stuff)
00318 #define record_atswap(stuff)
00319 #define record_end(label)                           }
00320 
00321 #define record_alias(label,type)
00322 
00323 #define union_begin(label,etype)            void ppConcat(label,_serial_read)( label* self, ctl_serial* serial ) \
00324                                             {\
00325                                                 assertobjptr(self);\
00326                                                 assertobjptr(serial);\
00327                                                 ppConcat(etype,_serial_read)( &self->type, serial );\
00328                                                 switch( self->type )\
00329                                                 {
00330 #define     union_alias(type,enum)              case enum:
00331 #define     union_member(label,type,enum)       case enum:\
00332                                                     {\
00333                                                         ctl_serial tmp = *serial;\
00334                                                         ctl_serial_read_serial( &tmp, serial );\
00335                                                         ppConcat(type,_serial_read)(&self->obj.label, &tmp ); \
00336                                                     }\
00337                                                     break;
00338 #define union_end(label,etype)                  default:\
00339                                                     throwassert(ppTokStr(ppConcat(label,_serial_read)) ":Unknown type");\
00340                                                     break;\
00341                                                 }\
00342                                             }
00343 
00344 #define container_array(label,type,size)
00345 #define container_vector(label,type)
00346 #define container_list( label, type )
00347 #define container_map( label, keytype, type )
00348 #define container_multimap( label, keytype, type )
00349 #define container_set( label, type )
00350 #define container_multiset( label, type )
00351 
00352 #define protocol_end( label )
00353 
00354 /* Run definitions through translation */
00355 #include ctl_declarations
00356 
00357 /*
00358  * Clean up the namespace 
00359  */
00360 #define UNDEF_ALL
00361 #include "ctl/dg/blank.h"
00362 
00363 #endif /* NO_RECORD_SERIAL */

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