source: src/Actions/Reaction_impl_header.hpp@ 6253ed

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 6253ed was 5ca6b5, checked in by Michael Ankele <ankele@…>, 12 years ago

drop deprecated references to ValueStorage

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