| [0b2ce9] | 1 | /*
|
|---|
| 2 | * Action_impl_header.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Aug 25, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| [56f73b] | 8 | // include config.h
|
|---|
| 9 | #ifdef HAVE_CONFIG_H
|
|---|
| 10 | #include <config.h>
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| [0b2ce9] | 13 | #include <boost/preprocessor/cat.hpp>
|
|---|
| 14 | #include <boost/preprocessor/comparison/equal.hpp>
|
|---|
| 15 | #include <boost/preprocessor/comparison/not_equal.hpp>
|
|---|
| 16 | #include <boost/preprocessor/control/if.hpp>
|
|---|
| 17 | #include <boost/preprocessor/debug/assert.hpp>
|
|---|
| 18 | #include <boost/preprocessor/iteration/local.hpp>
|
|---|
| 19 | #include <boost/preprocessor/punctuation/comma_if.hpp>
|
|---|
| 20 | #include <boost/preprocessor/repetition/repeat.hpp>
|
|---|
| 21 | #include <boost/preprocessor/seq/elem.hpp>
|
|---|
| 22 | #include <boost/preprocessor/seq/push_back.hpp>
|
|---|
| 23 | #include <boost/preprocessor/seq/seq.hpp>
|
|---|
| 24 | #include <boost/preprocessor/seq/size.hpp>
|
|---|
| [9ee38b] | 25 | #include <boost/preprocessor/seq/transform.hpp>
|
|---|
| [0b2ce9] | 26 |
|
|---|
| [e4afb4] | 27 | #include <iostream>
|
|---|
| 28 | #include <typeinfo>
|
|---|
| 29 |
|
|---|
| 30 | #include "Actions/ActionTraits.hpp"
|
|---|
| [df32ee] | 31 | #include "Actions/ValueStorage.hpp"
|
|---|
| 32 |
|
|---|
| [e4afb4] | 33 | // some derived names: if CATEGORY is not given, we don't prefix with it
|
|---|
| 34 | #ifdef CATEGORY
|
|---|
| [0b2ce9] | 35 | #define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
|
|---|
| 36 | #define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
|
|---|
| 37 | #define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
|
|---|
| [e4afb4] | 38 | #else
|
|---|
| 39 | #define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
|
|---|
| 40 | #define COMMAND ACTIONNAME
|
|---|
| 41 | #define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
|
|---|
| 42 | #endif
|
|---|
| [0b2ce9] | 43 | // check if no lists given
|
|---|
| [b4fa106] | 44 | #ifndef paramtypes
|
|---|
| 45 | #define MAXPARAMTYPES 0
|
|---|
| [0b2ce9] | 46 | #else
|
|---|
| [b4fa106] | 47 | #define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
|
|---|
| [0b2ce9] | 48 | #endif
|
|---|
| 49 |
|
|---|
| 50 | // check user has given name and category
|
|---|
| 51 | #ifndef ACTIONNAME
|
|---|
| 52 | ERROR: No "ACTIONNAME" defined in: __FILE__
|
|---|
| 53 | #endif
|
|---|
| 54 |
|
|---|
| 55 | // calculate numbers and check whether all have same size
|
|---|
| [b4fa106] | 56 | #ifdef paramtokens
|
|---|
| 57 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\
|
|---|
| 58 | ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
|
|---|
| [0b2ce9] | 59 | )
|
|---|
| 60 | #endif
|
|---|
| [b4fa106] | 61 | #ifdef paramreferences
|
|---|
| 62 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
|
|---|
| 63 | ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
|
|---|
| [0b2ce9] | 64 | )
|
|---|
| 65 | #endif
|
|---|
| [53be34] | 66 | #ifdef paramdescriptions
|
|---|
| 67 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdescriptions)),\
|
|---|
| 68 | ERROR: There are not the same number of "paramtokens" and "paramdescriptions" in: __FILE__ \
|
|---|
| 69 | )
|
|---|
| 70 | #endif
|
|---|
| 71 |
|
|---|
| 72 | // check for mandatory defines
|
|---|
| 73 | #ifndef DESCRIPTION
|
|---|
| 74 | BOOST_PP_ASSERT_MSG(0, \
|
|---|
| 75 | "ERROR: Description is mandatory for Actions, here for ACTION " \
|
|---|
| 76 | )
|
|---|
| 77 | #endif
|
|---|
| [e4afb4] | 78 |
|
|---|
| 79 | // check if paramdefaults is given, otherwise fill list with NODEFAULT
|
|---|
| 80 | // this does not work: paramdefaults has to be completely defined before
|
|---|
| 81 | // being used within option_print (used as an array there and not as
|
|---|
| 82 | // some function call still to be expanded)
|
|---|
| 83 | //#define paramdefaults (NODEFAULT)
|
|---|
| 84 | //#define tempvalue(z,n,value)
|
|---|
| 85 | // BOOST_PP_CAT(value,(NODEFAULT))
|
|---|
| 86 | //BOOST_PP_REPEAT(tempvalue, MAXPARAMTYPES, paramdefaults)
|
|---|
| 87 | //#undef tempvalue
|
|---|
| 88 | //#else
|
|---|
| 89 |
|
|---|
| 90 | // if present, check if correct number of arguments
|
|---|
| 91 | #ifdef paramdefaults
|
|---|
| 92 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdefaults)),\
|
|---|
| 93 | ERROR: There are not the same number of "paramtokens" and "paramdefaults" in: __FILE__ \
|
|---|
| [53be34] | 94 | )
|
|---|
| 95 | #endif
|
|---|
| [0b2ce9] | 96 |
|
|---|
| 97 | // print a list of type ref followed by a separator, i.e. "int i;"
|
|---|
| [b4fa106] | 98 | #define type_print(z,n,TYPELIST, VARLIST, separator) \
|
|---|
| 99 | BOOST_PP_SEQ_ELEM(n, TYPELIST) \
|
|---|
| 100 | BOOST_PP_SEQ_ELEM(n, VARLIST)\
|
|---|
| [0b2ce9] | 101 | separator
|
|---|
| 102 |
|
|---|
| 103 | // print a list of type ref followed, i.e. "int i, double position"
|
|---|
| [b4fa106] | 104 | #define type_list(z,n,TYPELIST, VARLIST) \
|
|---|
| [0b2ce9] | 105 | BOOST_PP_COMMA_IF(n)\
|
|---|
| [b4fa106] | 106 | BOOST_PP_SEQ_ELEM(n, TYPELIST) \
|
|---|
| 107 | BOOST_PP_SEQ_ELEM(n, VARLIST)
|
|---|
| 108 |
|
|---|
| [e4afb4] | 109 | // prints Options.insert
|
|---|
| 110 | #ifdef paramdefaults
|
|---|
| 111 | #define option_print(z,n,unused, unused2) \
|
|---|
| 112 | tester = Options. insert (\
|
|---|
| 113 | std::pair< std::string, OptionTrait *> ( \
|
|---|
| 114 | BOOST_PP_SEQ_ELEM(n, paramtokens), \
|
|---|
| 115 | new OptionTrait(\
|
|---|
| 116 | BOOST_PP_SEQ_ELEM(n, paramtokens), \
|
|---|
| 117 | &typeid( BOOST_PP_SEQ_ELEM(n, paramtypes) ), \
|
|---|
| 118 | BOOST_PP_SEQ_ELEM(n, paramdescriptions), \
|
|---|
| [d1115d] | 119 | std::string( BOOST_PP_SEQ_ELEM(n, paramdefaults) ) )\
|
|---|
| [e4afb4] | 120 | )\
|
|---|
| 121 | ); \
|
|---|
| 122 | ASSERT(tester.second, "ActionTrait<ACTION>::ActionTrait<ACTION>() option token present twice!");
|
|---|
| 123 | #else
|
|---|
| 124 | #define option_print(z,n,unused, unused2) \
|
|---|
| 125 | tester = Options. insert (\
|
|---|
| 126 | std::pair< std::string, OptionTrait *> ( \
|
|---|
| 127 | BOOST_PP_SEQ_ELEM(n, paramtokens), \
|
|---|
| 128 | new OptionTrait(\
|
|---|
| 129 | BOOST_PP_SEQ_ELEM(n, paramtokens), \
|
|---|
| 130 | &typeid( BOOST_PP_SEQ_ELEM(n, paramtypes) ), \
|
|---|
| 131 | BOOST_PP_SEQ_ELEM(n, paramdescriptions), \
|
|---|
| 132 | NODEFAULT )\
|
|---|
| 133 | )\
|
|---|
| 134 | ); \
|
|---|
| 135 | ASSERT(tester.second, "ActionTrait<ACTION>::ActionTrait<ACTION>() option token present twice!");
|
|---|
| 136 | #endif
|
|---|
| [53be34] | 137 |
|
|---|
| [ce7fdc] | 138 | namespace MoleCuilder {
|
|---|
| 139 |
|
|---|
| [b4fa106] | 140 | void COMMAND(
|
|---|
| [05736a] | 141 | #if defined paramtypes && defined paramreferences
|
|---|
| [b4fa106] | 142 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
|
|---|
| 143 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
|---|
| 144 | #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| [0b2ce9] | 145 | #endif
|
|---|
| [05736a] | 146 | );
|
|---|
| [0b2ce9] | 147 |
|
|---|
| [df32ee] | 148 | class ACTION;
|
|---|
| 149 |
|
|---|
| 150 | template <>
|
|---|
| [3139b2] | 151 | class ActionTraits<ACTION> : public ActionTrait {
|
|---|
| [df32ee] | 152 | public:
|
|---|
| [3139b2] | 153 | ActionTraits() :
|
|---|
| [e4afb4] | 154 | #ifndef SHORTFORM
|
|---|
| [3139b2] | 155 | ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string()))
|
|---|
| [e4afb4] | 156 | #else
|
|---|
| [3139b2] | 157 | ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string(), SHORTFORM))
|
|---|
| [e4afb4] | 158 | #endif /* SHORTFORM */
|
|---|
| [bc2990] | 159 | {
|
|---|
| [e4afb4] | 160 | // initialize remainder of action info
|
|---|
| [53be34] | 161 | #ifdef MENUNAME
|
|---|
| 162 | MenuTitle = MENUNAME;
|
|---|
| 163 | #endif
|
|---|
| 164 | #ifdef MENUPOSITION
|
|---|
| 165 | MenuPosition = MENUPOSITION;
|
|---|
| [24fbf3] | 166 | #endif
|
|---|
| [e4afb4] | 167 |
|
|---|
| [6a2dae] | 168 | // initialize action's options
|
|---|
| [3139b2] | 169 | std::pair< ActionTrait::options_iterator, bool > tester;
|
|---|
| [e4afb4] | 170 | #ifdef paramtokens
|
|---|
| 171 | #define BOOST_PP_LOCAL_MACRO(n) option_print(~, n, ~, )
|
|---|
| 172 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
|---|
| 173 | #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| [24fbf3] | 174 | #endif
|
|---|
| [6a2dae] | 175 | // associate action's short form also with option
|
|---|
| [e4afb4] | 176 | #ifdef SHORTFORM
|
|---|
| [6a2dae] | 177 | if (Options.find(TOKEN) != Options.end())
|
|---|
| 178 | Options[TOKEN]->setShortForm(std::string(SHORTFORM));
|
|---|
| [e4afb4] | 179 | #endif /* SHORTFORM */
|
|---|
| [3139b2] | 180 | //std::cout << "ActionTraits<" << BOOST_PP_STRINGIZE(ACTION) << ">::ActionTraits() on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
|
|---|
| [bc2990] | 181 | }
|
|---|
| [df32ee] | 182 |
|
|---|
| [3139b2] | 183 | virtual ~ActionTraits() {
|
|---|
| 184 | //std::cout << "ActionTraits<" << BOOST_PP_STRINGIZE(ACTION) << ">::~ActionTraits() on instance " << this << " with name " << getName() << " called." << std::endl;
|
|---|
| 185 | }
|
|---|
| [df32ee] | 186 | };
|
|---|
| 187 |
|
|---|
| [0b2ce9] | 188 | class ACTION : public Action {
|
|---|
| [b4fa106] | 189 | #if defined paramtypes && defined paramreferences
|
|---|
| [e4afb4] | 190 | friend void COMMAND(
|
|---|
| [b4fa106] | 191 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
|
|---|
| 192 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
|---|
| 193 | #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| 194 | );
|
|---|
| 195 | # else
|
|---|
| 196 | void COMMAND();
|
|---|
| 197 | #endif
|
|---|
| 198 |
|
|---|
| [0b2ce9] | 199 | public:
|
|---|
| 200 | ACTION();
|
|---|
| 201 | virtual ~ACTION();
|
|---|
| 202 |
|
|---|
| 203 | bool canUndo();
|
|---|
| 204 | bool shouldUndo();
|
|---|
| 205 |
|
|---|
| [9ee38b] | 206 | struct PARAMS : ActionParameters {
|
|---|
| [b4fa106] | 207 | #if defined paramtypes && defined paramreferences
|
|---|
| 208 | #define BOOST_PP_LOCAL_MACRO(n) type_print(~, n, paramtypes, paramreferences, ;)
|
|---|
| 209 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
|---|
| [9ee38b] | 210 | #include BOOST_PP_LOCAL_ITERATE()
|
|---|
| 211 | #endif
|
|---|
| 212 | } params;
|
|---|
| [0b2ce9] | 213 |
|
|---|
| 214 | protected:
|
|---|
| 215 | virtual Dialog * fillDialog(Dialog*);
|
|---|
| [862b6a] | 216 |
|
|---|
| 217 | void startTimer() const;
|
|---|
| 218 | void endTimer() const;
|
|---|
| 219 |
|
|---|
| [0b2ce9] | 220 | private:
|
|---|
| 221 | virtual void getParametersfromValueStorage();
|
|---|
| 222 | virtual Action::state_ptr performCall();
|
|---|
| 223 | virtual Action::state_ptr performUndo(Action::state_ptr);
|
|---|
| 224 | virtual Action::state_ptr performRedo(Action::state_ptr);
|
|---|
| 225 | };
|
|---|
| 226 |
|
|---|
| [ce7fdc] | 227 | }
|
|---|
| 228 |
|
|---|
| [b4fa106] | 229 | #undef paramtypes
|
|---|
| 230 | #undef paramtokens
|
|---|
| 231 | #undef paramreferences
|
|---|
| [e4afb4] | 232 | #undef paramdescriptions
|
|---|
| 233 | #undef paramdefaults
|
|---|
| [b4fa106] | 234 | #undef MAXPARAMTYPES
|
|---|
| 235 | #undef statetypes
|
|---|
| 236 | #undef statereferences
|
|---|
| 237 | #undef MAXSTATETYPES
|
|---|
| [9ee38b] | 238 |
|
|---|
| [a02f78] | 239 | #undef option_print
|
|---|
| 240 | #undef type_print
|
|---|
| 241 | #undef type_list
|
|---|
| 242 |
|
|---|
| [9ee38b] | 243 | #undef ACTION
|
|---|
| 244 | #undef COMMAND
|
|---|
| 245 | #undef COMMANDFULL
|
|---|
| 246 | #undef PARAMS
|
|---|
| [b4fa106] | 247 |
|
|---|
| 248 | #undef ACTIONNAME
|
|---|
| 249 | #undef CATEGORY
|
|---|
| [e4afb4] | 250 | #undef MENUNAME
|
|---|
| 251 | #undef MENUPOSITION
|
|---|
| [9ee38b] | 252 | #undef TOKEN
|
|---|
| [e4afb4] | 253 |
|
|---|
| 254 | #undef DESCRIPTION
|
|---|
| 255 | #undef SHORTFORM
|
|---|