source: src/Actions/Action_impl_python.hpp@ 72a4c1

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 72a4c1 was 6ba9ba, checked in by Frederik Heber <heber@…>, 13 years ago

Default values are properly set by the Action into their (Action)Parameters.

  • we changed the boost::preprocessor magic to accomplish this.
  • NODEFAULT -> NOPARAM_DEFAULT to be safe.
  • it has been a hell of a lot of work to make it possible to add a construct such as ", default" to the call of a function, either the comma or the default is easy but both could only be accomplished via a list contained in the sequence of default values. Because the list has an explicit NIL element which is taken as NOPARAM_DEFAULT.
  • PARAM_DEFAULT is a macro to wrap the default value into a list.
  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Action_impl_python.hpp
3 *
4 * Created on: Sep 25, 2011
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include <boost/preprocessor/cat.hpp>
14#include <boost/preprocessor/comparison/equal.hpp>
15#include <boost/preprocessor/control/if.hpp>
16#include <boost/preprocessor/control/expr_if.hpp>
17#include <boost/preprocessor/debug/assert.hpp>
18#include <boost/preprocessor/facilities/expand.hpp>
19#include <boost/preprocessor/iteration/local.hpp>
20#include <boost/preprocessor/list/adt.hpp>
21#include <boost/preprocessor/punctuation/comma_if.hpp>
22#include <boost/preprocessor/punctuation/paren.hpp>
23
24// some derived names: if CATEGORY is not given, we don't prefix with it
25#ifdef CATEGORY
26#define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
27#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
28#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
29#else
30#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
31#define COMMAND ACTIONNAME
32#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
33#endif
34
35// for paramdefaults entries
36#define PARAM_DEFAULT(x) \
37 (x, BOOST_PP_NIL)
38
39// check if no lists given
40#ifndef paramtokens
41#define MAXPARAMTYPES 0
42#else
43#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtokens)
44#endif
45
46// calculate numbers and check whether all have same size
47#ifdef paramtokens
48BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdescriptions)),\
49 ERROR: There are not the same number of "paramtokens" and "paramdescriptions" in: __FILE__ \
50)
51#endif
52
53// print a list of "action separator description linenend, i.e. "Action - descrption\n"
54#define help_print(z,n,TYPELIST, VARLIST, separator, lineend) \
55 BOOST_PP_IF(n, +, BOOST_PP_EMPTY()) \
56 "\t" + std::string( BOOST_PP_SEQ_ELEM(n, TYPELIST) ) + \
57 std::string( separator ) + \
58 std::string( BOOST_PP_SEQ_ELEM(n, VARLIST) ) + \
59 std::string( lineend )
60
61// print a list of comma-separated list, i.e. (,)arg("Action")=default
62#define stringdefault_print(z,n,STRINGLIST, DEFAULTLIST) \
63 BOOST_PP_COMMA_IF(n) \
64 boost::python::arg( \
65 BOOST_PP_SEQ_ELEM(n, STRINGLIST) \
66 ) \
67 = \
68 BOOST_PP_IF( \
69 BOOST_PP_NOT( BOOST_PP_LIST_IS_NIL( BOOST_PP_SEQ_ELEM(n, paramdefaults) ) ), \
70 toString BOOST_PP_LPAREN() \
71 BOOST_PP_LIST_FIRST( BOOST_PP_SEQ_ELEM(n, DEFAULTLIST) ) \
72 BOOST_PP_RPAREN(), \
73 std::string("") \
74 )
75
76// print a list of comma-separated list, i.e. (,)arg("Action")
77#define string_print(z,n,STRINGLIST) \
78 BOOST_PP_COMMA_IF(n) \
79 boost::python::arg( \
80 BOOST_PP_SEQ_ELEM(n, STRINGLIST) \
81 )
82
83// print a list of type ref followed, i.e. "int i, double position"
84#define type_list(z,n,TYPELIST, VARLIST) \
85 BOOST_PP_COMMA_IF(n)\
86 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
87 BOOST_PP_SEQ_ELEM(n, VARLIST)
88
89// prints set/queryCurrentValue (command) for paramreferences and paramtokens
90#define value_print(z,n,command, prefix) \
91 ValueStorage::getInstance(). command (\
92 BOOST_PP_SEQ_ELEM(n, paramtokens)\
93 , \
94 prefix\
95 BOOST_PP_SEQ_ELEM(n, paramreferences)\
96 );
97
98#define stringtype std::string
99
100#define type2string(s, data, elem) \
101 stringtype
102
103#include "Actions/Action.hpp"
104#include "Actions/ActionRegistry.hpp"
105#include "Actions/ValueStorage.hpp"
106
107namespace MoleCuilder {
108#ifdef returntype
109 returntype
110#else
111 void
112#endif
113BOOST_PP_CAT( COMMAND, _stringargs)(
114#if defined paramtypes
115#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
116#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
117#include BOOST_PP_LOCAL_ITERATE()
118#endif
119 );
120}
121
122void BOOST_PP_CAT(export_, COMMAND)()
123{
124 std::string docstring =
125 std::string( DESCRIPTION ) + "\n\n"
126#if defined paramtokens && defined paramdescriptions
127#define BOOST_PP_LOCAL_MACRO(n) help_print(~, n, paramtokens, paramdescriptions, " - ", "\n")
128#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
129#include BOOST_PP_LOCAL_ITERATE()
130#endif
131 ;
132 boost::python::def(
133 BOOST_PP_STRINGIZE(COMMAND),
134 MoleCuilder:: BOOST_PP_CAT( COMMAND, _stringargs)
135#if defined paramtokens // do we have parameters at all?
136 ,(
137#if defined paramdefaults
138#define BOOST_PP_LOCAL_MACRO(n) stringdefault_print(~, n, paramtokens, paramdefaults)
139#else
140#define BOOST_PP_LOCAL_MACRO(n) string_print(~, n, paramtokens)
141#endif
142#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
143#include BOOST_PP_LOCAL_ITERATE()
144 ), docstring.c_str()
145#else
146 , DESCRIPTION
147#endif
148 );
149}
150
151#undef COMMAND
152#undef ACTION
153#undef PARAMS
154#undef MAXPARAMTYPES
155#undef PARAM_DEFAULT
156
157#undef help_print
158#undef string_print
159#undef stringdefault_print
160#undef type_list
161#undef value_print
162
163#undef type2string
164#undef stringtype
Note: See TracBrowser for help on using the repository browser.