source: src/Actions/Action_impl_header.hpp@ 361805

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 361805 was 649aaa, checked in by Frederik Heber <heber@…>, 13 years ago

All Actions' .def files now have a paramvalids that is used to for validators of their Parameters.

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