source: src/Actions/Reaction_impl_pre.hpp@ 40ec38

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 40ec38 was 0c8056, checked in by Frederik Heber <heber@…>, 12 years ago

Actions now get ptr to ActionRegistry in cstor.

  • this is the last of the externally present getActionRegistry() calls.
  • also changed: Calculation, ErrorAction, ManipulateAtomsProcess, MakroAction, MethodAction, Process, Reaction. Some of these had default of doRegister but are only used with false. We removed any default value in header if set to true. However, this will cause default behavior of false (as Action has default NULL for ActionRegistry ptr).
  • purged some unnecessary ActionRegistry includes.
  • Property mode set to 100644
File size: 7.3 KB
Line 
1/*
2 * Reaction_impl.hpp
3 *
4 * Created on: Oct 13, 2011
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
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
24 * -# CATEGORY, e.g. Analysis
25 * -# ACTIONNAME, e.g. MolecularVolume
26 */
27
28// include config.h
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32
33#include <boost/preprocessor/cat.hpp>
34#include <boost/preprocessor/comparison/equal.hpp>
35#include <boost/preprocessor/comparison/not_equal.hpp>
36#include <boost/preprocessor/debug/assert.hpp>
37#include <boost/preprocessor/iteration/local.hpp>
38#include <boost/preprocessor/punctuation/comma_if.hpp>
39#include <boost/preprocessor/seq/elem.hpp>
40#include <boost/preprocessor/seq/seq.hpp>
41#include <boost/preprocessor/seq/size.hpp>
42#include <boost/preprocessor/seq/transform.hpp>
43
44#include "Actions/ActionQueue.hpp"
45
46// some derived names: if CATEGORY is not given, we don't prefix with it
47#ifdef CATEGORY
48#define REACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
49#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
50#define STATE BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, State))
51#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
52#else
53#define REACTION BOOST_PP_CAT(ACTIONNAME, Action)
54#define COMMAND ACTIONNAME
55#define STATE BOOST_PP_CAT(ACTIONNAME, State)
56#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
57#endif
58
59// check if no lists given
60#ifndef paramtypes
61#define MAXPARAMTYPES 0
62#else
63#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
64#endif
65#ifndef statetypes
66#define MAXSTATETYPES 0
67#else
68#define MAXSTATETYPES BOOST_PP_SEQ_SIZE(statetypes)
69#endif
70
71// check user has given name and category
72#ifndef ACTIONNAME
73ERROR: No "ACTIONNAME" defined in: __FILE__
74#endif
75
76// calculate numbers and check whether all have same size
77#ifdef paramtokens
78BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\
79 ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
80)
81#endif
82#ifdef paramreferences
83BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
84 ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
85)
86#endif
87
88#ifdef statetypes
89BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXSTATETYPES, BOOST_PP_SEQ_SIZE(statereferences)),\
90 ERROR: There are not the same number of "statetypes" and "statereferences" in: __FILE__ \
91)
92#endif
93
94// set the return type
95#ifndef returntype
96BOOST_PP_ASSERT_MSG(0,\
97 ERROR: No returntype is defined in __FILE__ \
98)
99#endif
100#define RETURNTYPE returntype
101
102// print a list of type ref followed by a separator, i.e. "int i;"
103#define initialiser_print(z,n,initialiserlist) \
104 BOOST_PP_SEQ_ELEM(n, initialiserlist) \
105 (BOOST_PP_CAT(_, BOOST_PP_SEQ_ELEM(n, initialiserlist))),
106
107// print a list of ref(_ref) followed by a separator, i.e. "id(_id),"
108#define type_print(z,n,TYPELIST, VARLIST, separator) \
109 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
110 BOOST_PP_SEQ_ELEM(n, VARLIST)\
111 separator
112
113// print a list of type ref followed, i.e. "int i, double position"
114#define type_list(z,n,TYPELIST,VARLIST) \
115 BOOST_PP_COMMA_IF(n)\
116 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
117 BOOST_PP_SEQ_ELEM(n, VARLIST)
118
119// prints dialog->query calls for paramtypes with tokens
120#define dialog_print(z,n,unused) \
121 dialog->query<\
122 BOOST_PP_SEQ_ELEM(n, paramtypes)\
123 >(\
124 BOOST_PP_SEQ_ELEM(n, paramtokens)\
125 , Traits.getDescription()\
126 );
127
128// prints set/queryCurrentValue (command) for paramreferences and paramtokens
129#define value_print(z, n, container, prefix) \
130 prefix \
131 BOOST_PP_SEQ_ELEM(n, container)\
132 .set(\
133 BOOST_PP_SEQ_ELEM(n, container)\
134 );
135
136// prints set/queryCurrentValue (command) for paramreferences and paramtokens
137#define valuetype_print(z,n,container, types, prefix) \
138 prefix \
139 BOOST_PP_SEQ_ELEM(n, container) \
140 .setAsString( \
141 BOOST_PP_SEQ_ELEM(n, container) \
142 );
143
144#define stringtype std::string
145
146#define type2string(s, data, elem) \
147 stringtype
148
149
150#include "Actions/ActionRegistry.hpp"
151//#include "Actions/ActionTraits.hpp"
152#include "UIElements/Dialog.hpp"
153
154#ifdef paramtokens
155#define statenecessary 1
156#endif
157#ifndef statetokens
158#define statenecessary 1
159#endif
160
161namespace MoleCuilder {
162
163// =========== constructor ===========
164REACTION::REACTION () :
165 Reaction< RETURNTYPE >(ActionTraits< REACTION >(), NULL)
166{}
167
168// =========== destructor ===========
169REACTION::~REACTION ()
170{
171 //std::cout << "Action REACTION is being destroyed." << std::endl;
172}
173
174// =========== fill a dialog ===========
175Dialog* REACTION::fillDialog(Dialog *dialog) {
176 ASSERT(dialog,"No Dialog given when filling actionname's dialog");
177#if BOOST_PP_EQUAL(MAXPARAMTYPES,0)
178 dialog->queryEmpty(TOKEN, Traits.getDescription());
179#else
180#define BOOST_PP_LOCAL_MACRO(n) dialog_print(~, n, ~)
181#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
182#include BOOST_PP_LOCAL_ITERATE()
183#endif
184 return dialog;
185};
186
187// =========== command for calling action directly ===========
188RETURNTYPE COMMAND(
189#if defined paramtypes && defined paramreferences
190#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
191#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
192#include BOOST_PP_LOCAL_ITERATE()
193#endif
194)
195{
196 Action *ToCall = ActionQueue::getInstance().getActionByName( TOKEN ); //->clone(params);
197 //REACTION::PARAMS params;
198#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
199#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, setCurrentValue, )
200#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
201#include BOOST_PP_LOCAL_ITERATE()
202#endif
203 ToCall->call(Action::NonInteractive);
204
205 return static_cast<Reaction< RETURNTYPE > *>(ToCall)->getResult();
206};
207
208RETURNTYPE BOOST_PP_CAT( COMMAND, _stringargs)(
209#if defined paramtypes && defined paramreferences
210#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
211#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
212#include BOOST_PP_LOCAL_ITERATE()
213#endif
214 ) {
215 Action *ToCall = ActionQueue::getInstance().getActionByName( TOKEN ); //->clone(params);
216 //REACTION::PARAMS params;
217#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
218#define BOOST_PP_LOCAL_MACRO(n) valuetype_print(~, n, setCurrentValueByString, )
219#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
220#include BOOST_PP_LOCAL_ITERATE()
221#endif
222 ToCall->call(MoleCuilder::Action::NonInteractive);
223
224 return static_cast<Reaction< RETURNTYPE > *>(ToCall)->getResult();
225};
226
227}
228
229// free up defines
230#undef paramtypes
231#undef paramtokens
232#undef paramreferences
233#undef MAXPARAMTYPES
234
235#undef returntype
236#undef RETURNTYPE
237
238#undef type2string
239#undef stringtype
240#undef initialiser_print
241#undef type_print
242#undef type_list
243#undef dialog_print
244#undef value_print
245#undef valuetype_print
246
247#undef REACTION
248#undef COMMAND
249#undef PARAMS
250#undef STATE
251
252#undef ACTIONNAME
253#undef CATEGORY
254#undef TOKEN
Note: See TracBrowser for help on using the repository browser.