title: Code generation using preprocessor macros
body: <p>Lately, I am working in a project, that has a lot of code that is being generated using macros. I have come across such situation where generated code was very less. But in this current one there is a lot of code that is being generated using #defines etc. 
  Example, like a class for event generation and processing and generating class Id's for class.</p>
  
  <pre><code>#define INIT_EVENT_INFO(eventType) \
     template &lt;&gt; const GenericClassID eventType::tClassID(#eventType) ;
  
  #define DECLARE_EVENT(dType, evtType, destnType) \
     typedef DUMMY_EVT_GEN&lt;dType, std_event, custom_destn, destnType&gt;::EventClass evtType;
  
  template &lt;typename ctData,
            EventTypes evType,
            DestnTypes evtDestType = standard_destn,
            class DestnInterface = EmptyClass&gt;
  class DUMMY_EVT_GEN
  {
  private:
     // alias for our current generator
     typedef DUMMY_EVT_GEN&lt;ctData,
                                evType,
                                evtDestType,
                                DestnInterface&gt; Generator;
  
     // Construct the first layer by adding the data part to our
     // framework event base class.
     //
     typedef BaseEvent::DerivedEvent&lt;Generator&gt; CompleteEvent_;
  
  
     /*
      * Assemble an event destn type
      */
  
     // Determine base class for event Destn: RTTIEventDestn for
     // rtiDestns
     typedef typename IF&lt;isRtiDestn, BRTTIEventDestn, EventDestn&gt;::type DestnBase_;
  
     // create event Destn type
     typedef typename IF&lt;isCustomDestn, DestnInterface, BaseEvent::THBDestn&lt;Generator&gt; &gt;::type DestnType_;
  
  public:
  
     /**
      * A struct that contains all configuration options 
      */
     struct Config
     {
        /// base class for the Destn (rti or not)
        typedef DestnBase_  DestnBaseClass;
        /// class serving as data container for the event type
        typedef ctData     EventDataClass;
  
        /// the resulting event type
        typedef CompleteEvent_ EventClass;
        /// the resulting Destn interface type
        typedef DestnType_  DestnInterface;
     };
  
     // our final return values
     typedef typename Config::EventClass EVT;
     typedef typename Config::DestnInterface DestnInterface;
     typedef typename Config::EventClass EventClass;
  };
  </code></pre>
  
  <p>Now, my question is, Is there a specific way that already defines such things.</p>
  
  <p><strong>Hash defines can be used at one's own liberty.</strong> 
  But, are there any defined patterns or ways to write such a code, which helps us generate such code. Not only this scenario. There are many other scenarios, where such a code can be written and used for auto generation of classes, events, structures etc.</p>
  
  <p>As a programmer, how to think of writing such macros' which will ease our effort. It does comes by practice, but are there any specific ways or patterns 
   or any documents which helps us to program this way, I mean to think of programming using such macros.</p>
  
  <p>Any pointers or suggestions will be of great help.</p>