| [0b2ce9] | 1 | /* | 
|---|
|  | 2 | * Action_impl.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Aug 25, 2010 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | /** These macros define the following functions, necessary but repetitive for | 
|---|
|  | 9 | * every Action: | 
|---|
|  | 10 | *  -# Dialog* fillDialog() | 
|---|
|  | 11 | *  -# action command (e.g. AnalysisMolecularVolume() ) | 
|---|
|  | 12 | *  -# void getParametersfromValuStorage() | 
|---|
|  | 13 | *  -# struct Action...Parameters | 
|---|
|  | 14 | * | 
|---|
|  | 15 | *  For this, the user has the define the following values, each with | 
|---|
| [b4fa106] | 16 | *  parenthesis, for the values/parameters the action needs | 
|---|
|  | 17 | *  -# paramtypes, e.g. (int)(double) | 
|---|
|  | 18 | *  -# paramtokens, e.g. ("Z")("length") | 
|---|
|  | 19 | *  -# paramreferences, e.g. (Z)(length) | 
|---|
|  | 20 | *  and for additional values/parameters to save in the state | 
|---|
|  | 21 | *  -# statetypes, e.g. (int)(double) | 
|---|
|  | 22 | *  -# statereferences, e.g. (Z)(length) | 
|---|
|  | 23 | *  and the name and category of the action | 
|---|
| [0b2ce9] | 24 | *  -# CATEGORY, e.g. Analysis | 
|---|
|  | 25 | *  -# ACTIONNAME, e.g. MolecularVolume | 
|---|
|  | 26 | */ | 
|---|
|  | 27 |  | 
|---|
| [56f73b] | 28 | // include config.h | 
|---|
|  | 29 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 30 | #include <config.h> | 
|---|
|  | 31 | #endif | 
|---|
| [9ee38b] | 32 |  | 
|---|
|  | 33 | #include <boost/preprocessor/cat.hpp> | 
|---|
| [b4fa106] | 34 | #include <boost/preprocessor/expand.hpp> | 
|---|
| [9ee38b] | 35 | #include <boost/preprocessor/comparison/equal.hpp> | 
|---|
|  | 36 | #include <boost/preprocessor/comparison/not_equal.hpp> | 
|---|
|  | 37 | #include <boost/preprocessor/control/if.hpp> | 
|---|
|  | 38 | #include <boost/preprocessor/debug/assert.hpp> | 
|---|
|  | 39 | #include <boost/preprocessor/iteration/local.hpp> | 
|---|
|  | 40 | #include <boost/preprocessor/punctuation/comma_if.hpp> | 
|---|
|  | 41 | #include <boost/preprocessor/repetition/repeat.hpp> | 
|---|
|  | 42 | #include <boost/preprocessor/seq/elem.hpp> | 
|---|
|  | 43 | #include <boost/preprocessor/seq/push_back.hpp> | 
|---|
|  | 44 | #include <boost/preprocessor/seq/seq.hpp> | 
|---|
|  | 45 | #include <boost/preprocessor/seq/size.hpp> | 
|---|
|  | 46 | #include <boost/preprocessor/seq/transform.hpp> | 
|---|
|  | 47 |  | 
|---|
| [e4afb4] | 48 | // some derived names: if CATEGORY is not given, we don't prefix with it | 
|---|
|  | 49 | #ifdef CATEGORY | 
|---|
| [9ee38b] | 50 | #define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action)) | 
|---|
|  | 51 | #define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME) | 
|---|
|  | 52 | #define STATE BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, State)) | 
|---|
|  | 53 | #define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters)) | 
|---|
| [e4afb4] | 54 | #else | 
|---|
|  | 55 | #define ACTION BOOST_PP_CAT(ACTIONNAME, Action) | 
|---|
|  | 56 | #define COMMAND ACTIONNAME | 
|---|
|  | 57 | #define STATE BOOST_PP_CAT(ACTIONNAME, State) | 
|---|
|  | 58 | #define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters) | 
|---|
|  | 59 | #endif | 
|---|
| [2a6a2c] | 60 | #define INSTANCE BOOST_PP_CAT(this_, BOOST_PP_CAT(ACTIONNAME, _instance)) | 
|---|
| [9ee38b] | 61 |  | 
|---|
|  | 62 | // check if no lists given | 
|---|
| [b4fa106] | 63 | #ifndef paramtypes | 
|---|
|  | 64 | #define MAXPARAMTYPES 0 | 
|---|
| [9ee38b] | 65 | #else | 
|---|
| [b4fa106] | 66 | #define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes) | 
|---|
|  | 67 | #endif | 
|---|
|  | 68 | #ifndef statetypes | 
|---|
|  | 69 | #define MAXSTATETYPES 0 | 
|---|
|  | 70 | #else | 
|---|
|  | 71 | #define MAXSTATETYPES BOOST_PP_SEQ_SIZE(statetypes) | 
|---|
| [9ee38b] | 72 | #endif | 
|---|
|  | 73 |  | 
|---|
|  | 74 | // check user has given name and category | 
|---|
|  | 75 | #ifndef ACTIONNAME | 
|---|
|  | 76 | ERROR: No "ACTIONNAME" defined in: __FILE__ | 
|---|
|  | 77 | #endif | 
|---|
|  | 78 |  | 
|---|
|  | 79 | // calculate numbers and check whether all have same size | 
|---|
| [b4fa106] | 80 | #ifdef paramtokens | 
|---|
|  | 81 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\ | 
|---|
|  | 82 | ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \ | 
|---|
| [9ee38b] | 83 | ) | 
|---|
|  | 84 | #endif | 
|---|
| [b4fa106] | 85 | #ifdef paramreferences | 
|---|
|  | 86 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\ | 
|---|
|  | 87 | ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \ | 
|---|
|  | 88 | ) | 
|---|
|  | 89 | #endif | 
|---|
|  | 90 |  | 
|---|
|  | 91 | #ifdef statetypes | 
|---|
|  | 92 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXSTATETYPES, BOOST_PP_SEQ_SIZE(statereferences)),\ | 
|---|
|  | 93 | ERROR: There are not the same number of "statetypes" and "statereferences" in: __FILE__ \ | 
|---|
| [9ee38b] | 94 | ) | 
|---|
|  | 95 | #endif | 
|---|
|  | 96 |  | 
|---|
|  | 97 | // print a list of type ref followed by a separator, i.e. "int i;" | 
|---|
| [b4fa106] | 98 | #define initialiser_print(z,n,initialiserlist) \ | 
|---|
|  | 99 | BOOST_PP_SEQ_ELEM(n, initialiserlist) \ | 
|---|
|  | 100 | (BOOST_PP_CAT(_, BOOST_PP_SEQ_ELEM(n, initialiserlist))), | 
|---|
|  | 101 |  | 
|---|
|  | 102 | // print a list of ref(_ref) followed by a separator, i.e. "id(_id)," | 
|---|
|  | 103 | #define type_print(z,n,TYPELIST, VARLIST, separator) \ | 
|---|
|  | 104 | BOOST_PP_SEQ_ELEM(n, TYPELIST) \ | 
|---|
|  | 105 | BOOST_PP_SEQ_ELEM(n, VARLIST)\ | 
|---|
| [9ee38b] | 106 | separator | 
|---|
|  | 107 |  | 
|---|
|  | 108 | // print a list of type ref followed, i.e. "int i, double position" | 
|---|
| [b4fa106] | 109 | #define type_list(z,n,TYPELIST,VARLIST) \ | 
|---|
| [9ee38b] | 110 | BOOST_PP_COMMA_IF(n)\ | 
|---|
| [b4fa106] | 111 | BOOST_PP_SEQ_ELEM(n, TYPELIST) \ | 
|---|
|  | 112 | BOOST_PP_SEQ_ELEM(n, VARLIST) | 
|---|
| [9ee38b] | 113 |  | 
|---|
| [b4fa106] | 114 | // prints dialog->query calls for paramtypes with tokens | 
|---|
| [9ee38b] | 115 | #define dialog_print(z,n,unused) \ | 
|---|
|  | 116 | dialog->query<\ | 
|---|
| [b4fa106] | 117 | BOOST_PP_SEQ_ELEM(n, paramtypes)\ | 
|---|
| [9ee38b] | 118 | >(\ | 
|---|
| [b4fa106] | 119 | BOOST_PP_SEQ_ELEM(n, paramtokens)\ | 
|---|
| [e4afb4] | 120 | , Traits.getDescription()\ | 
|---|
|  | 121 | ); | 
|---|
| [9ee38b] | 122 |  | 
|---|
|  | 123 | // prints set/queryCurrentValue (command) for paramreferences and paramtokens | 
|---|
|  | 124 | #define value_print(z,n,command, prefix) \ | 
|---|
|  | 125 | ValueStorage::getInstance(). command (\ | 
|---|
| [b4fa106] | 126 | BOOST_PP_SEQ_ELEM(n, paramtokens)\ | 
|---|
| [9ee38b] | 127 | , \ | 
|---|
|  | 128 | prefix\ | 
|---|
| [b4fa106] | 129 | BOOST_PP_SEQ_ELEM(n, paramreferences)\ | 
|---|
| [9ee38b] | 130 | ); | 
|---|
|  | 131 |  | 
|---|
| [0b2ce9] | 132 | #include "Actions/ActionRegistry.hpp" | 
|---|
|  | 133 | #include "UIElements/Dialog.hpp" | 
|---|
|  | 134 |  | 
|---|
| [e4afb4] | 135 | #ifdef paramtokens | 
|---|
|  | 136 | #define statenecessary 1 | 
|---|
|  | 137 | #endif | 
|---|
|  | 138 | #ifndef statetokens | 
|---|
|  | 139 | #define statenecessary 1 | 
|---|
|  | 140 | #endif | 
|---|
| [9ee38b] | 141 |  | 
|---|
| [b4fa106] | 142 | // =========== memento to remember the state when undoing =========== | 
|---|
| [e4afb4] | 143 | #ifdef statenecessary | 
|---|
| [b4fa106] | 144 | class STATE : public ActionState { | 
|---|
|  | 145 | public: | 
|---|
|  | 146 | STATE( | 
|---|
|  | 147 | #if defined statetypes && defined statereferences // if we have parameters, we have to add "_" before each reference and add the params as the last one | 
|---|
|  | 148 | #define OP(s,data,elem) BOOST_PP_CAT(data, elem)  // OP to add "_" | 
|---|
|  | 149 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_PUSH_BACK(statetypes, const ACTION::PARAMS &), BOOST_PP_SEQ_TRANSFORM(OP, _, BOOST_PP_SEQ_PUSH_BACK(statereferences, params))) | 
|---|
|  | 150 | #else /// if not, params is only list | 
|---|
|  | 151 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, (const ACTION::PARAMS &), (_params)) | 
|---|
|  | 152 | #endif | 
|---|
|  | 153 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXSTATETYPES) | 
|---|
|  | 154 | #include BOOST_PP_LOCAL_ITERATE() | 
|---|
|  | 155 | ) : | 
|---|
|  | 156 | #if defined statetypes && defined statereferences // do we have parameters at all? | 
|---|
|  | 157 | BOOST_PP_REPEAT(MAXSTATETYPES, initialiser_print, statereferences) | 
|---|
|  | 158 | #endif | 
|---|
|  | 159 | params(_params) | 
|---|
|  | 160 | {} | 
|---|
| [0b2ce9] | 161 |  | 
|---|
| [b4fa106] | 162 | #if defined statetypes && defined statereferences // do we have parameters at all? | 
|---|
|  | 163 | #define BOOST_PP_LOCAL_MACRO(n) type_print(~, n, statetypes, statereferences, ;) | 
|---|
|  | 164 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXSTATETYPES-1) | 
|---|
|  | 165 | #include BOOST_PP_LOCAL_ITERATE() | 
|---|
|  | 166 | #endif | 
|---|
|  | 167 | ACTION::PARAMS params; | 
|---|
|  | 168 | }; | 
|---|
| [e4afb4] | 169 | #endif /* statenecessary */ | 
|---|
| [0b2ce9] | 170 |  | 
|---|
| [2a6a2c] | 171 | // (const) prototype to be placed into the ActionRegistry (must be deleted by registry itself) | 
|---|
| [95c0ab] | 172 | const ACTION *INSTANCE = new ACTION(); | 
|---|
| [2a6a2c] | 173 |  | 
|---|
| [b4fa106] | 174 | // =========== constructor =========== | 
|---|
| [0b2ce9] | 175 | ACTION::ACTION () : | 
|---|
| [e4afb4] | 176 | Action(ActionTrait<ACTION>()) | 
|---|
| [0b2ce9] | 177 | {} | 
|---|
|  | 178 |  | 
|---|
| [b4fa106] | 179 | // =========== destructor =========== | 
|---|
| [0b2ce9] | 180 | ACTION::~ACTION () | 
|---|
| [e4afb4] | 181 | { | 
|---|
|  | 182 | //std::cout << "Action ACTION is being destroyed." << std::endl; | 
|---|
|  | 183 | } | 
|---|
| [0b2ce9] | 184 |  | 
|---|
| [b4fa106] | 185 | // =========== fill a dialog =========== | 
|---|
| [0b2ce9] | 186 | Dialog* ACTION::fillDialog(Dialog *dialog) { | 
|---|
|  | 187 | ASSERT(dialog,"No Dialog given when filling actionname's dialog"); | 
|---|
| [b4fa106] | 188 | #if BOOST_PP_EQUAL(MAXPARAMTYPES,0) | 
|---|
| [e4afb4] | 189 | dialog->queryEmpty(TOKEN, Traits.getDescription()); | 
|---|
| [0b2ce9] | 190 | #else | 
|---|
|  | 191 | #define BOOST_PP_LOCAL_MACRO(n) dialog_print(~, n, ~) | 
|---|
| [b4fa106] | 192 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1) | 
|---|
| [0b2ce9] | 193 | #include BOOST_PP_LOCAL_ITERATE() | 
|---|
|  | 194 | #endif | 
|---|
|  | 195 | return dialog; | 
|---|
|  | 196 | }; | 
|---|
|  | 197 |  | 
|---|
| [b4fa106] | 198 | // =========== command for calling action directly =========== | 
|---|
|  | 199 | #if defined paramtypes && defined paramreferences | 
|---|
|  | 200 | void COMMAND( | 
|---|
|  | 201 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences) | 
|---|
|  | 202 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1) | 
|---|
|  | 203 | #include BOOST_PP_LOCAL_ITERATE() | 
|---|
|  | 204 | ) | 
|---|
|  | 205 | #else | 
|---|
|  | 206 | void COMMAND() | 
|---|
|  | 207 | #endif | 
|---|
| [0b2ce9] | 208 | { | 
|---|
| [9ee38b] | 209 | ACTION::PARAMS params; | 
|---|
| [e4afb4] | 210 | Action *ToCall = ActionRegistry::getInstance().getActionByName( TOKEN ); //->clone(params); | 
|---|
| [b4fa106] | 211 | #if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0) | 
|---|
| [9ee38b] | 212 | #define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, setCurrentValue, ) | 
|---|
| [b4fa106] | 213 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1) | 
|---|
| [0b2ce9] | 214 | #include BOOST_PP_LOCAL_ITERATE() | 
|---|
|  | 215 | #endif | 
|---|
| [9ee38b] | 216 | ToCall->call(Action::NonInteractive); | 
|---|
| [0b2ce9] | 217 | }; | 
|---|
|  | 218 |  | 
|---|
| [b4fa106] | 219 | // =========== obtain parameters from Storage, used by performCall() =========== | 
|---|
| [9ee38b] | 220 | void ACTION::getParametersfromValueStorage() { | 
|---|
| [b4fa106] | 221 | #if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0) | 
|---|
| [9ee38b] | 222 | #define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, queryCurrentValue, params.) | 
|---|
| [b4fa106] | 223 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1) | 
|---|
| [0b2ce9] | 224 | #include BOOST_PP_LOCAL_ITERATE() | 
|---|
|  | 225 | #endif | 
|---|
|  | 226 | }; | 
|---|
|  | 227 |  | 
|---|
| [b4fa106] | 228 | // free up defines | 
|---|
|  | 229 | #undef paramtypes | 
|---|
|  | 230 | #undef paramtokens | 
|---|
|  | 231 | #undef paramreferences | 
|---|
|  | 232 | #undef MAXPARAMTYPES | 
|---|
|  | 233 | #undef statetypes | 
|---|
|  | 234 | #undef statereferences | 
|---|
|  | 235 | #undef MAXSTATETYPES | 
|---|
| [0b2ce9] | 236 |  | 
|---|
| [9ee38b] | 237 | #undef ACTION | 
|---|
|  | 238 | #undef COMMAND | 
|---|
|  | 239 | #undef PARAMS | 
|---|
|  | 240 | #undef STATE | 
|---|
| [2a6a2c] | 241 | #undef INSTANCE | 
|---|
| [b4fa106] | 242 |  | 
|---|
|  | 243 | #undef ACTIONNAME | 
|---|
|  | 244 | #undef CATEGORY | 
|---|
| [9ee38b] | 245 | #undef TOKEN | 
|---|