source: src/Actions/Action_impl_pre.hpp@ 429069

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 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 429069 was 3139b2, checked in by Frederik Heber <heber@…>, 13 years ago

Renamed ActionTrait and ActionTraits.

  • the specialized Trait contains multiple OptionTraits, hence is now called ActionTrait_s_, where its base class (that just has the OptionTrait for itself) is called ActionTrait.
  • This caused many changes in other Action related files.
  • Property mode set to 100644
File size: 9.3 KB
RevLine 
[0b2ce9]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
[b4fa106]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
[0b2ce9]24 * -# CATEGORY, e.g. Analysis
25 * -# ACTIONNAME, e.g. MolecularVolume
26 */
27
[56f73b]28// include config.h
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
[9ee38b]32
[862b6a]33#include "CodePatterns/Chronos.hpp"
34
[9ee38b]35#include <boost/preprocessor/cat.hpp>
[b4fa106]36#include <boost/preprocessor/expand.hpp>
[9ee38b]37#include <boost/preprocessor/comparison/equal.hpp>
38#include <boost/preprocessor/comparison/not_equal.hpp>
39#include <boost/preprocessor/control/if.hpp>
40#include <boost/preprocessor/debug/assert.hpp>
41#include <boost/preprocessor/iteration/local.hpp>
42#include <boost/preprocessor/punctuation/comma_if.hpp>
43#include <boost/preprocessor/repetition/repeat.hpp>
44#include <boost/preprocessor/seq/elem.hpp>
45#include <boost/preprocessor/seq/push_back.hpp>
46#include <boost/preprocessor/seq/seq.hpp>
47#include <boost/preprocessor/seq/size.hpp>
48#include <boost/preprocessor/seq/transform.hpp>
49
[e4afb4]50// some derived names: if CATEGORY is not given, we don't prefix with it
51#ifdef CATEGORY
[9ee38b]52#define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
53#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
54#define STATE BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, State))
55#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
[e4afb4]56#else
57#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
58#define COMMAND ACTIONNAME
59#define STATE BOOST_PP_CAT(ACTIONNAME, State)
60#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
61#endif
[2a6a2c]62#define INSTANCE BOOST_PP_CAT(this_, BOOST_PP_CAT(ACTIONNAME, _instance))
[9ee38b]63
64// check if no lists given
[b4fa106]65#ifndef paramtypes
66#define MAXPARAMTYPES 0
[9ee38b]67#else
[b4fa106]68#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
69#endif
70#ifndef statetypes
71#define MAXSTATETYPES 0
72#else
73#define MAXSTATETYPES BOOST_PP_SEQ_SIZE(statetypes)
[9ee38b]74#endif
75
76// check user has given name and category
77#ifndef ACTIONNAME
78ERROR: No "ACTIONNAME" defined in: __FILE__
79#endif
80
81// calculate numbers and check whether all have same size
[b4fa106]82#ifdef paramtokens
83BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\
84 ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
[9ee38b]85)
86#endif
[b4fa106]87#ifdef paramreferences
88BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
89 ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
90)
91#endif
92
93#ifdef statetypes
94BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXSTATETYPES, BOOST_PP_SEQ_SIZE(statereferences)),\
95 ERROR: There are not the same number of "statetypes" and "statereferences" in: __FILE__ \
[9ee38b]96)
97#endif
98
99// print a list of type ref followed by a separator, i.e. "int i;"
[b4fa106]100#define initialiser_print(z,n,initialiserlist) \
101 BOOST_PP_SEQ_ELEM(n, initialiserlist) \
102 (BOOST_PP_CAT(_, BOOST_PP_SEQ_ELEM(n, initialiserlist))),
103
104// print a list of ref(_ref) followed by a separator, i.e. "id(_id),"
105#define type_print(z,n,TYPELIST, VARLIST, separator) \
106 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
107 BOOST_PP_SEQ_ELEM(n, VARLIST)\
[9ee38b]108 separator
109
110// print a list of type ref followed, i.e. "int i, double position"
[b4fa106]111#define type_list(z,n,TYPELIST,VARLIST) \
[9ee38b]112 BOOST_PP_COMMA_IF(n)\
[b4fa106]113 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
114 BOOST_PP_SEQ_ELEM(n, VARLIST)
[9ee38b]115
[b4fa106]116// prints dialog->query calls for paramtypes with tokens
[9ee38b]117#define dialog_print(z,n,unused) \
118 dialog->query<\
[b4fa106]119 BOOST_PP_SEQ_ELEM(n, paramtypes)\
[9ee38b]120 >(\
[b4fa106]121 BOOST_PP_SEQ_ELEM(n, paramtokens)\
[e4afb4]122 , Traits.getDescription()\
123 );
[9ee38b]124
125// prints set/queryCurrentValue (command) for paramreferences and paramtokens
126#define value_print(z,n,command, prefix) \
127 ValueStorage::getInstance(). command (\
[b4fa106]128 BOOST_PP_SEQ_ELEM(n, paramtokens)\
[9ee38b]129 , \
130 prefix\
[b4fa106]131 BOOST_PP_SEQ_ELEM(n, paramreferences)\
[9ee38b]132 );
133
[88ba1f]134// prints set/queryCurrentValue (command) for paramreferences and paramtokens
135#define valuetype_print(z,n,command, prefix) \
136 ValueStorage::getInstance(). command< \
137 BOOST_PP_SEQ_ELEM(n, paramtypes) \
138 > (\
139 BOOST_PP_SEQ_ELEM(n, paramtokens)\
140 , \
141 prefix\
142 BOOST_PP_SEQ_ELEM(n, paramreferences)\
143 );
144
145#define stringtype std::string
146
147#define type2string(s, data, elem) \
148 stringtype
149
150
[0b2ce9]151#include "Actions/ActionRegistry.hpp"
[3139b2]152//#include "Actions/ActionTraits.hpp"
[0b2ce9]153#include "UIElements/Dialog.hpp"
154
[e4afb4]155#ifdef paramtokens
156#define statenecessary 1
157#endif
158#ifndef statetokens
159#define statenecessary 1
160#endif
[9ee38b]161
[ce7fdc]162namespace MoleCuilder {
163
[b4fa106]164// =========== memento to remember the state when undoing ===========
[e4afb4]165#ifdef statenecessary
[b4fa106]166class STATE : public ActionState {
167public:
168 STATE(
169#if defined statetypes && defined statereferences // if we have parameters, we have to add "_" before each reference and add the params as the last one
170#define OP(s,data,elem) BOOST_PP_CAT(data, elem) // OP to add "_"
171#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)))
172#else /// if not, params is only list
173#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, (const ACTION::PARAMS &), (_params))
174#endif
175#define BOOST_PP_LOCAL_LIMITS (0, MAXSTATETYPES)
176#include BOOST_PP_LOCAL_ITERATE()
177) :
178#if defined statetypes && defined statereferences // do we have parameters at all?
179BOOST_PP_REPEAT(MAXSTATETYPES, initialiser_print, statereferences)
180#endif
181params(_params)
182 {}
[0b2ce9]183
[b4fa106]184#if defined statetypes && defined statereferences // do we have parameters at all?
185#define BOOST_PP_LOCAL_MACRO(n) type_print(~, n, statetypes, statereferences, ;)
186#define BOOST_PP_LOCAL_LIMITS (0, MAXSTATETYPES-1)
187#include BOOST_PP_LOCAL_ITERATE()
188#endif
189 ACTION::PARAMS params;
190};
[e4afb4]191#endif /* statenecessary */
[0b2ce9]192
[2a6a2c]193// (const) prototype to be placed into the ActionRegistry (must be deleted by registry itself)
[83e90c]194//const ACTION INSTANCE;
195//boost::shared_ptr< ACTION > INSTANCE( new ACTION() );
[2a6a2c]196
[b4fa106]197// =========== constructor ===========
[0b2ce9]198ACTION::ACTION () :
[3139b2]199 Action(ActionTraits< ACTION >(), false)
[0b2ce9]200{}
201
[b4fa106]202// =========== destructor ===========
[0b2ce9]203ACTION::~ACTION ()
[e4afb4]204{
205 //std::cout << "Action ACTION is being destroyed." << std::endl;
206}
[0b2ce9]207
[b4fa106]208// =========== fill a dialog ===========
[0b2ce9]209Dialog* ACTION::fillDialog(Dialog *dialog) {
210 ASSERT(dialog,"No Dialog given when filling actionname's dialog");
[b4fa106]211#if BOOST_PP_EQUAL(MAXPARAMTYPES,0)
[e4afb4]212 dialog->queryEmpty(TOKEN, Traits.getDescription());
[0b2ce9]213#else
214#define BOOST_PP_LOCAL_MACRO(n) dialog_print(~, n, ~)
[b4fa106]215#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
[0b2ce9]216#include BOOST_PP_LOCAL_ITERATE()
217#endif
218 return dialog;
219};
220
[862b6a]221// =========== time the action ===========
222// we need this here to have the correct function name
223void ACTION::startTimer() const { Chronos::getInstance().startTiming( std::string( TOKEN ) ); }
224void ACTION::endTimer() const { Chronos::getInstance().endTiming( std::string( TOKEN ) ); }
225
[b4fa106]226// =========== command for calling action directly ===========
227void COMMAND(
[05736a]228#if defined paramtypes && defined paramreferences
[b4fa106]229#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
230#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
231#include BOOST_PP_LOCAL_ITERATE()
232#endif
[05736a]233)
[0b2ce9]234{
[e4afb4]235 Action *ToCall = ActionRegistry::getInstance().getActionByName( TOKEN ); //->clone(params);
[ddde10]236 //ACTION::PARAMS params;
[b4fa106]237#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
[9ee38b]238#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, setCurrentValue, )
[b4fa106]239#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
[0b2ce9]240#include BOOST_PP_LOCAL_ITERATE()
241#endif
[9ee38b]242 ToCall->call(Action::NonInteractive);
[0b2ce9]243};
244
[88ba1f]245void BOOST_PP_CAT( COMMAND, _stringargs)(
246#if defined paramtypes && defined paramreferences
247#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
248#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
249#include BOOST_PP_LOCAL_ITERATE()
250#endif
251 ) {
252 Action *ToCall = ActionRegistry::getInstance().getActionByName( TOKEN ); //->clone(params);
253 //ACTION::PARAMS params;
254#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
255#define BOOST_PP_LOCAL_MACRO(n) valuetype_print(~, n, setCurrentValueByString, )
256#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
257#include BOOST_PP_LOCAL_ITERATE()
258#endif
259 ToCall->call(MoleCuilder::Action::NonInteractive);
260};
261
[b4fa106]262// =========== obtain parameters from Storage, used by performCall() ===========
[9ee38b]263void ACTION::getParametersfromValueStorage() {
[b4fa106]264#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
[9ee38b]265#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, queryCurrentValue, params.)
[b4fa106]266#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
[0b2ce9]267#include BOOST_PP_LOCAL_ITERATE()
268#endif
269};
270
[ce7fdc]271}
272
[b4fa106]273// free up defines
274#undef paramtypes
275#undef paramtokens
276#undef paramreferences
277#undef MAXPARAMTYPES
278#undef statetypes
279#undef statereferences
280#undef MAXSTATETYPES
[0b2ce9]281
[88ba1f]282#undef type2string
283#undef stringtype
[a02f78]284#undef initialiser_print
285#undef type_print
286#undef type_list
287#undef dialog_print
288#undef value_print
[88ba1f]289#undef valuetype_print
[a02f78]290
[9ee38b]291#undef ACTION
292#undef COMMAND
293#undef PARAMS
294#undef STATE
[2a6a2c]295#undef INSTANCE
[b4fa106]296
297#undef ACTIONNAME
298#undef CATEGORY
[9ee38b]299#undef TOKEN
Note: See TracBrowser for help on using the repository browser.