source: src/Actions/Reaction_impl_pre.hpp@ 361805

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

Added Reaction as Action with a return value.

  • this is derived from Calculation, only that it is not a Process but a simpler Action.
  • A Reaction cannot be undone and sets an internal result.
  • Property mode set to 100644
File size: 7.7 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// some derived names: if CATEGORY is not given, we don't prefix with it
45#ifdef CATEGORY
46#define REACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
47#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
48#define STATE BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, State))
49#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
50#else
51#define REACTION BOOST_PP_CAT(ACTIONNAME, Action)
52#define COMMAND ACTIONNAME
53#define STATE BOOST_PP_CAT(ACTIONNAME, State)
54#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
55#endif
56
57// check if no lists given
58#ifndef paramtypes
59#define MAXPARAMTYPES 0
60#else
61#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
62#endif
63#ifndef statetypes
64#define MAXSTATETYPES 0
65#else
66#define MAXSTATETYPES BOOST_PP_SEQ_SIZE(statetypes)
67#endif
68
69// check user has given name and category
70#ifndef ACTIONNAME
71ERROR: No "ACTIONNAME" defined in: __FILE__
72#endif
73
74// calculate numbers and check whether all have same size
75#ifdef paramtokens
76BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\
77 ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
78)
79#endif
80#ifdef paramreferences
81BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
82 ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
83)
84#endif
85
86#ifdef statetypes
87BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXSTATETYPES, BOOST_PP_SEQ_SIZE(statereferences)),\
88 ERROR: There are not the same number of "statetypes" and "statereferences" in: __FILE__ \
89)
90#endif
91
92// set the return type
93#ifndef returntype
94BOOST_PP_ASSERT_MSG(0,\
95 ERROR: No returntype is defined in __FILE__ \
96)
97#endif
98#define RETURNTYPE returntype
99
100// print a list of type ref followed by a separator, i.e. "int i;"
101#define initialiser_print(z,n,initialiserlist) \
102 BOOST_PP_SEQ_ELEM(n, initialiserlist) \
103 (BOOST_PP_CAT(_, BOOST_PP_SEQ_ELEM(n, initialiserlist))),
104
105// print a list of ref(_ref) followed by a separator, i.e. "id(_id),"
106#define type_print(z,n,TYPELIST, VARLIST, separator) \
107 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
108 BOOST_PP_SEQ_ELEM(n, VARLIST)\
109 separator
110
111// print a list of type ref followed, i.e. "int i, double position"
112#define type_list(z,n,TYPELIST,VARLIST) \
113 BOOST_PP_COMMA_IF(n)\
114 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
115 BOOST_PP_SEQ_ELEM(n, VARLIST)
116
117// prints dialog->query calls for paramtypes with tokens
118#define dialog_print(z,n,unused) \
119 dialog->query<\
120 BOOST_PP_SEQ_ELEM(n, paramtypes)\
121 >(\
122 BOOST_PP_SEQ_ELEM(n, paramtokens)\
123 , Traits.getDescription()\
124 );
125
126// prints set/queryCurrentValue (command) for paramreferences and paramtokens
127#define value_print(z,n,command, prefix) \
128 ValueStorage::getInstance(). command (\
129 BOOST_PP_SEQ_ELEM(n, paramtokens)\
130 , \
131 prefix\
132 BOOST_PP_SEQ_ELEM(n, paramreferences)\
133 );
134
135// prints set/queryCurrentValue (command) for paramreferences and paramtokens
136#define valuetype_print(z,n,command, prefix) \
137 ValueStorage::getInstance(). command< \
138 BOOST_PP_SEQ_ELEM(n, paramtypes) \
139 > (\
140 BOOST_PP_SEQ_ELEM(n, paramtokens)\
141 , \
142 prefix\
143 BOOST_PP_SEQ_ELEM(n, paramreferences)\
144 );
145
146#define stringtype std::string
147
148#define type2string(s, data, elem) \
149 stringtype
150
151
152#include "Actions/ActionRegistry.hpp"
153//#include "Actions/ActionTraits.hpp"
154#include "UIElements/Dialog.hpp"
155
156#ifdef paramtokens
157#define statenecessary 1
158#endif
159#ifndef statetokens
160#define statenecessary 1
161#endif
162
163namespace MoleCuilder {
164
165// =========== constructor ===========
166REACTION::REACTION () :
167 Reaction< RETURNTYPE >(ActionTraits< REACTION >(), false)
168{}
169
170// =========== destructor ===========
171REACTION::~REACTION ()
172{
173 //std::cout << "Action REACTION is being destroyed." << std::endl;
174}
175
176// =========== fill a dialog ===========
177Dialog* REACTION::fillDialog(Dialog *dialog) {
178 ASSERT(dialog,"No Dialog given when filling actionname's dialog");
179#if BOOST_PP_EQUAL(MAXPARAMTYPES,0)
180 dialog->queryEmpty(TOKEN, Traits.getDescription());
181#else
182#define BOOST_PP_LOCAL_MACRO(n) dialog_print(~, n, ~)
183#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
184#include BOOST_PP_LOCAL_ITERATE()
185#endif
186 return dialog;
187};
188
189// =========== command for calling action directly ===========
190RETURNTYPE COMMAND(
191#if defined paramtypes && defined paramreferences
192#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
193#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
194#include BOOST_PP_LOCAL_ITERATE()
195#endif
196)
197{
198 Action *ToCall = ActionRegistry::getInstance().getActionByName( TOKEN ); //->clone(params);
199 //REACTION::PARAMS params;
200#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
201#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, setCurrentValue, )
202#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
203#include BOOST_PP_LOCAL_ITERATE()
204#endif
205 ToCall->call(Action::NonInteractive);
206
207 return static_cast<Reaction< RETURNTYPE > *>(ToCall)->getResult();
208};
209
210RETURNTYPE BOOST_PP_CAT( COMMAND, _stringargs)(
211#if defined paramtypes && defined paramreferences
212#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
213#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
214#include BOOST_PP_LOCAL_ITERATE()
215#endif
216 ) {
217 Action *ToCall = ActionRegistry::getInstance().getActionByName( TOKEN ); //->clone(params);
218 //REACTION::PARAMS params;
219#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
220#define BOOST_PP_LOCAL_MACRO(n) valuetype_print(~, n, setCurrentValueByString, )
221#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
222#include BOOST_PP_LOCAL_ITERATE()
223#endif
224 ToCall->call(MoleCuilder::Action::NonInteractive);
225
226 return static_cast<Reaction< RETURNTYPE > *>(ToCall)->getResult();
227};
228
229// =========== obtain parameters from Storage, used by performCall() ===========
230void REACTION::getParametersfromValueStorage() {
231#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
232#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, queryCurrentValue, params.)
233#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
234#include BOOST_PP_LOCAL_ITERATE()
235#endif
236};
237
238}
239
240// free up defines
241#undef paramtypes
242#undef paramtokens
243#undef paramreferences
244#undef MAXPARAMTYPES
245
246#undef returntype
247#undef RETURNTYPE
248
249#undef type2string
250#undef stringtype
251#undef initialiser_print
252#undef type_print
253#undef type_list
254#undef dialog_print
255#undef value_print
256#undef valuetype_print
257
258#undef REACTION
259#undef COMMAND
260#undef PARAMS
261#undef STATE
262
263#undef ACTIONNAME
264#undef CATEGORY
265#undef TOKEN
Note: See TracBrowser for help on using the repository browser.