| 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
 | 
|---|
| 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
 | 
|---|
| 24 |  *  -# CATEGORY, e.g. Analysis
 | 
|---|
| 25 |  *  -# ACTIONNAME, e.g. MolecularVolume
 | 
|---|
| 26 |  */
 | 
|---|
| 27 | 
 | 
|---|
| 28 | // include config.h
 | 
|---|
| 29 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 30 | #include <config.h>
 | 
|---|
| 31 | #endif
 | 
|---|
| 32 | 
 | 
|---|
| 33 | #include "CodePatterns/Chronos.hpp"
 | 
|---|
| 34 | 
 | 
|---|
| 35 | #include <boost/preprocessor/cat.hpp>
 | 
|---|
| 36 | #include <boost/preprocessor/expand.hpp>
 | 
|---|
| 37 | #include <boost/preprocessor/comparison/equal.hpp>
 | 
|---|
| 38 | #include <boost/preprocessor/comparison/not_equal.hpp>
 | 
|---|
| 39 | #include <boost/preprocessor/control/expr_if.hpp>
 | 
|---|
| 40 | #include <boost/preprocessor/control/if.hpp>
 | 
|---|
| 41 | #include <boost/preprocessor/debug/assert.hpp>
 | 
|---|
| 42 | #include <boost/preprocessor/iteration/local.hpp>
 | 
|---|
| 43 | #include <boost/preprocessor/list/adt.hpp>
 | 
|---|
| 44 | #include <boost/preprocessor/punctuation/comma_if.hpp>
 | 
|---|
| 45 | #include <boost/preprocessor/repetition/repeat.hpp>
 | 
|---|
| 46 | #include <boost/preprocessor/seq/elem.hpp>
 | 
|---|
| 47 | #include <boost/preprocessor/seq/push_back.hpp>
 | 
|---|
| 48 | #include <boost/preprocessor/seq/seq.hpp>
 | 
|---|
| 49 | #include <boost/preprocessor/seq/size.hpp>
 | 
|---|
| 50 | #include <boost/preprocessor/seq/transform.hpp>
 | 
|---|
| 51 | 
 | 
|---|
| 52 | #include "Actions/ActionQueue.hpp"
 | 
|---|
| 53 | #include "Actions/toCLIString.hpp"
 | 
|---|
| 54 | #include "Actions/toPythonString.hpp"
 | 
|---|
| 55 | #include "Parameters/Parameter.hpp"
 | 
|---|
| 56 | 
 | 
|---|
| 57 | 
 | 
|---|
| 58 | // some derived names: if CATEGORY is not given, we don't prefix with it
 | 
|---|
| 59 | #ifdef CATEGORY
 | 
|---|
| 60 | #define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
 | 
|---|
| 61 | #define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
 | 
|---|
| 62 | #define STATE BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, State))
 | 
|---|
| 63 | #define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
 | 
|---|
| 64 | #else
 | 
|---|
| 65 | #define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
 | 
|---|
| 66 | #define COMMAND ACTIONNAME
 | 
|---|
| 67 | #define STATE BOOST_PP_CAT(ACTIONNAME, State)
 | 
|---|
| 68 | #define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
 | 
|---|
| 69 | #endif
 | 
|---|
| 70 | #define INSTANCE BOOST_PP_CAT(this_, BOOST_PP_CAT(ACTIONNAME, _instance))
 | 
|---|
| 71 | 
 | 
|---|
| 72 | // check if no lists given
 | 
|---|
| 73 | #ifndef paramtypes
 | 
|---|
| 74 | #define MAXPARAMTYPES 0
 | 
|---|
| 75 | #else
 | 
|---|
| 76 | #define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
 | 
|---|
| 77 | #endif
 | 
|---|
| 78 | #ifndef statetypes
 | 
|---|
| 79 | #define MAXSTATETYPES 0
 | 
|---|
| 80 | #else
 | 
|---|
| 81 | #define MAXSTATETYPES BOOST_PP_SEQ_SIZE(statetypes)
 | 
|---|
| 82 | #endif
 | 
|---|
| 83 | #ifndef paramdefaults
 | 
|---|
| 84 | #define MAXPARAMDEFAULTS 0
 | 
|---|
| 85 | // this is required for valid_print "else part"
 | 
|---|
| 86 | #define sequencer(z,n,data) \
 | 
|---|
| 87 |   BOOST_PP_SEQ_PUSH_BACK( data, NOPARAM_DEFAULT)
 | 
|---|
| 88 | #define paramdefaults BOOST_PP_REPEAT( MAXPARAMTYPES, sequencer, BOOST_PP_SEQ_NIL )
 | 
|---|
| 89 | #else
 | 
|---|
| 90 | #define MAXPARAMDEFAULTS BOOST_PP_SEQ_SIZE(paramdefaults)
 | 
|---|
| 91 | #endif
 | 
|---|
| 92 | #define PARAM_DEFAULT(x) \
 | 
|---|
| 93 |     (x, BOOST_PP_NIL)
 | 
|---|
| 94 | 
 | 
|---|
| 95 | // check user has given name and category
 | 
|---|
| 96 | #ifndef ACTIONNAME
 | 
|---|
| 97 | ERROR: No "ACTIONNAME" defined in: __FILE__
 | 
|---|
| 98 | #endif
 | 
|---|
| 99 | 
 | 
|---|
| 100 | // calculate numbers and check whether all have same size
 | 
|---|
| 101 | #ifdef paramtokens
 | 
|---|
| 102 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\
 | 
|---|
| 103 |   ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
 | 
|---|
| 104 | )
 | 
|---|
| 105 | #endif
 | 
|---|
| 106 | #ifdef paramreferences
 | 
|---|
| 107 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
 | 
|---|
| 108 |   ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
 | 
|---|
| 109 | )
 | 
|---|
| 110 | #endif
 | 
|---|
| 111 | 
 | 
|---|
| 112 | #ifdef statetypes
 | 
|---|
| 113 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXSTATETYPES, BOOST_PP_SEQ_SIZE(statereferences)),\
 | 
|---|
| 114 |   ERROR: There are not the same number of "statetypes" and "statereferences" in: __FILE__ \
 | 
|---|
| 115 | )
 | 
|---|
| 116 | #endif
 | 
|---|
| 117 | 
 | 
|---|
| 118 | // print a list of type ref followed by a separator, i.e. "int i;"
 | 
|---|
| 119 | #define initialiser_print(z,n,initialiserlist) \
 | 
|---|
| 120 |   BOOST_PP_SEQ_ELEM(n, initialiserlist) \
 | 
|---|
| 121 |   (BOOST_PP_CAT(_, BOOST_PP_SEQ_ELEM(n, initialiserlist))),
 | 
|---|
| 122 | 
 | 
|---|
| 123 | // print a list of ref(_ref) followed by a separator, i.e. "id(_id),"
 | 
|---|
| 124 | #define type_print(z,n,TYPELIST, VARLIST, separator) \
 | 
|---|
| 125 |   BOOST_PP_SEQ_ELEM(n, TYPELIST) \
 | 
|---|
| 126 |   BOOST_PP_SEQ_ELEM(n, VARLIST)\
 | 
|---|
| 127 |   separator
 | 
|---|
| 128 | 
 | 
|---|
| 129 | // print a list of type ref followed, i.e. "int i, double position"
 | 
|---|
| 130 | #define type_list(z,n,TYPELIST,VARLIST) \
 | 
|---|
| 131 |   BOOST_PP_COMMA_IF(n)\
 | 
|---|
| 132 |   BOOST_PP_SEQ_ELEM(n, TYPELIST) \
 | 
|---|
| 133 |   BOOST_PP_SEQ_ELEM(n, VARLIST)
 | 
|---|
| 134 | 
 | 
|---|
| 135 | // prints dialog->query calls for paramtypes with tokens
 | 
|---|
| 136 | #define dialog_print(z,n,unused) \
 | 
|---|
| 137 |   dialog->query<\
 | 
|---|
| 138 |   BOOST_PP_SEQ_ELEM(n, paramtypes)\
 | 
|---|
| 139 |   >( params. \
 | 
|---|
| 140 |   BOOST_PP_SEQ_ELEM(n, paramreferences)\
 | 
|---|
| 141 |   ,\
 | 
|---|
| 142 |   BOOST_PP_SEQ_ELEM(n, paramtokens)\
 | 
|---|
| 143 |   , Traits.getDescription()\
 | 
|---|
| 144 |   );
 | 
|---|
| 145 | 
 | 
|---|
| 146 | // prints command line call for this Action for paramtypes with tokens
 | 
|---|
| 147 | #define outputAsCLI_print(z,n,output) \
 | 
|---|
| 148 |     output << \
 | 
|---|
| 149 |     BOOST_PP_IF(n, " --", "--") \
 | 
|---|
| 150 |     << \
 | 
|---|
| 151 |     BOOST_PP_SEQ_ELEM(n, paramtokens) \
 | 
|---|
| 152 |     << " " << toCLIString(params. \
 | 
|---|
| 153 |         BOOST_PP_SEQ_ELEM(n, paramreferences) \
 | 
|---|
| 154 |         .get());
 | 
|---|
| 155 | 
 | 
|---|
| 156 | // prints if statement to check two strings (paramtokens[n] vs. TOKEN)
 | 
|---|
| 157 | #define checkpresenttoken_print(z, n, TOKEN, booltoken) \
 | 
|---|
| 158 |     if ( std::string(\
 | 
|---|
| 159 |         BOOST_PP_SEQ_ELEM(n, paramtokens) )\
 | 
|---|
| 160 |         == getName()) \
 | 
|---|
| 161 |         booltoken = false;
 | 
|---|
| 162 | 
 | 
|---|
| 163 | // prints command line call for this Action for paramtypes with tokens
 | 
|---|
| 164 | #define outputAsPython_print(z,n,output) \
 | 
|---|
| 165 |     output << \
 | 
|---|
| 166 |     BOOST_PP_IF(n, ", ", "") \
 | 
|---|
| 167 |     << "\"" << toPythonString(params. \
 | 
|---|
| 168 |         BOOST_PP_SEQ_ELEM(n, paramreferences) \
 | 
|---|
| 169 |         .get()) \
 | 
|---|
| 170 |     << "\"";
 | 
|---|
| 171 | 
 | 
|---|
| 172 | // print an initialiser list, i.e. "var( token, valid (,default) )(,)"
 | 
|---|
| 173 | #define valid_print(z,n,TOKENLIST, VARLIST, VALIDLIST, DEFAULTLIST) \
 | 
|---|
| 174 |   BOOST_PP_COMMA_IF(n) \
 | 
|---|
| 175 |   BOOST_PP_SEQ_ELEM(n, VARLIST) \
 | 
|---|
| 176 |   ( \
 | 
|---|
| 177 |   BOOST_PP_SEQ_ELEM(n, TOKENLIST) \
 | 
|---|
| 178 |   , \
 | 
|---|
| 179 |   BOOST_PP_SEQ_ELEM(n, VALIDLIST) \
 | 
|---|
| 180 |   BOOST_PP_COMMA_IF( BOOST_PP_NOT( BOOST_PP_LIST_IS_NIL( BOOST_PP_SEQ_ELEM(n, DEFAULTLIST) ) ) ) \
 | 
|---|
| 181 |   BOOST_PP_EXPR_IF( \
 | 
|---|
| 182 |       BOOST_PP_NOT( BOOST_PP_LIST_IS_NIL( BOOST_PP_SEQ_ELEM(n, DEFAULTLIST) ) ), \
 | 
|---|
| 183 |       BOOST_PP_LIST_FIRST( BOOST_PP_SEQ_ELEM(n, DEFAULTLIST) )) \
 | 
|---|
| 184 |   )
 | 
|---|
| 185 | 
 | 
|---|
| 186 | // print an initialiser list, i.e. "var( valid . var )(,)"
 | 
|---|
| 187 | #define validcopy_print(z,n,TOKENLIST, VARLIST, VALID) \
 | 
|---|
| 188 |   BOOST_PP_COMMA_IF(n) \
 | 
|---|
| 189 |   BOOST_PP_SEQ_ELEM(n, VARLIST) \
 | 
|---|
| 190 |   ( \
 | 
|---|
| 191 |   VALID . \
 | 
|---|
| 192 |   BOOST_PP_SEQ_ELEM(n, VARLIST) \
 | 
|---|
| 193 |   )
 | 
|---|
| 194 | 
 | 
|---|
| 195 | // prints set/queryCurrentValue (command) for paramreferences and paramtokens
 | 
|---|
| 196 | #define value_print(z, n, container, prefix) \
 | 
|---|
| 197 |   prefix \
 | 
|---|
| 198 |   BOOST_PP_SEQ_ELEM(n, container)\
 | 
|---|
| 199 |   .set(\
 | 
|---|
| 200 |   BOOST_PP_SEQ_ELEM(n, container)\
 | 
|---|
| 201 |   );
 | 
|---|
| 202 | 
 | 
|---|
| 203 | // prints set/queryCurrentValue (command) for paramreferences and paramtokens
 | 
|---|
| 204 | #define valuetype_print(z,n,container, types, prefix) \
 | 
|---|
| 205 |   prefix \
 | 
|---|
| 206 |   BOOST_PP_SEQ_ELEM(n, container) \
 | 
|---|
| 207 |   .setAsString( \
 | 
|---|
| 208 |   BOOST_PP_SEQ_ELEM(n, container) \
 | 
|---|
| 209 |   );
 | 
|---|
| 210 | 
 | 
|---|
| 211 | #define stringtype std::string
 | 
|---|
| 212 | 
 | 
|---|
| 213 | #define type2string(s, data, elem) \
 | 
|---|
| 214 |         stringtype
 | 
|---|
| 215 | 
 | 
|---|
| 216 | 
 | 
|---|
| 217 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| 218 | //#include "Actions/ActionTraits.hpp"
 | 
|---|
| 219 | #include "UIElements/Dialog.hpp"
 | 
|---|
| 220 | 
 | 
|---|
| 221 | #ifdef paramtokens
 | 
|---|
| 222 | #define statenecessary 1
 | 
|---|
| 223 | #endif
 | 
|---|
| 224 | #ifndef statetokens
 | 
|---|
| 225 | #define statenecessary 1
 | 
|---|
| 226 | #endif
 | 
|---|
| 227 | 
 | 
|---|
| 228 | namespace MoleCuilder {
 | 
|---|
| 229 | 
 | 
|---|
| 230 | // =========== memento to remember the state when undoing ===========
 | 
|---|
| 231 | #ifdef statenecessary
 | 
|---|
| 232 | class STATE : public ActionState {
 | 
|---|
| 233 | public:
 | 
|---|
| 234 |   STATE(
 | 
|---|
| 235 | #if defined statetypes && defined statereferences // if we have states, we have to add "_" before each reference and add the params as the last one
 | 
|---|
| 236 | #define OP(s,data,elem) BOOST_PP_CAT(data, elem)  // OP to add "_"
 | 
|---|
| 237 | #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)))
 | 
|---|
| 238 | #else /// if not, params is only list
 | 
|---|
| 239 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, (const ACTION::PARAMS &), (_params))
 | 
|---|
| 240 | #endif
 | 
|---|
| 241 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXSTATETYPES)
 | 
|---|
| 242 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 243 | ) :
 | 
|---|
| 244 | #if defined statetypes && defined statereferences // do we have states at all?
 | 
|---|
| 245 | BOOST_PP_REPEAT(MAXSTATETYPES, initialiser_print, statereferences)
 | 
|---|
| 246 | #endif
 | 
|---|
| 247 | params(_params)
 | 
|---|
| 248 |   {}
 | 
|---|
| 249 | 
 | 
|---|
| 250 | #if defined statetypes && defined statereferences // do we have parameters at all?
 | 
|---|
| 251 | #define BOOST_PP_LOCAL_MACRO(n) type_print(~, n, statetypes, statereferences, ;)
 | 
|---|
| 252 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXSTATETYPES-1)
 | 
|---|
| 253 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 254 | #endif
 | 
|---|
| 255 |   ACTION::PARAMS params;
 | 
|---|
| 256 | };
 | 
|---|
| 257 | #endif /* statenecessary */
 | 
|---|
| 258 | 
 | 
|---|
| 259 | // (const) prototype to be placed into the ActionRegistry (must be deleted by registry itself)
 | 
|---|
| 260 | //const ACTION INSTANCE;
 | 
|---|
| 261 | //boost::shared_ptr< ACTION > INSTANCE( new ACTION() );
 | 
|---|
| 262 | 
 | 
|---|
| 263 | // =========== constructor ===========
 | 
|---|
| 264 | ACTION::ACTION () :
 | 
|---|
| 265 |   MakroAction(ActionTraits< ACTION >(), actions)
 | 
|---|
| 266 | {}
 | 
|---|
| 267 | 
 | 
|---|
| 268 | // =========== destructor ===========
 | 
|---|
| 269 | ACTION::~ACTION ()
 | 
|---|
| 270 | {
 | 
|---|
| 271 |   //std::cout << "Action ACTION is being destroyed." << std::endl;
 | 
|---|
| 272 | }
 | 
|---|
| 273 | 
 | 
|---|
| 274 | // =========== parameter constructor ===========
 | 
|---|
| 275 | ACTION::PARAMS::PARAMS()
 | 
|---|
| 276 | #if defined paramtokens && defined paramreferences && defined paramvalids
 | 
|---|
| 277 |       :
 | 
|---|
| 278 | #define BOOST_PP_LOCAL_MACRO(n) valid_print(~, n, paramtokens, paramreferences, paramvalids, paramdefaults)
 | 
|---|
| 279 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 280 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 281 | #endif
 | 
|---|
| 282 |     {}
 | 
|---|
| 283 | 
 | 
|---|
| 284 | ACTION::PARAMS::PARAMS(const PARAMS &p)
 | 
|---|
| 285 | #if defined paramtokens && defined paramreferences
 | 
|---|
| 286 |       :
 | 
|---|
| 287 | #define BOOST_PP_LOCAL_MACRO(n) validcopy_print(~, n, paramtokens, paramreferences, p)
 | 
|---|
| 288 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 289 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 290 | #endif
 | 
|---|
| 291 |     {}
 | 
|---|
| 292 | 
 | 
|---|
| 293 | // =========== clone Action ===========
 | 
|---|
| 294 | Action* ACTION::clone(enum QueryOptions flag) const
 | 
|---|
| 295 | {
 | 
|---|
| 296 |   if (flag == Interactive)
 | 
|---|
| 297 |     return new ACTION();
 | 
|---|
| 298 |   else
 | 
|---|
| 299 |     return new ACTION(*this);
 | 
|---|
| 300 | }
 | 
|---|
| 301 | 
 | 
|---|
| 302 | // =========== fill a dialog ===========
 | 
|---|
| 303 | Dialog* ACTION::fillOwnDialog(Dialog *dialog) {
 | 
|---|
| 304 |         ASSERT(dialog,"No Dialog given when filling actionname's dialog");
 | 
|---|
| 305 | #if BOOST_PP_EQUAL(MAXPARAMTYPES,0)
 | 
|---|
| 306 |         dialog->queryEmpty(TOKEN, Traits.getDescription());
 | 
|---|
| 307 | #else
 | 
|---|
| 308 | #define BOOST_PP_LOCAL_MACRO(n) dialog_print(~, n, ~)
 | 
|---|
| 309 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 310 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 311 | #endif
 | 
|---|
| 312 |         return dialog;
 | 
|---|
| 313 | };
 | 
|---|
| 314 | 
 | 
|---|
| 315 | // =========== output as CLI ===========
 | 
|---|
| 316 | void ACTION::outputAsCLI(std::ostream &ost) const {
 | 
|---|
| 317 |   // check whether TOKEN is also an option
 | 
|---|
| 318 |   // is a bit ugly as preprocessor cannot compare strings
 | 
|---|
| 319 |   bool status = true;
 | 
|---|
| 320 | #if defined paramtokens && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
 | 
|---|
| 321 | #define BOOST_PP_LOCAL_MACRO(n) checkpresenttoken_print(~, n, TOKEN, status)
 | 
|---|
| 322 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 323 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 324 | #endif
 | 
|---|
| 325 |   if (status) {
 | 
|---|
| 326 |     ost << "--" << TOKEN;
 | 
|---|
| 327 | #if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
 | 
|---|
| 328 |     ost << " ";
 | 
|---|
| 329 | #endif
 | 
|---|
| 330 |   }
 | 
|---|
| 331 |   // then print option along with each argument if set
 | 
|---|
| 332 | #if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
 | 
|---|
| 333 | #define BOOST_PP_LOCAL_MACRO(n) outputAsCLI_print(~, n, ost)
 | 
|---|
| 334 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 335 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 336 | #endif
 | 
|---|
| 337 | }
 | 
|---|
| 338 | 
 | 
|---|
| 339 | // =========== output as PYTHTON ===========
 | 
|---|
| 340 | void ACTION::outputAsPython(std::ostream &ost, const std::string &prefix) const {
 | 
|---|
| 341 |   // print prefix and action command
 | 
|---|
| 342 |   ost << prefix << "." << BOOST_PP_STRINGIZE( COMMAND ) << "(";
 | 
|---|
| 343 |   // then print option along with each argument if set
 | 
|---|
| 344 | #if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
 | 
|---|
| 345 | #define BOOST_PP_LOCAL_MACRO(n) outputAsCLI_print(~, n, ost)
 | 
|---|
| 346 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 347 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 348 | #endif
 | 
|---|
| 349 |   ost << ")" << std::endl;
 | 
|---|
| 350 | }
 | 
|---|
| 351 | 
 | 
|---|
| 352 | // =========== time the action ===========
 | 
|---|
| 353 | // we need this here to have the correct function name
 | 
|---|
| 354 | void ACTION::startTimer() const { Chronos::getInstance().startTiming( std::string( TOKEN ) ); }
 | 
|---|
| 355 | void ACTION::endTimer() const { Chronos::getInstance().endTiming( std::string( TOKEN ) ); }
 | 
|---|
| 356 | 
 | 
|---|
| 357 | // =========== command for calling action directly ===========
 | 
|---|
| 358 | void COMMAND(
 | 
|---|
| 359 | #if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
 | 
|---|
| 360 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
 | 
|---|
| 361 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 362 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 363 | #endif
 | 
|---|
| 364 | )
 | 
|---|
| 365 | {
 | 
|---|
| 366 |   ACTION *ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN )); //->clone(params);
 | 
|---|
| 367 |   //ACTION::PARAMS params;
 | 
|---|
| 368 | #if defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
 | 
|---|
| 369 | #define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, paramreferences, ToCall->params.)
 | 
|---|
| 370 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 371 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 372 | #endif
 | 
|---|
| 373 |   Action::insertAction( ToCall, Action::NonInteractive);
 | 
|---|
| 374 | };
 | 
|---|
| 375 | 
 | 
|---|
| 376 | void BOOST_PP_CAT( COMMAND, _stringargs)(
 | 
|---|
| 377 | #if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
 | 
|---|
| 378 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
 | 
|---|
| 379 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 380 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 381 | #endif
 | 
|---|
| 382 |         ) {
 | 
|---|
| 383 |   ACTION *ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN )); //->clone(params);
 | 
|---|
| 384 |   //ACTION::PARAMS params;
 | 
|---|
| 385 | #if defined paramtypes && defined paramtypes && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
 | 
|---|
| 386 | #define BOOST_PP_LOCAL_MACRO(n) valuetype_print(~, n, paramreferences, paramtypes, ToCall->params. )
 | 
|---|
| 387 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 388 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 389 | #endif
 | 
|---|
| 390 |   Action::insertAction( ToCall, Action::NonInteractive);
 | 
|---|
| 391 | };
 | 
|---|
| 392 | 
 | 
|---|
| 393 | }
 | 
|---|
| 394 | 
 | 
|---|
| 395 | // free up defines
 | 
|---|
| 396 | #undef paramvalids
 | 
|---|
| 397 | #undef paramtypes
 | 
|---|
| 398 | #undef paramtokens
 | 
|---|
| 399 | #undef paramreferences
 | 
|---|
| 400 | #undef paramdescriptions
 | 
|---|
| 401 | #undef paramdefaults
 | 
|---|
| 402 | #undef MAXPARAMTYPES
 | 
|---|
| 403 | #undef MAXPARAMDEFAULTS
 | 
|---|
| 404 | #undef statetypes
 | 
|---|
| 405 | #undef statereferences
 | 
|---|
| 406 | #undef MAXSTATETYPES
 | 
|---|
| 407 | #undef PARAM_DEFAULT
 | 
|---|
| 408 | 
 | 
|---|
| 409 | #undef type2string
 | 
|---|
| 410 | #undef stringtype
 | 
|---|
| 411 | #undef initialiser_print
 | 
|---|
| 412 | #undef type_print
 | 
|---|
| 413 | #undef type_list
 | 
|---|
| 414 | #undef dialog_print
 | 
|---|
| 415 | #undef sequencer
 | 
|---|
| 416 | #undef valid_print
 | 
|---|
| 417 | #undef validcopy_print
 | 
|---|
| 418 | #undef value_print
 | 
|---|
| 419 | #undef valuetype_print
 | 
|---|
| 420 | 
 | 
|---|
| 421 | #undef ACTION
 | 
|---|
| 422 | #undef COMMAND
 | 
|---|
| 423 | #undef PARAMS
 | 
|---|
| 424 | #undef STATE
 | 
|---|
| 425 | #undef INSTANCE
 | 
|---|
| 426 | 
 | 
|---|
| 427 | #undef ACTIONNAME
 | 
|---|
| 428 | #undef CATEGORY
 | 
|---|
| 429 | #undef TOKEN
 | 
|---|