source: src/Actions/Action_impl_pre.hpp@ 46b181

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

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

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