source: src/Actions/MakroAction_impl_pre.hpp@ 9e4655

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 9e4655 was f6ff216, checked in by Frederik Heber <heber@…>, 11 years ago

FIX: Removed " " around every printed parameter.

  • Property mode set to 100644
File size: 13.6 KB
Line 
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
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 "CodePatterns/Chronos.hpp"
34
35#include <boost/preprocessor/cat.hpp>
36#include <boost/preprocessor/expand.hpp>
37#include <boost/preprocessor/comparison/equal.hpp>
38#include <boost/preprocessor/comparison/not_equal.hpp>
39#include <boost/preprocessor/control/expr_if.hpp>
40#include <boost/preprocessor/control/if.hpp>
41#include <boost/preprocessor/debug/assert.hpp>
42#include <boost/preprocessor/iteration/local.hpp>
43#include <boost/preprocessor/list/adt.hpp>
44#include <boost/preprocessor/punctuation/comma_if.hpp>
45#include <boost/preprocessor/repetition/repeat.hpp>
46#include <boost/preprocessor/seq/elem.hpp>
47#include <boost/preprocessor/seq/push_back.hpp>
48#include <boost/preprocessor/seq/seq.hpp>
49#include <boost/preprocessor/seq/size.hpp>
50#include <boost/preprocessor/seq/transform.hpp>
51
52#include "Actions/ActionQueue.hpp"
53#include "Actions/toCLIString.hpp"
54#include "Parameters/Parameter.hpp"
55
56
57// some derived names: if CATEGORY is not given, we don't prefix with it
58#ifdef CATEGORY
59#define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
60#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
61#define STATE BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, State))
62#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
63#else
64#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
65#define COMMAND ACTIONNAME
66#define STATE BOOST_PP_CAT(ACTIONNAME, State)
67#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
68#endif
69#define INSTANCE BOOST_PP_CAT(this_, BOOST_PP_CAT(ACTIONNAME, _instance))
70
71// check if no lists given
72#ifndef paramtypes
73#define MAXPARAMTYPES 0
74#else
75#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
76#endif
77#ifndef statetypes
78#define MAXSTATETYPES 0
79#else
80#define MAXSTATETYPES BOOST_PP_SEQ_SIZE(statetypes)
81#endif
82#ifndef paramdefaults
83#define MAXPARAMDEFAULTS 0
84// this is required for valid_print "else part"
85#define sequencer(z,n,data) \
86 BOOST_PP_SEQ_PUSH_BACK( data, NOPARAM_DEFAULT)
87#define paramdefaults BOOST_PP_REPEAT( MAXPARAMTYPES, sequencer, BOOST_PP_SEQ_NIL )
88#else
89#define MAXPARAMDEFAULTS BOOST_PP_SEQ_SIZE(paramdefaults)
90#endif
91#define PARAM_DEFAULT(x) \
92 (x, BOOST_PP_NIL)
93
94// check user has given name and category
95#ifndef ACTIONNAME
96ERROR: No "ACTIONNAME" defined in: __FILE__
97#endif
98
99// calculate numbers and check whether all have same size
100#ifdef paramtokens
101BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\
102 ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
103)
104#endif
105#ifdef paramreferences
106BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
107 ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
108)
109#endif
110
111#ifdef statetypes
112BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXSTATETYPES, BOOST_PP_SEQ_SIZE(statereferences)),\
113 ERROR: There are not the same number of "statetypes" and "statereferences" in: __FILE__ \
114)
115#endif
116
117// print a list of type ref followed by a separator, i.e. "int i;"
118#define initialiser_print(z,n,initialiserlist) \
119 BOOST_PP_SEQ_ELEM(n, initialiserlist) \
120 (BOOST_PP_CAT(_, BOOST_PP_SEQ_ELEM(n, initialiserlist))),
121
122// print a list of ref(_ref) followed by a separator, i.e. "id(_id),"
123#define type_print(z,n,TYPELIST, VARLIST, separator) \
124 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
125 BOOST_PP_SEQ_ELEM(n, VARLIST)\
126 separator
127
128// print a list of type ref followed, i.e. "int i, double position"
129#define type_list(z,n,TYPELIST,VARLIST) \
130 BOOST_PP_COMMA_IF(n)\
131 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
132 BOOST_PP_SEQ_ELEM(n, VARLIST)
133
134// prints dialog->query calls for paramtypes with tokens
135#define dialog_print(z,n,unused) \
136 dialog->query<\
137 BOOST_PP_SEQ_ELEM(n, paramtypes)\
138 >( params. \
139 BOOST_PP_SEQ_ELEM(n, paramreferences)\
140 ,\
141 BOOST_PP_SEQ_ELEM(n, paramtokens)\
142 , Traits.getDescription()\
143 );
144
145// prints command line call for this Action for paramtypes with tokens
146#define outputAsCLI_print(z,n,output) \
147 output << \
148 BOOST_PP_IF(n, " --", "--") \
149 << \
150 BOOST_PP_SEQ_ELEM(n, paramtokens) \
151 << " " << toCLIString(params. \
152 BOOST_PP_SEQ_ELEM(n, paramreferences) \
153 .get());
154
155// prints if statement to check two strings (paramtokens[n] vs. TOKEN)
156#define checkpresenttoken_print(z, n, TOKEN, booltoken) \
157 if ( std::string(\
158 BOOST_PP_SEQ_ELEM(n, paramtokens) )\
159 == getName()) \
160 booltoken = false;
161
162// prints command line call for this Action for paramtypes with tokens
163#define outputAsPython_print(z,n,output) \
164 output << \
165 BOOST_PP_IF(n, ", ", "") \
166 << "\"" << toCLIString(params. \
167 BOOST_PP_SEQ_ELEM(n, paramreferences) \
168 .get()) \
169 << "\"";
170
171// print an initialiser list, i.e. "var( token, valid (,default) )(,)"
172#define valid_print(z,n,TOKENLIST, VARLIST, VALIDLIST, DEFAULTLIST) \
173 BOOST_PP_COMMA_IF(n) \
174 BOOST_PP_SEQ_ELEM(n, VARLIST) \
175 ( \
176 BOOST_PP_SEQ_ELEM(n, TOKENLIST) \
177 , \
178 BOOST_PP_SEQ_ELEM(n, VALIDLIST) \
179 BOOST_PP_COMMA_IF( BOOST_PP_NOT( BOOST_PP_LIST_IS_NIL( BOOST_PP_SEQ_ELEM(n, DEFAULTLIST) ) ) ) \
180 BOOST_PP_EXPR_IF( \
181 BOOST_PP_NOT( BOOST_PP_LIST_IS_NIL( BOOST_PP_SEQ_ELEM(n, DEFAULTLIST) ) ), \
182 BOOST_PP_LIST_FIRST( BOOST_PP_SEQ_ELEM(n, DEFAULTLIST) )) \
183 )
184
185// print an initialiser list, i.e. "var( valid . var )(,)"
186#define validcopy_print(z,n,TOKENLIST, VARLIST, VALID) \
187 BOOST_PP_COMMA_IF(n) \
188 BOOST_PP_SEQ_ELEM(n, VARLIST) \
189 ( \
190 VALID . \
191 BOOST_PP_SEQ_ELEM(n, VARLIST) \
192 )
193
194// prints set/queryCurrentValue (command) for paramreferences and paramtokens
195#define value_print(z, n, container, prefix) \
196 prefix \
197 BOOST_PP_SEQ_ELEM(n, container)\
198 .set(\
199 BOOST_PP_SEQ_ELEM(n, container)\
200 );
201
202// prints set/queryCurrentValue (command) for paramreferences and paramtokens
203#define valuetype_print(z,n,container, types, prefix) \
204 prefix \
205 BOOST_PP_SEQ_ELEM(n, container) \
206 .setAsString( \
207 BOOST_PP_SEQ_ELEM(n, container) \
208 );
209
210#define stringtype std::string
211
212#define type2string(s, data, elem) \
213 stringtype
214
215
216#include "Actions/ActionRegistry.hpp"
217//#include "Actions/ActionTraits.hpp"
218#include "UIElements/Dialog.hpp"
219
220#ifdef paramtokens
221#define statenecessary 1
222#endif
223#ifndef statetokens
224#define statenecessary 1
225#endif
226
227namespace MoleCuilder {
228
229// =========== memento to remember the state when undoing ===========
230#ifdef statenecessary
231class STATE : public ActionState {
232public:
233 STATE(
234#if defined statetypes && defined statereferences // if we have parameters, we have to add "_" before each reference and add the params as the last one
235#define OP(s,data,elem) BOOST_PP_CAT(data, elem) // OP to add "_"
236#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)))
237#else /// if not, params is only list
238#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, (const ACTION::PARAMS &), (_params))
239#endif
240#define BOOST_PP_LOCAL_LIMITS (0, MAXSTATETYPES)
241#include BOOST_PP_LOCAL_ITERATE()
242) :
243#if defined statetypes && defined statereferences // do we have parameters at all?
244BOOST_PP_REPEAT(MAXSTATETYPES, initialiser_print, statereferences)
245#endif
246params(_params)
247 {}
248
249#if defined statetypes && defined statereferences // do we have parameters at all?
250#define BOOST_PP_LOCAL_MACRO(n) type_print(~, n, statetypes, statereferences, ;)
251#define BOOST_PP_LOCAL_LIMITS (0, MAXSTATETYPES-1)
252#include BOOST_PP_LOCAL_ITERATE()
253#endif
254 ACTION::PARAMS params;
255};
256#endif /* statenecessary */
257
258// (const) prototype to be placed into the ActionRegistry (must be deleted by registry itself)
259//const ACTION INSTANCE;
260//boost::shared_ptr< ACTION > INSTANCE( new ACTION() );
261
262// =========== constructor ===========
263ACTION::ACTION () :
264 MakroAction(ActionTraits< ACTION >(), actions)
265{}
266
267// =========== destructor ===========
268ACTION::~ACTION ()
269{
270 //std::cout << "Action ACTION is being destroyed." << std::endl;
271}
272
273// =========== parameter constructor ===========
274ACTION::PARAMS::PARAMS()
275#if defined paramtokens && defined paramreferences && defined paramvalids
276 :
277#define BOOST_PP_LOCAL_MACRO(n) valid_print(~, n, paramtokens, paramreferences, paramvalids, paramdefaults)
278#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
279#include BOOST_PP_LOCAL_ITERATE()
280#endif
281 {}
282
283ACTION::PARAMS::PARAMS(const PARAMS &p)
284#if defined paramtokens && defined paramreferences
285 :
286#define BOOST_PP_LOCAL_MACRO(n) validcopy_print(~, n, paramtokens, paramreferences, p)
287#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
288#include BOOST_PP_LOCAL_ITERATE()
289#endif
290 {}
291
292// =========== fill a dialog ===========
293Dialog* ACTION::fillDialog(Dialog *dialog) {
294 ASSERT(dialog,"No Dialog given when filling actionname's dialog");
295#if BOOST_PP_EQUAL(MAXPARAMTYPES,0)
296 dialog->queryEmpty(TOKEN, Traits.getDescription());
297#else
298#define BOOST_PP_LOCAL_MACRO(n) dialog_print(~, n, ~)
299#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
300#include BOOST_PP_LOCAL_ITERATE()
301#endif
302 return dialog;
303};
304
305// =========== output as CLI ===========
306void ACTION::outputAsCLI(std::ostream &ost) const {
307 // check whether TOKEN is also an option
308 // is a bit ugly as preprocessor cannot compare strings
309 bool status = true;
310#if defined paramtokens && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
311#define BOOST_PP_LOCAL_MACRO(n) checkpresenttoken_print(~, n, TOKEN, status)
312#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
313#include BOOST_PP_LOCAL_ITERATE()
314#endif
315 if (status) {
316 ost << "--" << TOKEN;
317#if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
318 ost << " ";
319#endif
320 }
321 // then print option along with each argument if set
322#if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
323#define BOOST_PP_LOCAL_MACRO(n) outputAsCLI_print(~, n, ost)
324#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
325#include BOOST_PP_LOCAL_ITERATE()
326#endif
327}
328
329// =========== output as PYTHTON ===========
330void ACTION::outputAsPython(std::ostream &ost, const std::string &prefix) const {
331 // print prefix and action command
332 ost << prefix << "." << BOOST_PP_STRINGIZE( COMMAND ) << "(";
333 // then print option along with each argument if set
334#if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
335#define BOOST_PP_LOCAL_MACRO(n) outputAsCLI_print(~, n, ost)
336#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
337#include BOOST_PP_LOCAL_ITERATE()
338#endif
339 ost << ")" << std::endl;
340}
341
342// =========== time the action ===========
343// we need this here to have the correct function name
344void ACTION::startTimer() const { Chronos::getInstance().startTiming( std::string( TOKEN ) ); }
345void ACTION::endTimer() const { Chronos::getInstance().endTiming( std::string( TOKEN ) ); }
346
347// =========== command for calling action directly ===========
348void COMMAND(
349#if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
350#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
351#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
352#include BOOST_PP_LOCAL_ITERATE()
353#endif
354)
355{
356 ACTION *ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN )); //->clone(params);
357 //ACTION::PARAMS params;
358#if defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
359#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, paramreferences, ToCall->params.)
360#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
361#include BOOST_PP_LOCAL_ITERATE()
362#endif
363 ActionQueue::getInstance().queueAction( ToCall, Action::NonInteractive);
364};
365
366void BOOST_PP_CAT( COMMAND, _stringargs)(
367#if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
368#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
369#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
370#include BOOST_PP_LOCAL_ITERATE()
371#endif
372 ) {
373 ACTION *ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN )); //->clone(params);
374 //ACTION::PARAMS params;
375#if defined paramtypes && defined paramtypes && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
376#define BOOST_PP_LOCAL_MACRO(n) valuetype_print(~, n, paramreferences, paramtypes, ToCall->params. )
377#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
378#include BOOST_PP_LOCAL_ITERATE()
379#endif
380 ActionQueue::getInstance().queueAction( ToCall, Action::NonInteractive);
381};
382
383}
384
385// free up defines
386#undef paramvalids
387#undef paramtypes
388#undef paramtokens
389#undef paramreferences
390#undef paramdescriptions
391#undef paramdefaults
392#undef MAXPARAMTYPES
393#undef MAXPARAMDEFAULTS
394#undef statetypes
395#undef statereferences
396#undef MAXSTATETYPES
397#undef PARAM_DEFAULT
398
399#undef type2string
400#undef stringtype
401#undef initialiser_print
402#undef type_print
403#undef type_list
404#undef dialog_print
405#undef sequencer
406#undef valid_print
407#undef validcopy_print
408#undef value_print
409#undef valuetype_print
410
411#undef ACTION
412#undef COMMAND
413#undef PARAMS
414#undef STATE
415#undef INSTANCE
416
417#undef ACTIONNAME
418#undef CATEGORY
419#undef TOKEN
Note: See TracBrowser for help on using the repository browser.