source: src/Actions/Reaction_impl_pre.hpp@ bad589

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 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 bad589 was 46b181, checked in by Frederik Heber <heber@…>, 12 years ago

Added Action::outputAsCLI() and ActionQueue::outputAsCLI().

  • prints sequence of Actions along with their options.
  • Property mode set to 100644
File size: 9.1 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 command line call for this Action for paramtypes with tokens
129#define outputAsCLI_print(z,n,output) \
130 output << \
131 BOOST_PP_IF(n, BOOST_PP_STRINGIZE( ) , BOOST_PP_STRINGIZE() ) \
132 << "--" << \
133 BOOST_PP_SEQ_ELEM(n, paramtokens) \
134 << " \"" << params. \
135 BOOST_PP_SEQ_ELEM(n, paramreferences) \
136 .get() \
137 << "\"";
138
139// prints if statement to check two strings (paramtokens[n] vs. TOKEN)
140#define checkpresenttoken_print(z, n, TOKEN, booltoken) \
141 if ( std::string(\
142 BOOST_PP_SEQ_ELEM(n, paramtokens) )\
143 == getName()) \
144 booltoken = false;
145
146// prints set/queryCurrentValue (command) for paramreferences and paramtokens
147#define value_print(z, n, container, prefix) \
148 prefix \
149 BOOST_PP_SEQ_ELEM(n, container)\
150 .set(\
151 BOOST_PP_SEQ_ELEM(n, container)\
152 );
153
154// prints set/queryCurrentValue (command) for paramreferences and paramtokens
155#define valuetype_print(z,n,container, types, prefix) \
156 prefix \
157 BOOST_PP_SEQ_ELEM(n, container) \
158 .setAsString( \
159 BOOST_PP_SEQ_ELEM(n, container) \
160 );
161
162#define stringtype std::string
163
164#define type2string(s, data, elem) \
165 stringtype
166
167
168#include "Actions/ActionRegistry.hpp"
169//#include "Actions/ActionTraits.hpp"
170#include "UIElements/Dialog.hpp"
171
172#ifdef paramtokens
173#define statenecessary 1
174#endif
175#ifndef statetokens
176#define statenecessary 1
177#endif
178
179namespace MoleCuilder {
180
181// =========== constructor ===========
182REACTION::REACTION () :
183 Reaction< RETURNTYPE >(ActionTraits< REACTION >())
184{}
185
186// =========== destructor ===========
187REACTION::~REACTION ()
188{
189 //std::cout << "Action REACTION is being destroyed." << std::endl;
190}
191
192// =========== fill a dialog ===========
193Dialog* REACTION::fillDialog(Dialog *dialog) {
194 ASSERT(dialog,"No Dialog given when filling actionname's dialog");
195#if BOOST_PP_EQUAL(MAXPARAMTYPES,0)
196 dialog->queryEmpty(TOKEN, Traits.getDescription());
197#else
198#define BOOST_PP_LOCAL_MACRO(n) dialog_print(~, n, ~)
199#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
200#include BOOST_PP_LOCAL_ITERATE()
201#endif
202 return dialog;
203};
204
205// =========== output as CLI ===========
206void REACTION::outputAsCLI(std::ostream &ost) const {
207 // check whether TOKEN is also an option
208 // is a bit ugly as preprocessor cannot compare strings
209 bool status = true;
210#if defined paramtokens && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
211#define BOOST_PP_LOCAL_MACRO(n) checkpresenttoken_print(~, n, TOKEN, status)
212#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
213#include BOOST_PP_LOCAL_ITERATE()
214#endif
215 if (status) { ost << "--" << TOKEN; }
216 // then print option along with each argument if set
217#if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
218#define BOOST_PP_LOCAL_MACRO(n) outputAsCLI_print(~, n, ost)
219#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
220#include BOOST_PP_LOCAL_ITERATE()
221#endif
222}
223
224// =========== command for calling action directly ===========
225RETURNTYPE COMMAND(
226#if defined paramtypes && defined paramreferences
227#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
228#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
229#include BOOST_PP_LOCAL_ITERATE()
230#endif
231)
232{
233 Action *ToCall = ActionQueue::getInstance().getActionByName( TOKEN ); //->clone(params);
234 //REACTION::PARAMS params;
235#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
236#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, setCurrentValue, )
237#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
238#include BOOST_PP_LOCAL_ITERATE()
239#endif
240 ActionQueue::getInstance().queueAction( ToCall, Action::NonInteractive);
241 Reaction< RETURNTYPE > * resultaction = static_cast<Reaction< RETURNTYPE > *>(ToCall);
242 ASSERT( resultaction != NULL,
243 " COMMAND - static cast to Reaction type failed.");
244 ASSERT( resultaction->hasResult (),
245 " _COMMAND - result is not done yet?");
246 return resultaction->getResult();
247};
248
249RETURNTYPE BOOST_PP_CAT( COMMAND, _stringargs)(
250#if defined paramtypes && defined paramreferences
251#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
252#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
253#include BOOST_PP_LOCAL_ITERATE()
254#endif
255 ) {
256 Action *ToCall = ActionQueue::getInstance().getActionByName( TOKEN ); //->clone(params);
257 //REACTION::PARAMS params;
258#if BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
259#define BOOST_PP_LOCAL_MACRO(n) valuetype_print(~, n, setCurrentValueByString, )
260#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
261#include BOOST_PP_LOCAL_ITERATE()
262#endif
263 ActionQueue::getInstance().queueAction( ToCall, Action::NonInteractive);
264 Reaction< RETURNTYPE > * resultaction = static_cast<Reaction< RETURNTYPE > *>(ToCall);
265 ASSERT( resultaction != NULL,
266 " COMMAND - static cast to Reaction type failed.");
267 ASSERT( resultaction->hasResult (),
268 " _COMMAND - result is not done yet?");
269 return resultaction->getResult();
270};
271
272}
273
274// free up defines
275#undef paramtypes
276#undef paramtokens
277#undef paramreferences
278#undef MAXPARAMTYPES
279
280#undef returntype
281#undef RETURNTYPE
282
283#undef type2string
284#undef stringtype
285#undef initialiser_print
286#undef type_print
287#undef type_list
288#undef dialog_print
289#undef value_print
290#undef valuetype_print
291
292#undef REACTION
293#undef COMMAND
294#undef PARAMS
295#undef STATE
296
297#undef ACTIONNAME
298#undef CATEGORY
299#undef TOKEN
Note: See TracBrowser for help on using the repository browser.