/* * Action_impl_header.hpp * * Created on: Aug 25, 2010 * Author: heber */ #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 references and tokens #define value_print(z,n,command) \ ValueStorage::getInstance(). command (\ BOOST_PP_SEQ_ELEM(n, tokens)\ , \ params.\ 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 COMMANDFULL; class ACTION : public Action { friend COMMANDFULL; public: ACTION(); virtual ~ACTION(); bool canUndo(); bool shouldUndo(); virtual const std::string getName(); struct PARAMS : ActionParameters { #if BOOST_PP_NOT_EQUAL(MAXNOTOKENS,0) #define BOOST_PP_LOCAL_MACRO(n) type_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 } params; protected: virtual Dialog * fillDialog(Dialog*); private: virtual void getParametersfromValueStorage(); virtual Action::state_ptr performCall(); virtual Action::state_ptr performUndo(Action::state_ptr); virtual Action::state_ptr performRedo(Action::state_ptr); static const char NAME[]; }; #undef types #undef tokens #undef references #undef MAXNOTOKENS #undef ACTION #undef ACTIONNAME #undef CATEGORY #undef COMMAND #undef COMMANDFULL #undef PARAMS #undef STATE #undef TOKEN