instance.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 #define protocol_begin( label )                     const char* const ppConcat(szz,label)[1+ppConcat(label,_COUNT)] = \
00020                                                     {   /* The enumeration as strings */
00021 
00022 /*
00023  * Make enumeration
00024  */
00025 #define enum_begin( label )
00026 #define enum_item( label )
00027 #define enum_end( label )
00028 
00029 /*
00030  * Make record
00031  *
00032  * Note the odd syntax for adding this up makes it clear to even the dumbest 
00033  * compilers that we're adding a bunch of constants, so simple records with 
00034  * all scalar contents will generally boil down to sticking a size_t on the
00035  * stack or in a register and returning.
00036  */
00037 #define record_begin(label)                             #label,
00038 #define record_var(label,type,val)
00039 #define record_varok(label,type,val,min,max)
00040 #define record_array(label,type,alen,val)
00041 #define record_arrayok(label,type,alen,val,min,max)
00042 #define record_objarray(label,type,alen)
00043 #define record_achar(label,type,alen,val)
00044 #define record_string(label,type)
00045 #define record_obj(label,type)
00046 #define record_ref(label,type)
00047 #define record_preref(label,type)
00048 #define record_enum(label,enum,val)
00049 #define record_serial(label)
00050 #define record_serialref(label)
00051 #define record_member(stuff)
00052 #define record_atinit(stuff)
00053 #define record_atdestroy(stuff)
00054 #define record_atcopy(stuff)
00055 #define record_atmove(stuff)
00056 #define record_atswap(stuff)
00057 #define record_end(label)
00058 
00059 #define record_alias(label,type)                        #label,
00060 
00061 #define union_begin(label,etype)
00062 #define union_alias(type,enum)
00063 #define union_member(label,type,enum)
00064 #define union_end(label,etype)
00065 
00066 #define container_array(label,type,size)
00067 #define container_vector(label,type)
00068 #define container_list( label, type )
00069 #define container_map( label, keytype, type )
00070 #define container_multimap( label, keytype, type )
00071 #define container_set( label, type )
00072 #define container_multiset( label, type )
00073 
00074 #define protocol_end( label )                           NULL\
00075                                                     };\
00076                                                     /* Establish the type_init pattern for enum, such as for union members. */\
00077                                                     void ppConcat(label,_init)( label* self ) \
00078                                                     { \
00079                                                         *self = (label)0; \
00080                                                     }\
00081                                                     const bool ppConcat(label,_isscalar) = true;
00082 
00083 
00084 /****************************************************************************
00085  * \ingroup Patterns
00086  * 
00087  * Initialization
00088  *
00089  * Generate code to initialize a record to its default state.
00090  * 
00091  ****************************************************************************/
00092 
00093 #define UNDEF_ALL
00094 #include "ctl/dg/blank.h"
00095 
00100 #define RECORD_INITS
00101 
00102 /*
00103  * Make enum, enum string table for protocol, if defined
00104  */
00105 #define protocol_begin( label )
00106 
00107 
00108 /*
00109  * Make enum, enum string table
00110  */
00111 #define enum_begin( label )                         /* The enumeration as strings */\
00112                                                     const char* const ppConcat(szz,label)[1+ppConcat(label,_COUNT)] = \
00113                                                     {
00114 #define enum_item( label )                              #label,
00115 #define enum_end( label )                               NULL\
00116                                                     };\
00117                                                     /* Establish the type_init pattern for enum, such as for union members. */\
00118                                                     void ppConcat(label,_init)( label* self ) \
00119                                                     { \
00120                                                         *self = (label)0; \
00121                                                     }\
00122                                                     const bool ppConcat(label,_isscalar) = true;
00123 
00124 
00125 /*
00126  * Make record
00127  */
00128 #define record_begin(label)                         void ppConcat(label,_init)( label* self ) \
00129                                                     {\
00130                                                         assertobjptr( self ); /* Assert: valid inputs */
00131 #define record_var(label,type,val)                      self->label = (type)(val);
00132 #define record_varok(label,type,val,min,max)            self->label = (type)(val);
00133 #define record_array(label,type,alen,val)               array_fill( type, self->label, alen, val );
00134 #define record_arrayok(label,type,alen,val,min,max)     array_fill( type, self->label, alen, val );
00135 #define record_objarray(label,type,alen)                { array_foreach(type,self->label, curr ) ppConcat(type,_init)(curr); }
00136 #define record_achar(label,type,alen,val)               cstrncpy(type)(self->label, (val), (alen) );
00137 #define record_string(label,type)                       ctl_gstring_init(type, &self->label );
00138 #define record_obj(label,type)                          ppC(ppConcat(type,_init)(&self->label);) /* C++ will invoke its default constructor */
00139 #define record_ref(label,type)                          self->label = NULL;
00140 #define record_preref(label,type)                       ctl_new(self->label,type); 
00141 #define record_enum(label,type,val)                     self->label = (val);
00142 #define record_serial(label)                            ctl_serial_init(&(self->label),NULL,NULL);
00143 #define record_serialref(label)                         ctl_serial_init(&(self->label),NULL,NULL);
00144 #define record_member(stuff)                            
00145 #define record_atinit(stuff)                            { stuff }
00146 #define record_atdestroy(stuff)
00147 #define record_atcopy(stuff)
00148 #define record_atmove(stuff)
00149 #define record_atswap(stuff)
00150 #define record_end(label)                           }\
00151                                                     const bool ppConcat(label,_isscalar) = false;
00152 #define record_alias(label,type)
00153 
00154 
00155 /*
00156  * Make union default initializer
00157  */
00158 #define union_begin(label,etype)                    void ppConcat(label,_setup)( label* self, etype which ) \
00159                                                     {\
00160                                                         self->type = which;\
00161                                                         switch( self->type )\
00162                                                         {
00163 #define union_alias(type,enum)                          case enum:
00164 #define union_member(label,type,enum)                   case enum:\
00165                                                             ppConcat(type,_init)(&self->obj.label);\
00166                                                             break;
00167 #define union_end(label,etype)                          default:\
00168                                                             throwassert(ppTokStr(ppConcat(label,_setup)) ":Unknown type");\
00169                                                             break;\
00170                                                         }\
00171                                                     }\
00172                                                     const bool ppConcat(label,_isscalar) = false;\
00173                                                     /* Default initializer, probably wrong */\
00174                                                     void ppConcat(label,_init)( label* self ) \
00175                                                     { \
00176                                                         ppConcat(label,_setup)( self, (etype)0 ); \
00177                                                     }\
00178                                                     /* Reset to different type */\
00179                                                     void ppConcat(label,_reset)( label* self, etype which )\
00180                                                     {\
00181                                                         ppConcat(label,_destroy)( self ); \
00182                                                         ppConcat(label,_setup)( self, which ); \
00183                                                     }
00184 
00185 /*
00186  * Make containers
00187  */
00188 #define container_array(label,type,size)            ctl_implement_array(label,type,ctl_cooked)
00189 #define container_vector(label,type)                ctl_implement_vector(label,type,ctl_cooked)
00190 #define container_list( label, type )               ctl_implement_list(label,type)
00191 #define container_map( label, keytype, type )       ctl_implement_map(label,keytype,type)
00192 #define container_multimap( label, keytype, type )  ctl_implement_multimap(label,keytype,type)
00193 #define container_set( label, type )                ctl_implement_set(label,type)
00194 #define container_multiset( label, type )           ctl_implement_multiset(label,type)
00195 
00196 #define protocol_end( label )
00197 
00198 /* Run definitions through translation */
00199 #include ctl_declarations
00200 
00201 /*
00202  * Clean up the namespace 
00203  */
00204 #define UNDEF_ALL
00205 #include "ctl/dg/blank.h"
00206 
00207 /****************************************************************************
00208  * \ingroup Patterns
00209  * Destruction
00210  *
00211  * Generate code to destroy a record, freeing any resources it contains
00212  * 
00213  ****************************************************************************/
00214 
00219 #define RECORD_DESTROY
00220 
00221 #define protocol_begin( label )     enum_begin( label )
00222 
00223 /*
00224  * Make enum
00225  */
00226 #define enum_begin( label )                         void ppConcat(label,_destroy)( label* self ) {}
00227 #define enum_item( label )
00228 #define enum_end( label )
00229 
00230 /*
00231  * Make record destroy
00232  */
00233 #define record_begin(label)                         void ppConcat(label,_destroy)( label* self ) \
00234                                                     {\
00235                                                         assertobjptr( self ); /* Assert: valid inputs */
00236 #define record_var(label,type,val)
00237 #define record_varok(label,type,val,min,max)
00238 #define record_array(label,type,alen,val)
00239 #define record_arrayok(label,type,alen,val,min,max)
00240 #define record_objarray(label,type,alen)                ppC({ array_foreach(type,self->label, curr ) ppConcat(type,_destroy)(curr); }) /* C++ will invoke its default constructors */
00241 #define record_achar(label,type,alen,val)
00242 #define record_string(label,type)                       ctl_gstring_destroy(type, &self->label );
00243 #define record_obj(label,type)                          ppC(ppConcat(type,_destroy)(&self->label);) /* C++ will invoke its default constructor */
00244 #define record_ref(label,type)                          ctl_delete(self->label);
00245 #define record_preref(label,type)                       ctl_delete(self->label);
00246 #define record_enum(label,type,val)
00247 #define record_serial(label)                            ctl_serial_free( &self->label );
00248 #define record_serialref(label)                         record_serial(label)
00249 #define record_member(stuff)                            
00250 #define record_atinit(stuff)
00251 #define record_atdestroy(stuff)                         { stuff }
00252 #define record_atcopy(stuff)
00253 #define record_atmove(stuff)
00254 #define record_atswap(stuff)
00255 #define record_end(label)                           }
00256 
00257 #define record_alias(label,type)
00258 
00259 /*
00260  * Make union destroy
00261  */
00262 #define union_begin(label,etype)                    void ppConcat(label,_destroy)( label* self ) \
00263                                                     {\
00264                                                         switch( self->type )\
00265                                                         {
00266 #define union_alias(type,enum)                          case enum:
00267 #define union_member(label,type,enum)                   case enum:\
00268                                                             ppConcat(type,_destroy)(&self->obj.label);\
00269                                                             break;
00270 #define union_end(label,etype)                          default:\
00271                                                             throwassert(ppTokStr(ppConcat(label,_destroy)) ":Unknown type");\
00272                                                             break;\
00273                                                         }\
00274                                                     }
00275 
00276 #define container_array(label,type,size)
00277 #define container_vector(label,type)
00278 #define container_list( label, type )
00279 #define container_map( label, keytype, type )
00280 #define container_multimap( label, keytype, type )
00281 #define container_set( label, type )
00282 #define container_multiset( label, type )
00283 
00284 #define protocol_end( label )
00285 
00286 /* Run definitions through translation */
00287 #include ctl_declarations
00288 
00289 /*
00290  * Clean up the namespace 
00291  */
00292 #define UNDEF_ALL
00293 #include "ctl/dg/blank.h"
00294 
00295 #ifndef NO_RECORD_COPY
00296 
00297 /****************************************************************************
00298  * \ingroup Patterns
00299  * Copy
00300  *
00301  * Generate code to copy one record to another
00302  * Destination of copy is assumed to be uninitialized.
00303  *
00304  ****************************************************************************/
00305 
00310 #define RECORD_COPIES
00311 
00312 #define protocol_begin( label )                     enum_begin( label )
00313 
00314 /*
00315  * Make enum
00316  */
00317 #define enum_begin( label )                         void ppConcat(label,_copy)( label* dst, const label* src ) { *dst = *src; }
00318 #define enum_item( label )
00319 #define enum_end( label )
00320 
00321 
00322 /*
00323  * Make record
00324  */
00325 #define record_begin(label)                         void ppConcat(label,_copy)( label* dst, const label* src ) \
00326                                                     {\
00327                                                         assertobjptr(dst);\
00328                                                         assertobjconst(src);
00329 #define record_var(label,type,val)                      dst->label = src->label;
00330 #define record_varok(label,type,val,min,max)            dst->label = src->label;
00331 #define record_array(label,type,alen,val)               record_objarray(label,type,alen)
00332 #define record_arrayok(label,type,alen,val,min,max)     record_objarray(label,type,alen)
00333 #define record_objarray(label,type,alen)                {   type* dstcurr = dst->label; \
00334                                                             const type* srccurr = src->label; \
00335                                                             const type* pend = dstcurr + (alen); \
00336                                                             while( dstcurr < pend ) \
00337                                                                 ppConcat(type,_copy)(dstcurr++,srccurr++);\
00338                                                         }
00339 #define record_achar(label,type,alen,val)               cstrncpy(type)(dst->label,src->label,alen);
00340 #define record_string(label,type)                       ctl_gstring_init_sz(type, &dst->label, src->label.begin );
00341 #define record_obj(label,type)                          ppConcat(type,_copy)(&dst->label,&src->label);
00342 #define record_ref(label,type)                          ctl_ref(dst->label,src->label);
00343 #define record_preref(label,type)                       record_ref(label,type)
00344 #define record_enum(label,enum,val)                     dst->label = src->label;
00345 #define record_serial(label)                            ctl_serial_copy( &dst->label, &src->label ); ctl_serial_deref(&dst->label);
00346 #define record_serialref(label)                         ctl_serial_copy( &dst->label, &src->label ); 
00347 #define record_member(stuff)                            
00348 #define record_atinit(stuff)
00349 #define record_atdestroy(stuff)
00350 #define record_atcopy(stuff)                            { stuff }
00351 #define record_atmove(stuff)
00352 #define record_atswap(stuff)
00353 #define record_end(label)                           }
00354 
00355 #define record_alias(label,type)
00356 
00357 /*
00358  * Make union copy
00359  */
00360 #define union_begin(label,etype)                    void ppConcat(label,_copy)( label* dst, const label* src ) \
00361                                                     {\
00362                                                         dst->type = src->type;\
00363                                                         switch( dst->type )\
00364                                                         {
00365 #define union_alias(type,enum)                          case enum:
00366 #define union_member(label,type,enum)                   case enum:\
00367                                                             ppConcat(type,_copy)(&dst->obj.label,&src->obj.label);\
00368                                                             break;
00369 #define union_end(label,etype)                          default:\
00370                                                             throwassert(ppTokStr(ppConcat(label,_copy)) ":Unknown type");\
00371                                                             break;\
00372                                                         }\
00373                                                     }
00374 
00375 #define container_array(label,type,size)
00376 #define container_vector(label,type)
00377 #define container_list( label, type )
00378 #define container_map( label, keytype, type )
00379 #define container_multimap( label, keytype, type )
00380 #define container_set( label, type )
00381 #define container_multiset( label, type )
00382 
00383 #define protocol_end( label )       
00384 
00385 /* Run definitions through translation */
00386 #include ctl_declarations
00387 
00388 /*
00389  * Clean up the namespace 
00390  */
00391 #define UNDEF_ALL
00392 #include "ctl/dg/blank.h"
00393 
00394 #endif /* NO_RECORD_COPY */
00395 
00396 #ifndef NO_RECORD_VALID
00397 
00398 /****************************************************************************
00399  * \ingroup Patterns
00400  * Validity test
00401  *
00402  * Generate code to do bounds checks on a record for assertions, sanity tests
00403  * etc.
00404  *
00405  ****************************************************************************/
00406 
00407 #define protocol_begin( label )                     enum_begin( label )
00408 
00409 /*
00410  * Make enum
00411  */
00412 #define enum_begin( label )                         bool ppConcat(label,_valid)( const label* self ) { return enum_isvalid(label,*self); }
00413 #define enum_item( label )
00414 #define enum_end( label )
00415 
00416 /*
00417  * Make record
00418  */
00419 #define record_begin(label)                         bool ppConcat(label,_valid)( const label* self ) \
00420                                                     {\
00421                                                         if( NULL == self ) return false; /* A bad pointer is definitely invalid */
00422 #define record_var(label,type,val)                  
00423 #define record_varok(label,type,val,min,max)            if( self->label < (min) || self->label > (max) ) return false;
00424 #define record_array(label,type,alen,val)
00425 #define record_arrayok(label,type,alen,val,min,max)     { array_foreach_const(type,self->label, curr ) if( *curr < (min) || (*curr > (max)) ) return false; }
00426 #define record_objarray(label,type,alen)                { array_foreach_const(type,self->label, curr ) if( !ppConcat(type,_valid)(curr) ) return false; }
00427 #define record_achar(label,type,alen,val)
00428 #define record_string(label,type)                       
00429 #define record_obj(label,type)                          if( !ppConcat(type,_valid)(&self->label) ) return false;
00430 #define record_ref(label,type)                          if( self->label && !ppConcat(type,_valid)(self->label) ) return false;
00431 #define record_preref(label,type)                       record_ref(label,type)
00432 #define record_enum(label,enum,val)                     if( !enum_isvalid(enum,self->label) ) return false;
00433 #define record_serial(label)                            if( self->label.curr < self->label.begin || self->label.curr > self->label.end ) return false;
00434 #define record_serialref(label)                         record_serial(label)
00435 #define record_member(stuff)
00436 #define record_atinit(stuff)
00437 #define record_atdestroy(stuff)
00438 #define record_atcopy(stuff)
00439 #define record_atmove(stuff)
00440 #define record_atswap(stuff)
00441 #define record_end(label)                               return true;\
00442                                                     }
00443 /*
00444  * Make union validator
00445  */
00446 #define union_begin(label,etype)                    bool ppConcat(label,_valid)( const label* self ) \
00447                                                     {\
00448                                                         switch( self->type )\
00449                                                         {
00450 #define union_alias(type,enum)                          case enum:
00451 #define union_member(label,type,enum)                   case enum:\
00452                                                             return ppConcat(type,_valid)(&self->obj.label);
00453 #define union_end(label,etype)                          default:\
00454                                                             /* Unknown type */\
00455                                                             return false;\
00456                                                         }\
00457                                                     }
00458 
00459 #define record_alias(label,type)
00460 
00461 #define container_array(label,type,size)
00462 #define container_vector(label,type)
00463 #define container_list( label, type )
00464 #define container_map( label, keytype, type )
00465 #define container_multimap( label, keytype, type )
00466 #define container_set( label, type )
00467 #define container_multiset( label, type )
00468 
00469 #define protocol_end( label )
00470 
00471 /* Run definitions through translation */
00472 #include ctl_declarations
00473 
00474 /*
00475  * Clean up the namespace 
00476  */
00477 #define UNDEF_ALL
00478 #include "ctl/dg/blank.h"
00479 
00480 #endif /* NO_RECORD_VALID */
00481 
00482 #ifndef NO_RECORD_SIZE
00483 
00484 /****************************************************************************
00485  * \ingroup Patterns
00486  * Memory Size
00487  *
00488  * Generate code to determine how much actual memory a record is consuming, 
00489  * including its allocations
00490  *
00491  ****************************************************************************/
00492 
00493 #define protocol_begin( label )                     enum_begin( label )
00494 
00495 /*
00496  * Make enumeration
00497  */
00498 #define enum_begin( label )                         size_t ppConcat(label,_size)( const label* self ) { return sizeof(*self); }
00499 #define enum_item( label )
00500 #define enum_end( label )
00501 
00502 /*
00503  * Make record
00504  *
00505  * Note the odd syntax for adding this up makes it clear to even the dumbest 
00506  * compilers that we're adding a bunch of constants, so simple records with 
00507  * all scalar contents will generally boil down to sticking a size_t on the
00508  * stack or in a register and returning.
00509  */
00510 #define record_begin(label)                         size_t ppConcat(label,_size)( const label* self ) \
00511                                                     {\
00512                                                         size_t result;\
00513                                                         assertobjconst( self ); /* Assert: valid inputs */\
00514                                                         result = sizeof(*self)
00515 #define record_var(label,type,val)
00516 #define record_varok(label,type,val,min,max)
00517 #define record_array(label,type,alen,val)
00518 #define record_arrayok(label,type,alen,val,min,max)
00519 #define record_objarray(label,type,alen)                ; { array_foreach_const(type,self->label, curr ) result += ppConcat(type,_size)( curr ); } result = (result - sizeof(self->label))
00520 #define record_achar(label,type,alen,val)
00521 #define record_string(label,type)                       + (self->label.endBuff - self->label.begin)
00522 #define record_obj(label,type)                          + (ppConcat(type,_size)( &self->label ) - sizeof(self->label))
00523 #define record_ref(label,type)                          + (NULL == self->label ? 0 : ppConcat(type,_size)( self->label ))
00524 #define record_preref(label,type)                       record_ref(label,type)
00525 #define record_enum(label,enum,val)
00526 #define record_serial(label)                            + (NULL == self->label.buff ? 0 : ctl_serial_total( &self->label ) )
00527 #define record_serialref(label)                         record_serial(label)
00528 #define record_member(stuff)
00529 #define record_atinit(stuff)
00530 #define record_atdestroy(stuff)
00531 #define record_atcopy(stuff)
00532 #define record_atmove(stuff)
00533 #define record_atswap(stuff)
00534 #define record_end(label)                               ; return result;\
00535                                                     }
00536 
00537 #define record_alias(label,type)
00538 
00539 /*
00540  * Make union memory measurement
00541  */
00542 #define union_begin(label,etype)                    size_t ppConcat(label,_size)( const label* self ) \
00543                                                     {\
00544                                                         switch( self->type )\
00545                                                         {
00546 #define union_alias(type,enum)                          case enum:
00547 #define union_member(label,type,enum)                   case enum:\
00548                                                             return sizeof(*self) + ppConcat(type,_size)(&self->obj.label) - sizeof(type);
00549 #define union_end(label,etype)                          default:\
00550                                                             /* Unknown type */\
00551                                                             return sizeof(*self);\
00552                                                         }\
00553                                                     }
00554 
00555 #define container_array(label,type,size)
00556 #define container_vector(label,type)
00557 #define container_list( label, type )
00558 #define container_map( label, keytype, type )
00559 #define container_multimap( label, keytype, type )
00560 #define container_set( label, type )
00561 #define container_multiset( label, type )
00562 
00563 #define protocol_end( label )
00564 
00565 /* Run definitions through translation */
00566 #include ctl_declarations
00567 
00568 /*
00569  * Clean up the namespace 
00570  */
00571 #define UNDEF_ALL
00572 #include "ctl/dg/blank.h"
00573 
00574 #endif /* NO_RECORD_SIZE */
00575 

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