/* * Action_impl.hpp * * Created on: Aug 25, 2010 * Author: heber */ /** These macros define the following functions, necessary but repetitive for * every Action: * -# Dialog* fillDialog() * -# action command (e.g. AnalysisMolecularVolume() ) * -# void getParametersfromValuStorage() * -# struct Action...Parameters * * For this, the user has the define the following values, each with * parenthesis: * -# types, e.g. (int)(double) * -# tokens, e.g. ("Z")("length") * -# references, e.g. (Z)(length) * and * -# CATEGORY, e.g. Analysis * -# ACTIONNAME, e.g. MolecularVolume */ #include #include #include #include #include #include #include #include #include #include #include #include #include // some derived names #define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action)) #define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME) #define STATE BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, State)) #define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters)) #define PARAMSDOT BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters)) // check if no lists given #ifndef types #define MAXNOTOKENS 0 #else #define MAXNOTOKENS BOOST_PP_SEQ_SIZE(types) #endif // check user has given name and category #ifndef CATEGORY ERROR: No "CATEGORY" defined in: __FILE__ #endif #ifndef ACTIONNAME ERROR: No "ACTIONNAME" defined in: __FILE__ #endif // calculate numbers and check whether all have same size #ifdef tokens BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXNOTOKENS, BOOST_PP_SEQ_SIZE(tokens)),\ ERROR: There are not the same number of "tokens" and "types" in: __FILE__ \ ) #endif #ifdef references BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXNOTOKENS, BOOST_PP_SEQ_SIZE(references)),\ ERROR: There are not the same number of "tokens" and "references" in: __FILE__ \ ) #endif // print a list of type ref followed by a separator, i.e. "int i;" #define type_print(z,n,separator) \ BOOST_PP_SEQ_ELEM(n, types) \ BOOST_PP_SEQ_ELEM(n, references)\ separator // print a list of type ref followed, i.e. "int i, double position" #define type_list(z,n,unused) \ BOOST_PP_COMMA_IF(n)\ BOOST_PP_SEQ_ELEM(n, types) \ BOOST_PP_SEQ_ELEM(n, references) // prints dialog->query calls for types with tokens #define dialog_print(z,n,unused) \ dialog->query<\ BOOST_PP_SEQ_ELEM(n, types)\ >(\ BOOST_PP_SEQ_ELEM(n, tokens)\ , ValueStorage::getInstance().getDescription(\ BOOST_PP_SEQ_ELEM(n, tokens)\ )); // prints set/queryCurrentValue (command) for paramreferences and paramtokens #define value_print(z,n,command, prefix) \ ValueStorage::getInstance(). command (\ BOOST_PP_SEQ_ELEM(n, tokens)\ , \ prefix\ BOOST_PP_SEQ_ELEM(n, references)\ ); #if BOOST_PP_NOT_EQUAL(MAXNOTOKENS,0) #define COMMANDFULL \ void COMMAND( \ BOOST_PP_REPEAT(MAXNOTOKENS, type_list, ~) \ ) # else #define COMMANDFULL void COMMAND() #endif #include "Actions/ActionRegistry.hpp" #include "UIElements/Dialog.hpp" #include "Actions/ValueStorage.hpp" const char ACTION::NAME[] = TOKEN; // the actual functions constructed ACTION::ACTION () : Action(NAME) {} ACTION::~ACTION () {} Dialog* ACTION::fillDialog(Dialog *dialog) { ASSERT(dialog,"No Dialog given when filling actionname's dialog"); #if BOOST_PP_EQUAL(MAXNOTOKENS,0) dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME)); #else #define BOOST_PP_LOCAL_MACRO(n) dialog_print(~, n, ~) #define BOOST_PP_LOCAL_LIMITS (0, MAXNOTOKENS-1) #include BOOST_PP_LOCAL_ITERATE() #undef BOOST_PP_LOCAL_MACRO #undef BOOST_PP_LOCAL_LIMITS #endif return dialog; }; COMMANDFULL { ACTION::PARAMS params; Action *ToCall = ActionRegistry::getInstance().getActionByName( ACTION::NAME ); //->clone(params); #if BOOST_PP_NOT_EQUAL(MAXNOTOKENS,0) #define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, setCurrentValue, ) #define BOOST_PP_LOCAL_LIMITS (0, MAXNOTOKENS-1) #include BOOST_PP_LOCAL_ITERATE() #undef BOOST_PP_LOCAL_MACRO #undef BOOST_PP_LOCAL_LIMITS #endif ToCall->call(Action::NonInteractive); }; void ACTION::getParametersfromValueStorage() { #if BOOST_PP_NOT_EQUAL(MAXNOTOKENS,0) #define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, queryCurrentValue, params.) #define BOOST_PP_LOCAL_LIMITS (0, MAXNOTOKENS-1) #include BOOST_PP_LOCAL_ITERATE() #undef BOOST_PP_LOCAL_MACRO #undef BOOST_PP_LOCAL_LIMITS #endif }; #undef types #undef tokens #undef references #undef MAXNOTOKENS #undef ACTION #undef ACTIONNAME #undef CATEGORY #undef COMMAND #undef COMMANDFULL #undef PARAMS #undef STATE #undef TOKEN