source: src/Actions/Action_impl_header.hpp@ ab2ebe

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 ab2ebe 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
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>
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>
[9ee38b]25#include <boost/preprocessor/seq/transform.hpp>
[0b2ce9]26
[e4afb4]27#include <iostream>
28#include <typeinfo>
29
30#include "Actions/ActionTraits.hpp"
[df32ee]31#include "Actions/ValueStorage.hpp"
32
[f10b0c]33#include "Parameters/Parameter.hpp"
34
[e4afb4]35// some derived names: if CATEGORY is not given, we don't prefix with it
36#ifdef CATEGORY
[0b2ce9]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))
[e4afb4]40#else
41#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
42#define COMMAND ACTIONNAME
43#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
44#endif
[0b2ce9]45// check if no lists given
[b4fa106]46#ifndef paramtypes
47#define MAXPARAMTYPES 0
[0b2ce9]48#else
[b4fa106]49#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
[0b2ce9]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
[b4fa106]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__ \
[0b2ce9]61)
62#endif
[b4fa106]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__ \
[0b2ce9]66)
67#endif
[53be34]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
[e4afb4]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__ \
[53be34]96)
97#endif
[0b2ce9]98
[f10b0c]99// print a list of type ref followed by a separator, i.e. "Parameter<int> i;"
[b4fa106]100#define type_print(z,n,TYPELIST, VARLIST, separator) \
[f10b0c]101 Parameter < \
[b4fa106]102 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
[f10b0c]103 > \
104 BOOST_PP_SEQ_ELEM(n, VARLIST) \
[0b2ce9]105 separator
106
107// print a list of type ref followed, i.e. "int i, double position"
[b4fa106]108#define type_list(z,n,TYPELIST, VARLIST) \
[0b2ce9]109 BOOST_PP_COMMA_IF(n)\
[b4fa106]110 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
111 BOOST_PP_SEQ_ELEM(n, VARLIST)
112
[e4afb4]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), \
[d1115d]123 std::string( BOOST_PP_SEQ_ELEM(n, paramdefaults) ) )\
[e4afb4]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
[53be34]141
[ce7fdc]142namespace MoleCuilder {
143
[b4fa106]144void COMMAND(
[05736a]145#if defined paramtypes && defined paramreferences
[b4fa106]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()
[0b2ce9]149#endif
[05736a]150 );
[0b2ce9]151
[df32ee]152class ACTION;
153
154template <>
[3139b2]155class ActionTraits<ACTION> : public ActionTrait {
[df32ee]156public:
[3139b2]157 ActionTraits() :
[e4afb4]158#ifndef SHORTFORM
[3139b2]159 ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string()))
[e4afb4]160#else
[3139b2]161 ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string(), SHORTFORM))
[e4afb4]162#endif /* SHORTFORM */
[bc2990]163 {
[e4afb4]164 // initialize remainder of action info
[53be34]165#ifdef MENUNAME
166 MenuTitle = MENUNAME;
167#endif
168#ifdef MENUPOSITION
169 MenuPosition = MENUPOSITION;
[24fbf3]170#endif
[e4afb4]171
[6a2dae]172 // initialize action's options
[3139b2]173 std::pair< ActionTrait::options_iterator, bool > tester;
[e4afb4]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()
[24fbf3]178#endif
[6a2dae]179 // associate action's short form also with option
[e4afb4]180#ifdef SHORTFORM
[6a2dae]181 if (Options.find(TOKEN) != Options.end())
182 Options[TOKEN]->setShortForm(std::string(SHORTFORM));
[e4afb4]183#endif /* SHORTFORM */
[3139b2]184 //std::cout << "ActionTraits<" << BOOST_PP_STRINGIZE(ACTION) << ">::ActionTraits() on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
[bc2990]185 }
[df32ee]186
[3139b2]187 virtual ~ActionTraits() {
188 //std::cout << "ActionTraits<" << BOOST_PP_STRINGIZE(ACTION) << ">::~ActionTraits() on instance " << this << " with name " << getName() << " called." << std::endl;
189 }
[df32ee]190};
191
[0b2ce9]192class ACTION : public Action {
[b4fa106]193 #if defined paramtypes && defined paramreferences
[e4afb4]194 friend void COMMAND(
[b4fa106]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
[0b2ce9]203public:
204 ACTION();
205 virtual ~ACTION();
206
207 bool canUndo();
208 bool shouldUndo();
209
[9ee38b]210 struct PARAMS : ActionParameters {
[649aaa]211 //!> constructor for class PARAMS, setting valid ranges
212 PARAMS();
213 //!> copy constructor for class PARAMS, setting valid ranges
214 PARAMS(const PARAMS &p);
[b4fa106]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)
[9ee38b]218 #include BOOST_PP_LOCAL_ITERATE()
219 #endif
220 } params;
[0b2ce9]221
222protected:
223 virtual Dialog * fillDialog(Dialog*);
[862b6a]224
225 void startTimer() const;
226 void endTimer() const;
227
[0b2ce9]228private:
[f10b0c]229 //virtual void getParametersfromValueStorage();
[0b2ce9]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
[ce7fdc]235}
236
[649aaa]237#undef paramvalids
[b4fa106]238#undef paramtypes
239#undef paramtokens
240#undef paramreferences
[e4afb4]241#undef paramdescriptions
242#undef paramdefaults
[b4fa106]243#undef MAXPARAMTYPES
244#undef statetypes
245#undef statereferences
246#undef MAXSTATETYPES
[9ee38b]247
[a02f78]248#undef option_print
249#undef type_print
250#undef type_list
251
[9ee38b]252#undef ACTION
253#undef COMMAND
254#undef COMMANDFULL
255#undef PARAMS
[b4fa106]256
257#undef ACTIONNAME
258#undef CATEGORY
[e4afb4]259#undef MENUNAME
260#undef MENUPOSITION
[9ee38b]261#undef TOKEN
[e4afb4]262
263#undef DESCRIPTION
264#undef SHORTFORM
Note: See TracBrowser for help on using the repository browser.