00001
00007 #ifndef ctl_declarations
00008 #error The 'ctl_declarations' template parameter was not defined. It should be a string to pass to #include.
00009 #endif
00010
00011
00012
00013
00014 #define UNDEF_ALL
00015 #include "ctl/dg/blank.h"
00016
00017 #ifndef NO_RECORD_RECORD
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #define protocol_begin( label )
00032
00033
00034
00035
00036 #define enum_begin( label ) size_t ppConcat(label,_record_size)( const label* self, const char* szlabel ) \
00037 { \
00038 assertobjconst(self);\
00039 assertconst(szlabel,1);\
00040 return ctl_record_head_size(szlabel,szconst(char,#label)) + cstrlen(char)(enum_itemname(label,*self))+1;\
00041 }
00042 #define enum_item( label )
00043 #define enum_end( label )
00044
00045
00046
00047
00048 #define record_begin(label) size_t ppConcat(label,_record_size)( const label* self, const char* szlabel ) \
00049 {\
00050 size_t result;\
00051 assertobjconst(self);\
00052 assertconst(szlabel,1);\
00053 result = ctl_record_head_size(szlabel,#label);
00054 #define record_var(label,type,val) result += ppConcat(type,_record_size)( &self->label, #label );
00055 #define record_varok(label,type,val,min,max) result += ppConcat(type,_record_size)( &self->label, #label );
00056 #define record_array(label,type,alen,val) result += ctl_record_objarray_head_size( #label,"array",#type ) + ((alen)*ppConcat(type,_serial_size)(&self->label));
00057 #define record_arrayok(label,type,alen,val,min,max) record_array(label,type,alen,val)
00058 #define record_objarray(label,type,alen) result += ctl_record_objarray_head_size( #label,"container",#type ); { array_foreach_const(type,self->label,curr) result += ppConcat(type,_record_size)(curr,#label); }
00059 #define record_achar(label,type,alen,val) result += ppConcat(type,_record_size_string)( self->label, alen, #label );
00060 #define record_string(label,type) result += ppConcat(type,_record_size_gstring)( &self->label, #label );
00061 #define record_obj(label,type) result += ppConcat(type,_record_size)(&self->label,#label);
00062 #define record_ref(label,type) if( NULL != self->label ) { result += ppConcat(type,_record_size)(self->label,#label); }
00063 #define record_preref(label,type) record_ref(label,type)
00064 #define record_enum(label,enum,val) result += ppConcat(enum,_record_size)( &self->label, #label );
00065 #define record_serial(label) result += ctl_serial_record_size(&self->label,#label);
00066 #define record_serialref(label) record_serial(label)
00067 #define record_member(stuff)
00068 #define record_atinit(stuff)
00069 #define record_atdestroy(stuff)
00070 #define record_atcopy(stuff)
00071 #define record_atmove(stuff)
00072 #define record_atswap(stuff)
00073 #define record_end(label) return result;\
00074 }
00075 #define record_alias(label,type)
00076
00077 #define union_begin(label,etype) size_t ppConcat(label,_record_size)( const label* self, const char* szlabel ) \
00078 {\
00079 size_t result;\
00080 assertobjconst(self);\
00081 assertconst(szlabel,1);\
00082 result = ctl_record_head_size(szlabel,#label);\
00083 result += ppConcat(etype,_record_size)( &self->type, "type" ); \
00084 switch( self->type )\
00085 {
00086 #define union_alias(type,enum) case enum:
00087 #define union_member(label,type,enum) case enum:\
00088 result += ppConcat(type,_record_size)(&self->obj.label,#label);\
00089 break;
00090 #define union_end(label,etype) default:\
00091 throwassert(ppTokStr(ppConcat(label,_record_size)) ":Unknown type");\
00092 break;\
00093 }\
00094 return result;\
00095 }
00096
00097 #define container_array(label,type,size)
00098 #define container_vector(label,type)
00099 #define container_list( label, type )
00100 #define container_map( label, keytype, type )
00101 #define container_multimap( label, keytype, type )
00102 #define container_set( label, type )
00103 #define container_multiset( label, type )
00104
00105 #define protocol_end( label )
00106
00107
00108 #include ctl_declarations
00109
00110
00111
00112
00113 #define UNDEF_ALL
00114 #include "ctl/dg/blank.h"
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 #define protocol_begin( label )
00141
00142
00143
00144
00145 #define enum_begin( label ) void ppConcat(label,_record_write)( const label* self, ctl_serial* serial, const char* szlabel ) \
00146 { \
00147 assertobjconst(self);\
00148 assertobjptr(serial);\
00149 assert( enum_isvalid(label,*self) );\
00150 { \
00151 const char* szEnum = enum_itemname(label,*self);\
00152 size_t szLen = cstrlen(char)(szEnum)+1;\
00153 ctl_record_write_begin( szconst(char,#label), szLen, serial, szlabel );\
00154 memcpy( serial->curr, szEnum, szLen );\
00155 serial->curr += szLen;\
00156 }\
00157 }
00158 #define enum_item( label )
00159 #define enum_end( label )
00160
00161
00162
00163
00164 #define record_begin(label) void ppConcat(label,_record_write)( const label* self, ctl_serial* serial, const char* szlabel ) \
00165 {\
00166 uint8* rectemp;\
00167 assertobjconst(self);\
00168 assertobjptr(serial);\
00169 assertconst(szlabel,1);\
00170 rectemp = ctl_record_write_begin( #label, 0, serial, szlabel );
00171 #define record_var(label,type,val) ppConcat(type,_record_write)( &self->label, serial, #label );
00172 #define record_varok(label,type,val,min,max) ppConcat(type,_record_write)( &self->label, serial, #label );
00173 #define record_array(label,type,alen,val) ppConcat(type,_record_writearray)( self->label, alen, serial, #label );
00174 #define record_arrayok(label,type,alen,val,min,max) ppConcat(type,_record_writearray)( self->label, alen, serial, #label );
00175 #define record_objarray(label,type,alen) {\
00176 uint8* rectemp = ctl_record_write_container_begin( "container", #type, 0,(alen), serial, #label );\
00177 array_foreach_const(type,self->label,curr)\
00178 ppConcat(type,_record_write)( curr, serial, #label );\
00179 ctl_record_write_end( rectemp, serial );\
00180 }
00181 #define record_achar(label,type,alen,val) ppConcat(type,_record_write_string)( self->label, alen, serial, #label );
00182 #define record_string(label,type) ppConcat(type,_record_write_string)( self->label.begin, ctl_gstring_size(type, &self->label), serial, #label );
00183 #define record_obj(label,type) ppConcat(type,_record_write)( &self->label, serial, #label );
00184 #define record_ref(label,type) { if( self->label ) { ppConcat(type,_record_write)( self->label, serial, #label ); } }
00185 #define record_preref(label,type) { if( self->label ) { ppConcat(type,_record_write)( self->label, serial, #label ); } }
00186 #define record_enum(label,enum,val) ppConcat(enum,_record_write)( &self->label, serial, #label );
00187 #define record_serial(label) ctl_serial_record_write(&self->label, serial, #label );
00188 #define record_serialref(label) record_serial(label)
00189 #define record_member(stuff)
00190 #define record_atinit(stuff)
00191 #define record_atdestroy(stuff)
00192 #define record_atcopy(stuff)
00193 #define record_atmove(stuff)
00194 #define record_atswap(stuff)
00195 #define record_end(label) ctl_record_write_end( rectemp, serial );\
00196 }
00197
00198 #define record_alias(label,type)
00199
00200 #define union_begin(label,etype) void ppConcat(label,_record_write)( const label* self, ctl_serial* serial, const char* szlabel ) \
00201 {\
00202 uint8* rectemp;\
00203 assertobjconst(self);\
00204 assertobjptr(serial);\
00205 assertconst(szlabel,1);\
00206 rectemp = ctl_record_write_begin( #label, 0, serial, szlabel );\
00207 ppConcat(etype,_record_write)( &self->type, serial, "type" );\
00208 switch( self->type )\
00209 {
00210 #define union_alias(type,enum) case enum:
00211 #define union_member(label,type,enum) case enum:\
00212 ppConcat(type,_record_write)( &self->obj.label, serial, #label );\
00213 break;
00214 #define union_end(label,etype) default:\
00215 throwassert(ppTokStr(ppConcat(label,_record_write)) ":Unknown type");\
00216 break;\
00217 }\
00218 ctl_record_write_end( rectemp, serial );\
00219 }
00220
00221 #define container_array(label,type,size)
00222 #define container_vector(label,type)
00223 #define container_list( label, type )
00224 #define container_map( label, keytype, type )
00225 #define container_multimap( label, keytype, type )
00226 #define container_set( label, type )
00227 #define container_multiset( label, type )
00228
00229 #define protocol_end( label )
00230
00231
00232 #include ctl_declarations
00233
00234
00235
00236
00237 #define UNDEF_ALL
00238 #include "ctl/dg/blank.h"
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 #define protocol_begin( label )
00252
00253
00254
00255
00256 #define enum_begin( label ) bool ppConcat(label,_record_read)( label* self, ctl_serial* serial, const char* szlabel ) \
00257 { \
00258 ctl_serial pserial = *serial;\
00259 assertobjptr(self);\
00260 assertobjptr(serial);\
00261 assertconst(szlabel,1);\
00262 if( ctl_record_find( &pserial, szlabel ) )\
00263 {\
00264 const char* sz = ctl_record_type( &pserial );\
00265 if( strcmp(sz, szconst(char,#label) ) )\
00266 ctl_serial_except( &pserial, "enum " #label ": Mismatch type!" );\
00267 ctl_record_getdata( &pserial );\
00268 {\
00269 ctl_sconst_auto(char, (char*)pserial.curr, (char*)pserial.end, got );\
00270 ctl_sconst_getenum(char, &got, (int*)self, enum_itemnames( label ) );\
00271 }\
00272 return true;\
00273 }\
00274 return false;\
00275 }
00276 #define enum_item( label )
00277 #define enum_end( label )
00278
00279
00280
00281
00282 #define record_begin(label) bool ppConcat(label,_record_read)( label* self, ctl_serial* serial, const char* szlabel ) \
00283 {\
00284 assertobjptr(self);\
00285 assertobjptr(serial);\
00286 assertconst(szlabel,1);\
00287 {\
00288 ctl_serial pserial = *serial;\
00289 if( ctl_record_find( &pserial, szlabel ) )\
00290 {\
00291 if( cstrcmp(char)(#label, ctl_record_type( &pserial ) ) )\
00292 ctl_serial_except(&pserial, "_record_read: Incorrect type!" );\
00293 ctl_record_getdata( &pserial );
00294 #define record_var(label,type,val) ppConcat(type,_record_read)( &self->label, &pserial, #label );
00295 #define record_varok(label,type,val,min,max) ppConcat(type,_record_read)( &self->label, &pserial, #label );
00296 #define record_array(label,type,alen,val) ppConcat(type,_record_readarray)( self->label, alen, &pserial, #label );
00297 #define record_arrayok(label,type,alen,val,min,max) ppConcat(type,_record_readarray)( self->label, alen, &pserial, #label );
00298 #define record_objarray(label,type,alen) {\
00299 ctl_serial ppserial = pserial;\
00300 if( ctl_record_find( &ppserial, #label ) )\
00301 {\
00302 size_t count = ctl_record_container_validatedata( &ppserial, "container", #type );\
00303 type* curr = self->label;\
00304 count = min((alen),count);\
00305 while( count-- )\
00306 {\
00307 ppConcat(type,_record_read)( curr, &ppserial, #label );\
00308 ctl_record_next( &ppserial );\
00309 curr++;\
00310 }\
00311 if( ppserial.curr != ppserial.end )\
00312 ctl_serial_except(&ppserial, #type " array read: Data read leftovers!" );\
00313 }\
00314 }
00315 #define record_achar(label,type,alen,val) ppConcat(type,_record_read_string)( self->label, (alen), &pserial, #label );
00316 #define record_string(label,type) ppConcat(type,_record_read_gstring)( &self->label, &pserial, #label );
00317 #define record_obj(label,type) ppConcat(type,_record_read)( &self->label, &pserial, #label );
00318 #define record_ref(label,type) { \
00319 ctl_serial ppserial = pserial;\
00320 if( ctl_record_find( &ppserial, #label ) )\
00321 {\
00322 ctl_delete(self->label);\
00323 ctl_new(self->label,type);\
00324 ppConcat(type,_record_read)( self->label, &ppserial, #label );\
00325 }\
00326 }
00327 #define record_preref(label,type) record_ref(label,type)
00328 #define record_enum(label,enum,val) ppConcat(enum,_record_read)( &self->label, &pserial, szconst(char,#label) );
00329 #define record_serial(label) ctl_serial_record_read(&self->label, &pserial, #label ); ctl_serial_deref(&self->label);
00330 #define record_serialref(label) ctl_serial_record_read(&self->label, &pserial, #label );
00331
00332 #define record_member(stuff)
00333 #define record_atinit(stuff)
00334 #define record_atdestroy(stuff)
00335 #define record_atcopy(stuff)
00336 #define record_atmove(stuff)
00337 #define record_atswap(stuff)
00338 #define record_end(label) return true;\
00339 }\
00340 }\
00341 return false;\
00342 }
00343
00344 #define record_alias(label,type)
00345
00346 #define union_begin(label,etype) bool ppConcat(label,_record_read)( label* self, ctl_serial* serial, const char* szlabel ) \
00347 {\
00348 assertobjptr(self);\
00349 assertobjptr(serial);\
00350 assertconst(szlabel,1);\
00351 {\
00352 ctl_serial pserial = *serial;\
00353 if( ctl_record_find( &pserial, szlabel ) )\
00354 {\
00355 if( cstrcmp(char)(#label, ctl_record_type( &pserial ) ) )\
00356 ctl_serial_except(&pserial, "_record_read: Incorrect type!" );\
00357 ctl_record_getdata( &pserial ); \
00358 ppConcat(etype,_record_read)( &self->type, &pserial, szconst(char,"type") );\
00359 switch( self->type )\
00360 {
00361 #define union_alias(type,enum) case enum:
00362 #define union_member(label,type,enum) case enum:\
00363 ppConcat(type,_record_read)( &self->obj.label, &pserial, #label );\
00364 return true;
00365 #define union_end(label,etype) default:\
00366 throwassert(ppTokStr(ppConcat(label,_record_read)) ":Unknown type");\
00367 break;\
00368 }\
00369 }\
00370 }\
00371 return false;\
00372 }
00373
00374 #define container_array(label,type,size)
00375 #define container_vector(label,type)
00376 #define container_list( label, type )
00377 #define container_map( label, keytype, type )
00378 #define container_multimap( label, keytype, type )
00379 #define container_set( label, type )
00380 #define container_multiset( label, type )
00381
00382 #define protocol_end( label )
00383
00384
00385 #include ctl_declarations
00386
00387
00388
00389
00390 #define UNDEF_ALL
00391 #include "ctl/dg/blank.h"
00392
00393 #endif
00394