source: src/Actions/Action_impl_header.hpp@ 0b2ce9

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 Candidate_v1.7.0 Candidate_v1.7.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 0b2ce9 was 0b2ce9, checked in by Frederik Heber <heber@…>, 16 years ago

Implemented macros for automatically generating repetitive stuff around Actions.

The idea is that only the following items have to be provided for by the user

  • parameters (i.e. for each the following tupel: type, token and reference)
  • perform...(), ...Undo(), ...

Therefore, we have three new files:

  • Action_impl_header.hpp: Is for the declarations in the header
  • Action_impl_pre.hpp: Is before definition of functions
  • Action_impl_post.hpp: is after definition of functions (cleanup)

Changes:

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[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
37ERROR: No "CATEGORY" defined in: __FILE__
38#endif
39
40#ifndef ACTIONNAME
41ERROR: No "ACTIONNAME" defined in: __FILE__
42#endif
43
44// calculate numbers and check whether all have same size
45#ifdef tokens
46BOOST_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
51BOOST_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 \
88void COMMAND( \
89BOOST_PP_REPEAT(MAXNOTOKENS, type_list, ~) \
90)
91# else
92#define COMMANDFULL void COMMAND()
93#endif
94
95COMMANDFULL;
96
97class ACTION : public Action {
98 friend COMMANDFULL;
99public:
100 ACTION();
101 virtual ~ACTION();
102
103 bool canUndo();
104 bool shouldUndo();
105
106 virtual const std::string getName();
107
108 struct PARAMS;
109
110protected:
111 virtual Dialog * fillDialog(Dialog*);
112private:
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
Note: See TracBrowser for help on using the repository browser.