| 1 | /*
 | 
|---|
| 2 |  * SubgraphDissectionAction.hpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Mar 1, 2013
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #ifndef SUBGRAPHDISSECTIONACTION_HPP_
 | 
|---|
| 9 | #define SUBGRAPHDISSECTIONACTION_HPP_
 | 
|---|
| 10 | 
 | 
|---|
| 11 | // include config.h
 | 
|---|
| 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 13 | #include <config.h>
 | 
|---|
| 14 | #endif
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include "Actions/ActionSequence.hpp"
 | 
|---|
| 17 | #include "Actions/ActionTraits.hpp"
 | 
|---|
| 18 | #include "Actions/MakroAction.hpp"
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "SubgraphDissectionAction.def"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | // some derived names: if CATEGORY is not given, we don't prefix with it
 | 
|---|
| 23 | #ifdef CATEGORY
 | 
|---|
| 24 | #define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
 | 
|---|
| 25 | #define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
 | 
|---|
| 26 | #define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
 | 
|---|
| 27 | #else
 | 
|---|
| 28 | #define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
 | 
|---|
| 29 | #define COMMAND ACTIONNAME
 | 
|---|
| 30 | #define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
 | 
|---|
| 31 | #endif
 | 
|---|
| 32 | // check if no lists given
 | 
|---|
| 33 | #ifndef paramtypes
 | 
|---|
| 34 | #define MAXPARAMTYPES 0
 | 
|---|
| 35 | #else
 | 
|---|
| 36 | #define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
 | 
|---|
| 37 | #endif
 | 
|---|
| 38 | #ifndef paramdefaults
 | 
|---|
| 39 | #define MAXPARAMDEFAULTS 0
 | 
|---|
| 40 | #else
 | 
|---|
| 41 | #define MAXPARAMDEFAULTS BOOST_PP_SEQ_SIZE(paramdefaults)
 | 
|---|
| 42 | #endif
 | 
|---|
| 43 | 
 | 
|---|
| 44 | namespace MoleCuilder {
 | 
|---|
| 45 | 
 | 
|---|
| 46 | // print a list of type ref followed, i.e. "int i, double position"
 | 
|---|
| 47 | #define type_list(z,n,TYPELIST, VARLIST) \
 | 
|---|
| 48 |   BOOST_PP_COMMA_IF(n)\
 | 
|---|
| 49 |   BOOST_PP_SEQ_ELEM(n, TYPELIST) \
 | 
|---|
| 50 |   BOOST_PP_SEQ_ELEM(n, VARLIST)
 | 
|---|
| 51 | 
 | 
|---|
| 52 | void COMMAND(
 | 
|---|
| 53 | #if defined paramtypes && defined paramreferences
 | 
|---|
| 54 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
 | 
|---|
| 55 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
| 56 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
| 57 | #endif
 | 
|---|
| 58 |     );
 | 
|---|
| 59 | 
 | 
|---|
| 60 | class GraphSubgraphDissectionAction;
 | 
|---|
| 61 | 
 | 
|---|
| 62 | template <>
 | 
|---|
| 63 | class ActionTraits<ACTION> : public ActionTrait {
 | 
|---|
| 64 | public:
 | 
|---|
| 65 |   ActionTraits() :
 | 
|---|
| 66 | #ifndef SHORTFORM
 | 
|---|
| 67 |     ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string()))
 | 
|---|
| 68 | #else
 | 
|---|
| 69 |     ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string(), SHORTFORM))
 | 
|---|
| 70 | #endif /* SHORTFORM */
 | 
|---|
| 71 |   {
 | 
|---|
| 72 |   // initialize remainder of action info
 | 
|---|
| 73 | #ifdef MENUNAME
 | 
|---|
| 74 |     MenuTitle = MENUNAME;
 | 
|---|
| 75 | #endif
 | 
|---|
| 76 | #ifdef MENUPOSITION
 | 
|---|
| 77 |     MenuPosition = MENUPOSITION;
 | 
|---|
| 78 | #endif
 | 
|---|
| 79 | 
 | 
|---|
| 80 |     // we got no options to initialize
 | 
|---|
| 81 |   }
 | 
|---|
| 82 | 
 | 
|---|
| 83 |   virtual ~ActionTraits() {
 | 
|---|
| 84 |     //std::cout << "ActionTraits<" << BOOST_PP_STRINGIZE(ACTION) << ">::~ActionTraits() on instance " << this << " with name " << getName() << " called." << std::endl;
 | 
|---|
| 85 |   }
 | 
|---|
| 86 | };
 | 
|---|
| 87 | 
 | 
|---|
| 88 | class GraphSubgraphDissectionAction : public MakroAction
 | 
|---|
| 89 | {
 | 
|---|
| 90 | public:
 | 
|---|
| 91 |   GraphSubgraphDissectionAction();
 | 
|---|
| 92 |   virtual ~GraphSubgraphDissectionAction();
 | 
|---|
| 93 | 
 | 
|---|
| 94 |   // must be called after all primitive actions are present
 | 
|---|
| 95 |   void prepare(ActionRegistry &AR);
 | 
|---|
| 96 |   // must be called before alle primitive actions are removed
 | 
|---|
| 97 |   void unprepare(ActionRegistry &AR);
 | 
|---|
| 98 | 
 | 
|---|
| 99 |   virtual ActionState::ptr performCall();
 | 
|---|
| 100 |   virtual ActionState::ptr performUndo(ActionState::ptr);
 | 
|---|
| 101 |   virtual ActionState::ptr performRedo(ActionState::ptr);
 | 
|---|
| 102 | 
 | 
|---|
| 103 | private:
 | 
|---|
| 104 |   //!> flag to check whether actions have been prepared
 | 
|---|
| 105 |   static bool isPrepared;
 | 
|---|
| 106 |   //!> sequence of actions for this macro action
 | 
|---|
| 107 |   static ActionSequence actions;
 | 
|---|
| 108 | };
 | 
|---|
| 109 | 
 | 
|---|
| 110 | }
 | 
|---|
| 111 | 
 | 
|---|
| 112 | #undef ACTION
 | 
|---|
| 113 | #undef COMMAND
 | 
|---|
| 114 | #undef COMMANDFULL
 | 
|---|
| 115 | #undef PARAMS
 | 
|---|
| 116 | 
 | 
|---|
| 117 | #undef ACTIONNAME
 | 
|---|
| 118 | #undef CATEGORY
 | 
|---|
| 119 | #undef MENUNAME
 | 
|---|
| 120 | #undef MENUPOSITION
 | 
|---|
| 121 | #undef TOKEN
 | 
|---|
| 122 | 
 | 
|---|
| 123 | #undef DESCRIPTION
 | 
|---|
| 124 | #undef SHORTFORM
 | 
|---|
| 125 | 
 | 
|---|
| 126 | #endif /* SUBGRAPHDISSECTIONACTION_HPP_ */
 | 
|---|