| [0b2ce9] | 1 | /*
|
|---|
| 2 | * Action_impl_header.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Aug 25, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include <boost/preprocessor/cat.hpp>
|
|---|
| 9 | #include <boost/preprocessor/comparison/equal.hpp>
|
|---|
| 10 | #include <boost/preprocessor/comparison/not_equal.hpp>
|
|---|
| 11 | #include <boost/preprocessor/control/if.hpp>
|
|---|
| 12 | #include <boost/preprocessor/debug/assert.hpp>
|
|---|
| 13 | #include <boost/preprocessor/iteration/local.hpp>
|
|---|
| 14 | #include <boost/preprocessor/punctuation/comma_if.hpp>
|
|---|
| 15 | #include <boost/preprocessor/repetition/repeat.hpp>
|
|---|
| 16 | #include <boost/preprocessor/seq/elem.hpp>
|
|---|
| 17 | #include <boost/preprocessor/seq/push_back.hpp>
|
|---|
| 18 | #include <boost/preprocessor/seq/seq.hpp>
|
|---|
| 19 | #include <boost/preprocessor/seq/size.hpp>
|
|---|
| 20 |
|
|---|
| 21 | // some derived names
|
|---|
| 22 | #define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
|
|---|
| 23 | #define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
|
|---|
| 24 | #define STATE BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, State))
|
|---|
| 25 | #define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | // check if no lists given
|
|---|
| 29 | #ifndef types
|
|---|
| 30 | #define MAXNOTOKENS 0
|
|---|
| 31 | #else
|
|---|
| 32 | #define MAXNOTOKENS BOOST_PP_SEQ_SIZE(types)
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | // check user has given name and category
|
|---|
| 36 | #ifndef CATEGORY
|
|---|
| 37 | ERROR: No "CATEGORY" defined in: __FILE__
|
|---|
| 38 | #endif
|
|---|
| 39 |
|
|---|
| 40 | #ifndef ACTIONNAME
|
|---|
| 41 | ERROR: No "ACTIONNAME" defined in: __FILE__
|
|---|
| 42 | #endif
|
|---|
| 43 |
|
|---|
| 44 | // calculate numbers and check whether all have same size
|
|---|
| 45 | #ifdef tokens
|
|---|
| 46 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXNOTOKENS, BOOST_PP_SEQ_SIZE(tokens)),\
|
|---|
| 47 | ERROR: There are not the same number of "tokens" and "types" in: __FILE__ \
|
|---|
| 48 | )
|
|---|
| 49 | #endif
|
|---|
| 50 | #ifdef references
|
|---|
| 51 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXNOTOKENS, BOOST_PP_SEQ_SIZE(references)),\
|
|---|
| 52 | ERROR: There are not the same number of "tokens" and "references" in: __FILE__ \
|
|---|
| 53 | )
|
|---|
| 54 | #endif
|
|---|
| 55 |
|
|---|
| 56 | // print a list of type ref followed by a separator, i.e. "int i;"
|
|---|
| 57 | #define type_print(z,n,separator) \
|
|---|
| 58 | BOOST_PP_SEQ_ELEM(n, types) \
|
|---|
| 59 | BOOST_PP_SEQ_ELEM(n, references)\
|
|---|
| 60 | separator
|
|---|
| 61 |
|
|---|
| 62 | // print a list of type ref followed, i.e. "int i, double position"
|
|---|
| 63 | #define type_list(z,n,unused) \
|
|---|
| 64 | BOOST_PP_COMMA_IF(n)\
|
|---|
| 65 | BOOST_PP_SEQ_ELEM(n, types) \
|
|---|
| 66 | BOOST_PP_SEQ_ELEM(n, references)
|
|---|
| 67 |
|
|---|
| 68 | // prints dialog->query calls for types with tokens
|
|---|
| 69 | #define dialog_print(z,n,unused) \
|
|---|
| 70 | dialog->query<\
|
|---|
| 71 | BOOST_PP_SEQ_ELEM(n, types)\
|
|---|
| 72 | >(\
|
|---|
| 73 | BOOST_PP_SEQ_ELEM(n, tokens)\
|
|---|
| 74 | , ValueStorage::getInstance().getDescription(\
|
|---|
| 75 | BOOST_PP_SEQ_ELEM(n, tokens)\
|
|---|
| 76 | ));
|
|---|
| 77 |
|
|---|
| 78 | // prints set/queryCurrentValue (command) for references and tokens
|
|---|
| 79 | #define value_print(z,n,command) \
|
|---|
| 80 | ValueStorage::getInstance(). command (\
|
|---|
| 81 | BOOST_PP_SEQ_ELEM(n, references)\
|
|---|
| 82 | , \
|
|---|
| 83 | BOOST_PP_SEQ_ELEM(n, tokens)\
|
|---|
| 84 | );
|
|---|
| 85 |
|
|---|
| 86 | #if BOOST_PP_NOT_EQUAL(MAXNOTOKENS,0)
|
|---|
| 87 | #define COMMANDFULL \
|
|---|
| 88 | void COMMAND( \
|
|---|
| 89 | BOOST_PP_REPEAT(MAXNOTOKENS, type_list, ~) \
|
|---|
| 90 | )
|
|---|
| 91 | # else
|
|---|
| 92 | #define COMMANDFULL void COMMAND()
|
|---|
| 93 | #endif
|
|---|
| 94 |
|
|---|
| 95 | COMMANDFULL;
|
|---|
| 96 |
|
|---|
| 97 | class ACTION : public Action {
|
|---|
| 98 | friend COMMANDFULL;
|
|---|
| 99 | public:
|
|---|
| 100 | ACTION();
|
|---|
| 101 | virtual ~ACTION();
|
|---|
| 102 |
|
|---|
| 103 | bool canUndo();
|
|---|
| 104 | bool shouldUndo();
|
|---|
| 105 |
|
|---|
| 106 | virtual const std::string getName();
|
|---|
| 107 |
|
|---|
| 108 | struct PARAMS;
|
|---|
| 109 |
|
|---|
| 110 | protected:
|
|---|
| 111 | virtual Dialog * fillDialog(Dialog*);
|
|---|
| 112 | private:
|
|---|
| 113 | virtual void getParametersfromValueStorage();
|
|---|
| 114 | virtual Action::state_ptr performCall();
|
|---|
| 115 | virtual Action::state_ptr performUndo(Action::state_ptr);
|
|---|
| 116 | virtual Action::state_ptr performRedo(Action::state_ptr);
|
|---|
| 117 |
|
|---|
| 118 | static const char NAME[];
|
|---|
| 119 | };
|
|---|
| 120 |
|
|---|