source: src/Actions/Action_impl_header.hpp@ 071243

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 Candidate_v1.7.0 Candidate_v1.7.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 071243 was 6a2dae, checked in by Frederik Heber <heber@…>, 14 years ago

Corrected indenting in ActionTrait<>s cstor.

  • Property mode set to 100644
File size: 7.4 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"
31#include "Actions/OptionTrait.hpp"
[df32ee]32#include "Actions/ValueStorage.hpp"
33
[e4afb4]34// some derived names: if CATEGORY is not given, we don't prefix with it
35#ifdef CATEGORY
[0b2ce9]36#define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
37#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
38#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
[e4afb4]39#else
40#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
41#define COMMAND ACTIONNAME
42#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
43#endif
[0b2ce9]44// check if no lists given
[b4fa106]45#ifndef paramtypes
46#define MAXPARAMTYPES 0
[0b2ce9]47#else
[b4fa106]48#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
[0b2ce9]49#endif
50
51// check user has given name and category
52#ifndef ACTIONNAME
53ERROR: No "ACTIONNAME" defined in: __FILE__
54#endif
55
56// calculate numbers and check whether all have same size
[b4fa106]57#ifdef paramtokens
58BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtokens)),\
59 ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
[0b2ce9]60)
61#endif
[b4fa106]62#ifdef paramreferences
63BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
64 ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
[0b2ce9]65)
66#endif
[53be34]67#ifdef paramdescriptions
68BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdescriptions)),\
69 ERROR: There are not the same number of "paramtokens" and "paramdescriptions" in: __FILE__ \
70)
71#endif
72
73// check for mandatory defines
74#ifndef DESCRIPTION
75BOOST_PP_ASSERT_MSG(0, \
76 "ERROR: Description is mandatory for Actions, here for ACTION " \
77)
78#endif
[e4afb4]79
80// check if paramdefaults is given, otherwise fill list with NODEFAULT
81// this does not work: paramdefaults has to be completely defined before
82// being used within option_print (used as an array there and not as
83// some function call still to be expanded)
84//#define paramdefaults (NODEFAULT)
85//#define tempvalue(z,n,value)
86// BOOST_PP_CAT(value,(NODEFAULT))
87//BOOST_PP_REPEAT(tempvalue, MAXPARAMTYPES, paramdefaults)
88//#undef tempvalue
89//#else
90
91// if present, check if correct number of arguments
92#ifdef paramdefaults
93BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdefaults)),\
94 ERROR: There are not the same number of "paramtokens" and "paramdefaults" in: __FILE__ \
[53be34]95)
96#endif
[0b2ce9]97
98// print a list of type ref followed by a separator, i.e. "int i;"
[b4fa106]99#define type_print(z,n,TYPELIST, VARLIST, separator) \
100 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
101 BOOST_PP_SEQ_ELEM(n, VARLIST)\
[0b2ce9]102 separator
103
104// print a list of type ref followed, i.e. "int i, double position"
[b4fa106]105#define type_list(z,n,TYPELIST, VARLIST) \
[0b2ce9]106 BOOST_PP_COMMA_IF(n)\
[b4fa106]107 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
108 BOOST_PP_SEQ_ELEM(n, VARLIST)
109
[e4afb4]110// prints Options.insert
111#ifdef paramdefaults
112#define option_print(z,n,unused, unused2) \
113 tester = Options. insert (\
114 std::pair< std::string, OptionTrait *> ( \
115 BOOST_PP_SEQ_ELEM(n, paramtokens), \
116 new OptionTrait(\
117 BOOST_PP_SEQ_ELEM(n, paramtokens), \
118 &typeid( BOOST_PP_SEQ_ELEM(n, paramtypes) ), \
119 BOOST_PP_SEQ_ELEM(n, paramdescriptions), \
[d1115d]120 std::string( BOOST_PP_SEQ_ELEM(n, paramdefaults) ) )\
[e4afb4]121 )\
122 ); \
123 ASSERT(tester.second, "ActionTrait<ACTION>::ActionTrait<ACTION>() option token present twice!");
124#else
125#define option_print(z,n,unused, unused2) \
126 tester = Options. insert (\
127 std::pair< std::string, OptionTrait *> ( \
128 BOOST_PP_SEQ_ELEM(n, paramtokens), \
129 new OptionTrait(\
130 BOOST_PP_SEQ_ELEM(n, paramtokens), \
131 &typeid( BOOST_PP_SEQ_ELEM(n, paramtypes) ), \
132 BOOST_PP_SEQ_ELEM(n, paramdescriptions), \
133 NODEFAULT )\
134 )\
135 ); \
136 ASSERT(tester.second, "ActionTrait<ACTION>::ActionTrait<ACTION>() option token present twice!");
137#endif
[53be34]138
[ce7fdc]139namespace MoleCuilder {
140
[b4fa106]141void COMMAND(
[05736a]142#if defined paramtypes && defined paramreferences
[b4fa106]143#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
144#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
145#include BOOST_PP_LOCAL_ITERATE()
[0b2ce9]146#endif
[05736a]147 );
[0b2ce9]148
[df32ee]149class ACTION;
150
151template <>
152class ActionTrait<ACTION> : public ActionTraits {
153public:
[e4afb4]154 ActionTrait() :
155#ifndef SHORTFORM
156 ActionTraits(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string()))
157#else
158 ActionTraits(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string(), SHORTFORM))
159#endif /* SHORTFORM */
[bc2990]160 {
[e4afb4]161 // initialize remainder of action info
[53be34]162#ifdef MENUNAME
163 MenuTitle = MENUNAME;
164#endif
165#ifdef MENUPOSITION
166 MenuPosition = MENUPOSITION;
[24fbf3]167#endif
[e4afb4]168
[6a2dae]169 // initialize action's options
170 std::pair< ActionTraits::options_iterator, bool > tester;
[e4afb4]171#ifdef paramtokens
172#define BOOST_PP_LOCAL_MACRO(n) option_print(~, n, ~, )
173#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
174#include BOOST_PP_LOCAL_ITERATE()
[24fbf3]175#endif
[6a2dae]176 // associate action's short form also with option
[e4afb4]177#ifdef SHORTFORM
[6a2dae]178 if (Options.find(TOKEN) != Options.end())
179 Options[TOKEN]->setShortForm(std::string(SHORTFORM));
[e4afb4]180#endif /* SHORTFORM */
[6a2dae]181 //std::cout << "ActionTrait<" << BOOST_PP_STRINGIZE(ACTION) << ">::ActionTrait() on instance " << this << " with " << getName() << ", type " << getTypeName() << " and description " << getDescription() << std::endl;
[bc2990]182 }
[df32ee]183
[807d91]184 virtual ~ActionTrait() {}
[df32ee]185};
186
[0b2ce9]187class ACTION : public Action {
[b4fa106]188 #if defined paramtypes && defined paramreferences
[e4afb4]189 friend void COMMAND(
[b4fa106]190 #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
191 #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
192 #include BOOST_PP_LOCAL_ITERATE()
193 );
194 # else
195 void COMMAND();
196 #endif
197
[0b2ce9]198public:
199 ACTION();
200 virtual ~ACTION();
201
202 bool canUndo();
203 bool shouldUndo();
204
[9ee38b]205 struct PARAMS : ActionParameters {
[b4fa106]206 #if defined paramtypes && defined paramreferences
207 #define BOOST_PP_LOCAL_MACRO(n) type_print(~, n, paramtypes, paramreferences, ;)
208 #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
[9ee38b]209 #include BOOST_PP_LOCAL_ITERATE()
210 #endif
211 } params;
[0b2ce9]212
213protected:
214 virtual Dialog * fillDialog(Dialog*);
[862b6a]215
216 void startTimer() const;
217 void endTimer() const;
218
[0b2ce9]219private:
220 virtual void getParametersfromValueStorage();
221 virtual Action::state_ptr performCall();
222 virtual Action::state_ptr performUndo(Action::state_ptr);
223 virtual Action::state_ptr performRedo(Action::state_ptr);
224};
225
[ce7fdc]226}
227
[b4fa106]228#undef paramtypes
229#undef paramtokens
230#undef paramreferences
[e4afb4]231#undef paramdescriptions
232#undef paramdefaults
[b4fa106]233#undef MAXPARAMTYPES
234#undef statetypes
235#undef statereferences
236#undef MAXSTATETYPES
[9ee38b]237
[a02f78]238#undef option_print
239#undef type_print
240#undef type_list
241
[9ee38b]242#undef ACTION
243#undef COMMAND
244#undef COMMANDFULL
245#undef PARAMS
[b4fa106]246
247#undef ACTIONNAME
248#undef CATEGORY
[e4afb4]249#undef MENUNAME
250#undef MENUPOSITION
[9ee38b]251#undef TOKEN
[e4afb4]252
253#undef DESCRIPTION
254#undef SHORTFORM
Note: See TracBrowser for help on using the repository browser.