Thursday, 28 March 2013

Code Generation By C Macro

The C Macro Code Generation technique can be found in link http://www.rt-embedded.com/blog/archives/macros-in-the-c-programming-language/

Now C Macro is not only useful for embedded programming, but also Object Oriented Design and Programming.

When talking about OO Design, it can be considered into two level of code reuse:

1. Interface Reuse;  It provides the flexibility and encapsulates the specific logic into subclasses well , however the number of classes can be big in a large system. 

2. Implementation Reuse; Most of the subclasses implementation are the same except some customized class.

So, Programming based on interface is the motivation, and implementation reusing is good code feature of large amounts' class definition auto generation.

See example:

Define the basic operation first:

/**
 *   basic def block
 */
#define LIMIT_BASIC_DEF( limit, param ) \

#undef LIMIT_BASIC_DEF


Define the list:

#define LIMIT_INTEGER_VALUE_GROUP(param) \
    LIMIT_BASIC_DEF(LimitMaxOrdQty, param); \
    LIMIT_BASIC_DEF(EquityBuyQtyLimit, param); \
    LIMIT_BASIC_DEF(EquitySellQtyLimit, param); \


One Behavior:

#define LIMIT_BASIC_DEF(limit, param) \
    LimitCreateClickedProcessorDefaultImpl(limit, param);

LIMIT_INTEGER_VALUE_GROUP(IntegerValueVerifier);

#undef LIMIT_BASIC_DEF


The Other Behavior:

#define LIMIT_BASIC_DEF(limit, param) \
    CreateLimitDialogComboBoxSelectedClickedProcessorDefaultImpl(limit);
LIMIT_INTEGER_VALUE_GROUP(0);

#undef LIMIT_BASIC_DEF



No comments:

Post a Comment