patterns.h

00001 
00016 #ifndef ctl_declarations
00017 #error The 'ctl_declarations' template parameter was not defined.  It should be a string defined before #include.
00018 #endif
00019 
00020 #ifndef DATAGEN_H
00021 #include "ctl/dg/datagen.h"
00022 #endif
00023 
00024 #define UNDEF_ALL
00025 #include "ctl/dg/blank.h"
00026 
00027 /****************************************************************************
00028  * \ingroup Patterns
00029  * Declare a protocol
00030  * 
00031  * This defines a basic naming convention and code body for enumeration 
00032  * handlers.  Declaring it like this makes auto-generating a switch or a 
00033  * lookup table very straight-forward.  
00034  * 
00035  * The following code defines the protocol pattern
00036  * 
00037  *  protocol_begin( label )
00038  *      data decls
00039  *      ...
00040  *  protocol_end( label )
00041  ****************************************************************************/
00042 
00048 #define protocol_begin( label )
00049 
00050 
00051 /****************************************************************************
00052  * \ingroup Patterns
00053  * Declare an enumeration
00054  * 
00055  * This defines a basic naming convention and code body for enumeration 
00056  * handlers.  Declaring it like this makes auto-generating a switch or a 
00057  * lookup table very straight-forward.  
00058  * 
00059  * The following code defines the enumeration pattern
00060  * 
00061  *  enum_begin( label )
00062  *      enum_item( label )
00063  *      ...
00064  *  enum_end( label )
00065  ****************************************************************************/
00066 
00072 #define enum_begin( label )             typedef enum {
00073 
00078 #define enum_item( label )                  label,
00079 
00084 #define enum_end( label )                   enum_count( label )\
00085                                         } label;\
00086                                         extern const bool ppConcat(label,_isscalar);\
00087                                         extern const char* const ppConcat(szz,label)[];
00088 
00089 
00090 /****************************************************************************
00091  * \ingroup Patterns
00092  * Declare a class/struct/record
00093  *
00094  * A record basically produces a C structure that native C code can make 
00095  * normal use of, while generating all the glue that would normally need to
00096  * be separately written and maintained.
00097  *
00098  * The following code defines the record pattern
00099  * 
00100  *  record_begin(label)
00101  *      record_var(label,type,val)
00102  *      record_varok(label,type,val,min,max)
00103  *      record_array(label,type,alen,val)
00104  *      record_arrayok(label,type,alen,val,min,max)
00105  *      record_objarray(label,type,alen)
00106  *      record_achar(label,type,alen,val)
00107  *      record_string(label,type)
00108  *      record_obj(label,type)
00109  *      record_ref(label,type)
00110  *      record_preref(label,type)
00111  *      record_enum(label,type,val)
00112  *      record_member(stuff)
00113  *      record_serial(label)
00114  *      record_serialref(label)
00115  *      record_atinit(stuff)
00116  *      record_atdestroy(stuff)
00117  *      ...
00118  *  record_end(label)
00119  * 
00120  ****************************************************************************/
00121 
00127 #define record_begin(label)                         typedef struct label {
00128 
00136 #define record_var(label,type,val)                      type label;
00137 
00147 #define record_varok(label,type,val,min,max)            type label;
00148 
00157 #define record_array(label,type,alen,val)               type label[alen];
00158 
00169 #define record_arrayok(label,type,alen,val,min,max)     type label[alen];
00170 
00178 #define record_objarray(label,type,alen)                type label[alen];
00179 
00188 #define record_achar(label,type,alen,val)               type label[alen];
00189 
00196 #define record_string(label,type)                       ctl_gstring(type) label;
00197 
00204 #define record_obj(label,type)                          type label;
00205 
00212 #define record_ref(label,type)                          type* label;
00213 
00220 #define record_preref(label,type)                       type* label;
00221 
00229 #define record_enum(label,type,val)                     type label;
00230 
00237 #define record_serial(label)                            ctl_serial  label;
00238 
00247 #define record_serialref(label)                         ctl_serial  label;
00248 
00249 
00255 #define record_member(stuff)                            stuff
00256 
00261 #define RECORD_MEMBERS
00262 
00269 #define record_atinit(stuff)
00270 
00277 #define record_atdestroy(stuff)
00278 
00285 #define record_atcopy(stuff)
00286 
00293 #define record_atmove(stuff)
00294 
00301 #define record_atswap(stuff)
00302 
00308 #define record_end(label)                               ppCPP( public: )    /* C++ code generated if we're building under C++ */\
00309                                                         ppCPP( const classname& operator=( const label& src ) { ppConcat(label,_destroy)(this); ppConcat(label,_copy)(this,&src); return *this; } )\
00310                                                     } label;\
00311                                                     /* These functions are bundled up so we can semi-trivially manufacture record declarations for extensions */\
00312                                                     ctl_datagen_declare_functions(label);\
00313                                                     /* Unit test optional randomizer */\
00314                                                     RANDOMIZER( void ppConcat(label,_randomize)( label* self ); )\
00315 
00316 
00322 #define record_alias(label,type)
00323 
00324 #ifdef MAKE_RANDOMIZE
00325 #define RANDOMIZER(def) def
00326 #else
00327 #define RANDOMIZER(def)
00328 #endif
00329 
00330 /****************************************************************************
00331  * \ingroup Patterns
00332  * \brief Declare an enumerated union type
00333  * \param label What to call the record
00334  * \param etype Enumeration that controls union switch
00335  * This particular pass makes the enumeration for the union items
00336  * union_begin(label,etype)
00337  *  union_member(label,type,enum)
00338  *  union_alias(type,enum)
00339  *  union_alias(type,enum)
00340  *  union_member(label,type,enum)
00341  *  ...
00342  * union_end(label,etype)
00343  ****************************************************************************/
00344 #define union_begin(label,etype)            typedef struct label {\
00345                                                 etype   type;\
00346                                                 union {
00347 
00348 
00368 #define union_alias(type,enum)
00369 
00377 #define union_member(label,type,enum)               type label;
00378 
00384 #define union_end(label,etype)                  }   obj;\
00385                                             } label;\
00386                                             /* These functions are bundled up so we can semi-trivially manufacture record declarations for extensions */\
00387                                             ctl_datagen_declare_functions(label);\
00388                                             /* Unit test optional randomizer */\
00389                                             RANDOMIZER( void ppConcat(label,_randomize)( label* self ); )\
00390                                             void ppConcat(label,_setup)( label* self, etype which );\
00391                                             void ppConcat(label,_reset)( label* self, etype which );
00392 
00393 /****************************************************************************
00394  * \ingroup Patterns
00395  * Declare various containers
00396  *
00397  * In this system, records and containers are tightly integrated, such that 
00398  * all containers and their contained records are copied, serialized, etc. 
00399  * correctly.  This manufactures the code to correctly serialize based on 
00400  * the established structure/class/record patterns.  
00401  * 
00402  * All containers are initially empty and consume only their own structure 
00403  * overhead.  
00404  * 
00405  ****************************************************************************/
00406 
00410 #define container_array(label,type,size)            ctl_declare_array(label,type,size);
00411 
00415 #define container_vector(label,type)                ctl_declare_vector(label,type);
00416 
00424 #define container_list(label,type)                  ctl_declare_list(label,type);
00425 
00435 #define container_map(label,keytype,type)           ctl_declare_map(label,keytype,type);
00436 
00446 #define container_multimap(label,keytype,type)      ctl_declare_multimap(label,keytype,type);
00447 
00456 #define container_set(label,type)                   ctl_declare_set(label,type);
00457 
00466 #define container_multiset(label,type)              ctl_declare_multiset(label,type);
00467 
00473 #define protocol_end( label )
00474 
00475 #include ctl_declarations
00476 #define UNDEF_ALL
00477 #include "ctl/dg/blank.h"
00478 
00482 #define protocol_begin(label)           typedef enum label {
00483 
00484 #define enum_begin( label )
00485 #define enum_item( label )
00486 #define enum_end( label )
00487 
00488 #define record_begin(label)                 ppConcat(e,label),
00489 #define record_var(label,type,val)
00490 #define record_varok(label,type,val,min,max)
00491 #define record_array(label,type,alen,val)
00492 #define record_arrayok(label,type,alen,val,min,max)
00493 #define record_objarray(label,type,alen)
00494 #define record_achar(label,type,alen,val)
00495 #define record_string(label,type)
00496 #define record_obj(label,type)
00497 #define record_ref(label,type)
00498 #define record_preref(label,type)
00499 #define record_enum(label,type,val)
00500 #define record_serial(label)
00501 #define record_serialref(label)
00502 #define record_member(stuff)
00503 #define record_atinit(stuff)
00504 #define record_atdestroy(stuff)
00505 #define record_atcopy(stuff)
00506 #define record_atmove(stuff)
00507 #define record_atswap(stuff)
00508 #define record_end(label)
00509 
00510 #define record_alias(label,type)            ppConcat(e,label),
00511 
00512 #define union_begin(label,etype)            ppConcat(e,label),
00513 #define union_alias(type,enum)
00514 #define union_member(label,type,enum)
00515 #define union_end(label,etype)
00516 
00517 
00518 #define container_array(label,type,size)
00519 #define container_vector(label,type)
00520 #define container_list(label,type)
00521 #define container_map(label,keytype,type)
00522 #define container_multimap(label,keytype,type)
00523 #define container_set(label,type)
00524 #define container_multiset(label,type)
00525 
00526 #define protocol_end(label)                 enum_count( label )\
00527                                         } label;\
00528                                         extern const bool ppConcat(label,_isscalar);\
00529                                         extern const char* const ppConcat(szz,label)[];
00530 
00531 #include ctl_declarations
00532 #undef ctl_declarations
00533 #undef ctl_classdef
00534 #define UNDEF_ALL
00535 #include "ctl/dg/blank.h"

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