source: src/Actions/Action_impl_header.hpp@ 2aad5a

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 2aad5a 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: 8.2 KB
RevLine 
[0b2ce9]1/*
2 * Action_impl_header.hpp
3 *
4 * Created on: Aug 25, 2010
5 * Author: heber
6 */
7
[56f73b]8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
[0b2ce9]13#include <boost/preprocessor/cat.hpp>
14#include <boost/preprocessor/comparison/equal.hpp>
15#include <boost/preprocessor/comparison/not_equal.hpp>
[6ba9ba]16#include <boost/preprocessor/control/expr_if.hpp>
[0b2ce9]17#include <boost/preprocessor/control/if.hpp>
18#include <boost/preprocessor/debug/assert.hpp>
19#include <boost/preprocessor/iteration/local.hpp>
[6ba9ba]20#include <boost/preprocessor/list/adt.hpp>
[0b2ce9]21#include <boost/preprocessor/punctuation/comma_if.hpp>
[6ba9ba]22#include <boost/preprocessor/punctuation/paren.hpp>
[0b2ce9]23#include <boost/preprocessor/repetition/repeat.hpp>
24#include <boost/preprocessor/seq/elem.hpp>
25#include <boost/preprocessor/seq/push_back.hpp>
26#include <boost/preprocessor/seq/seq.hpp>
27#include <boost/preprocessor/seq/size.hpp>
[9ee38b]28#include <boost/preprocessor/seq/transform.hpp>
[0b2ce9]29
[e4afb4]30#include <iostream>
31#include <typeinfo>
32
33#include "Actions/ActionTraits.hpp"
[df32ee]34#include "Actions/ValueStorage.hpp"
35
[f10b0c]36#include "Parameters/Parameter.hpp"
37
[e4afb4]38// some derived names: if CATEGORY is not given, we don't prefix with it
39#ifdef CATEGORY
[0b2ce9]40#define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
41#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
42#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
[e4afb4]43#else
44#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
45#define COMMAND ACTIONNAME
46#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
47#endif
[0b2ce9]48// check if no lists given
[b4fa106]49#ifndef paramtypes
50#define MAXPARAMTYPES 0
[0b2ce9]51#else
[b4fa106]52#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
[0b2ce9]53#endif
[6ba9ba]54#ifndef paramdefaults
55#define MAXPARAMDEFAULTS 0
56// this is required for valid_print "else part"
57#define sequencer(z,n,data) \
58 BOOST_PP_SEQ_PUSH_BACK( data, NOPARAM_DEFAULT)
59#define paramdefaults BOOST_PP_REPEAT( MAXPARAMTYPES, sequencer, BOOST_PP_SEQ_NIL )
60#else
61#define MAXPARAMDEFAULTS BOOST_PP_SEQ_SIZE(paramdefaults)
62#endif
63#define PARAM_DEFAULT(x) \
64 (x, BOOST_PP_NIL)
[0b2ce9]65
66// check user has given name and category
67#ifndef ACTIONNAME
68ERROR: No "ACTIONNAME" defined in: __FILE__
69#endif
70
71// calculate numbers and check whether all have same size
[b4fa106]72#ifdef paramtokens
73BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\
74 ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
[0b2ce9]75)
76#endif
[b4fa106]77#ifdef paramreferences
78BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
79 ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
[0b2ce9]80)
81#endif
[53be34]82#ifdef paramdescriptions
83BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdescriptions)),\
84 ERROR: There are not the same number of "paramtokens" and "paramdescriptions" in: __FILE__ \
85)
86#endif
87
88// check for mandatory defines
89#ifndef DESCRIPTION
90BOOST_PP_ASSERT_MSG(0, \
91 "ERROR: Description is mandatory for Actions, here for ACTION " \
92)
93#endif
[e4afb4]94
[6ba9ba]95// check if paramdefaults is given, otherwise fill list with NOPARAM_DEFAULT
[e4afb4]96// this does not work: paramdefaults has to be completely defined before
97// being used within option_print (used as an array there and not as
98// some function call still to be expanded)
[6ba9ba]99//#define paramdefaults (NOPARAM_DEFAULT)
[e4afb4]100//#define tempvalue(z,n,value)
[6ba9ba]101// BOOST_PP_CAT(value,(NOPARAM_DEFAULT))
[e4afb4]102//BOOST_PP_REPEAT(tempvalue, MAXPARAMTYPES, paramdefaults)
103//#undef tempvalue
104//#else
105
106// if present, check if correct number of arguments
107#ifdef paramdefaults
108BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdefaults)),\
109 ERROR: There are not the same number of "paramtokens" and "paramdefaults" in: __FILE__ \
[53be34]110)
111#endif
[0b2ce9]112
[f10b0c]113// print a list of type ref followed by a separator, i.e. "Parameter<int> i;"
[b4fa106]114#define type_print(z,n,TYPELIST, VARLIST, separator) \
[f10b0c]115 Parameter < \
[b4fa106]116 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
[f10b0c]117 > \
118 BOOST_PP_SEQ_ELEM(n, VARLIST) \
[0b2ce9]119 separator
120
121// print a list of type ref followed, i.e. "int i, double position"
[b4fa106]122#define type_list(z,n,TYPELIST, VARLIST) \
[0b2ce9]123 BOOST_PP_COMMA_IF(n)\
[b4fa106]124 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
125 BOOST_PP_SEQ_ELEM(n, VARLIST)
126
[e4afb4]127// prints Options.insert
128#define option_print(z,n,unused, unused2) \
129 tester = Options. insert (\
130 std::pair< std::string, OptionTrait *> ( \
131 BOOST_PP_SEQ_ELEM(n, paramtokens), \
132 new OptionTrait(\
133 BOOST_PP_SEQ_ELEM(n, paramtokens), \
134 &typeid( BOOST_PP_SEQ_ELEM(n, paramtypes) ), \
[6ba9ba]135 BOOST_PP_SEQ_ELEM(n, paramdescriptions) \
136 BOOST_PP_COMMA_IF( BOOST_PP_NOT( BOOST_PP_LIST_IS_NIL( BOOST_PP_SEQ_ELEM(n, paramdefaults) ) ) ) \
137 BOOST_PP_EXPR_IF( \
138 BOOST_PP_NOT( BOOST_PP_LIST_IS_NIL( BOOST_PP_SEQ_ELEM(n, paramdefaults) ) ), \
139 toString BOOST_PP_LPAREN() \
140 BOOST_PP_LIST_FIRST( BOOST_PP_SEQ_ELEM(n, paramdefaults) )) \
141 BOOST_PP_RPAREN() \
142 )\
[e4afb4]143 )\
144 ); \
145 ASSERT(tester.second, "ActionTrait<ACTION>::ActionTrait<ACTION>() option token present twice!");
[53be34]146
[ce7fdc]147namespace MoleCuilder {
148
[b4fa106]149void COMMAND(
[05736a]150#if defined paramtypes && defined paramreferences
[b4fa106]151#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
152#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
153#include BOOST_PP_LOCAL_ITERATE()
[0b2ce9]154#endif
[05736a]155 );
[0b2ce9]156
[df32ee]157class ACTION;
158
159template <>
[3139b2]160class ActionTraits<ACTION> : public ActionTrait {
[df32ee]161public:
[3139b2]162 ActionTraits() :
[e4afb4]163#ifndef SHORTFORM
[3139b2]164 ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string()))
[e4afb4]165#else
[3139b2]166 ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string(), SHORTFORM))
[e4afb4]167#endif /* SHORTFORM */
[bc2990]168 {
[e4afb4]169 // initialize remainder of action info
[53be34]170#ifdef MENUNAME
171 MenuTitle = MENUNAME;
172#endif
173#ifdef MENUPOSITION
174 MenuPosition = MENUPOSITION;
[24fbf3]175#endif
[e4afb4]176
[6a2dae]177 // initialize action's options
[3139b2]178 std::pair< ActionTrait::options_iterator, bool > tester;
[e4afb4]179#ifdef paramtokens
180#define BOOST_PP_LOCAL_MACRO(n) option_print(~, n, ~, )
181#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
182#include BOOST_PP_LOCAL_ITERATE()
[24fbf3]183#endif
[6a2dae]184 // associate action's short form also with option
[e4afb4]185#ifdef SHORTFORM
[6a2dae]186 if (Options.find(TOKEN) != Options.end())
187 Options[TOKEN]->setShortForm(std::string(SHORTFORM));
[e4afb4]188#endif /* SHORTFORM */
[3139b2]189 //std::cout << "ActionTraits<" << BOOST_PP_STRINGIZE(ACTION) << ">::ActionTraits() on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
[bc2990]190 }
[df32ee]191
[3139b2]192 virtual ~ActionTraits() {
193 //std::cout << "ActionTraits<" << BOOST_PP_STRINGIZE(ACTION) << ">::~ActionTraits() on instance " << this << " with name " << getName() << " called." << std::endl;
194 }
[df32ee]195};
196
[0b2ce9]197class ACTION : public Action {
[b4fa106]198 #if defined paramtypes && defined paramreferences
[e4afb4]199 friend void COMMAND(
[b4fa106]200 #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
201 #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
202 #include BOOST_PP_LOCAL_ITERATE()
203 );
204 # else
205 void COMMAND();
206 #endif
207
[0b2ce9]208public:
209 ACTION();
210 virtual ~ACTION();
211
212 bool canUndo();
213 bool shouldUndo();
214
[9ee38b]215 struct PARAMS : ActionParameters {
[649aaa]216 //!> constructor for class PARAMS, setting valid ranges
217 PARAMS();
218 //!> copy constructor for class PARAMS, setting valid ranges
219 PARAMS(const PARAMS &p);
[b4fa106]220 #if defined paramtypes && defined paramreferences
221 #define BOOST_PP_LOCAL_MACRO(n) type_print(~, n, paramtypes, paramreferences, ;)
222 #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
[9ee38b]223 #include BOOST_PP_LOCAL_ITERATE()
224 #endif
225 } params;
[0b2ce9]226
227protected:
228 virtual Dialog * fillDialog(Dialog*);
[862b6a]229
230 void startTimer() const;
231 void endTimer() const;
232
[0b2ce9]233private:
[f10b0c]234 //virtual void getParametersfromValueStorage();
[0b2ce9]235 virtual Action::state_ptr performCall();
236 virtual Action::state_ptr performUndo(Action::state_ptr);
237 virtual Action::state_ptr performRedo(Action::state_ptr);
238};
239
[ce7fdc]240}
241
[649aaa]242#undef paramvalids
[b4fa106]243#undef paramtypes
244#undef paramtokens
245#undef paramreferences
[e4afb4]246#undef paramdescriptions
247#undef paramdefaults
[b4fa106]248#undef MAXPARAMTYPES
[6ba9ba]249#undef MAXPARAMDEFAULTS
[b4fa106]250#undef statetypes
251#undef statereferences
252#undef MAXSTATETYPES
[6ba9ba]253#undef PARAM_DEFAULT
[9ee38b]254
[a02f78]255#undef option_print
[6ba9ba]256#undef sequencer
[a02f78]257#undef type_print
258#undef type_list
259
[9ee38b]260#undef ACTION
261#undef COMMAND
262#undef COMMANDFULL
263#undef PARAMS
[b4fa106]264
265#undef ACTIONNAME
266#undef CATEGORY
[e4afb4]267#undef MENUNAME
268#undef MENUPOSITION
[9ee38b]269#undef TOKEN
[e4afb4]270
271#undef DESCRIPTION
272#undef SHORTFORM
Note: See TracBrowser for help on using the repository browser.