thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
Switch.h
1// -*- C++ -*-
2//
3// Switch.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef ThePEG_Switch_H
10#define ThePEG_Switch_H
11// This is the declaration of the Switch, SwitchBase and SwitchOption classes.
12
14#include "Switch.fh"
15#include "Switch.xh"
16#include "InterfaceBase.h"
17
18namespace ThePEG {
19
36class SwitchOption: public Named {
37
38public:
39
54 template<typename EnumT>
55 SwitchOption(SwitchBase & theSwitch, string newName,
56 string newDescription, EnumT newValue);
57
62
66 const string & description() const { return theDescription; }
67
71 long value() const { return theValue; }
72
76 operator long () const;
77
78protected:
79
80private:
81
86
91
92};
93
119
120public:
121
123 typedef map<long, SwitchOption> OptionMap;
125 typedef map<string, SwitchOption> StringMap;
126
128 friend class SwitchOption;
129
130public:
131
152 SwitchBase(string newName, string newDescription,
153 string newClassName, const type_info & newTypeInfo,
154 bool depSafe, bool readonly)
155 : InterfaceBase(newName, newDescription, newClassName,
156 newTypeInfo, depSafe, readonly) {}
157
165 virtual string exec(InterfacedBase & ib, string action,
166 string arguments) const;
167
171 virtual string fullDescription(const InterfacedBase & ib) const;
172
176 virtual string type() const;
177
181 virtual void set(InterfacedBase & ib, long val)
182 const = 0;
183
187 virtual long get(const InterfacedBase & ib)
188 const = 0;
189
193 virtual long def(const InterfacedBase & ib)
194 const = 0;
195
199 void setDef(InterfacedBase & i) const {
200 set(i, def(i));
201 }
202
206 bool check(long newValue) const { return member(theOptions, newValue); }
207
211 const OptionMap & options() const { return theOptions; }
212
217 virtual string doxygenType() const;
218
222 string opttag(long opt) const;
223
224protected:
225
229 void registerOption(const SwitchOption & o) {
230 theOptions[o.value()] = o;
231 theOptionNames[o.name()] = o;
232 }
233
234private:
235
240
245
246};
247
272template <typename T, typename Int>
273class Switch: public SwitchBase {
274
275public:
276
281 typedef void (T::*SetFn)(Int);
286 typedef Int (T::*GetFn)() const;
287
291 typedef Int T::* Member;
292
293public:
294
324 Switch(string newName, string newDescription,
325 Member newMember, Int newDef, bool depSafe = false,
326 bool readonly = false, SetFn newSetFn = 0, GetFn newGetFn = 0,
327 GetFn newDefFn = 0)
328 : SwitchBase(newName, newDescription, ClassTraits<T>::className(),
329 typeid(T), depSafe, readonly),
330 theMember(newMember), theDef(newDef), theSetFn(newSetFn),
331 theGetFn(newGetFn), theDefFn(newDefFn) {}
332
336 virtual void set(InterfacedBase & ib, long val) const
337 ;
338
342 virtual long get(const InterfacedBase & ib) const;
343
347 virtual long def(const InterfacedBase & ib) const;
348
352 void setSetFunction(SetFn sf) { theSetFn = sf; }
353
357 void setGetFunction(GetFn gf) { theGetFn = gf; }
358
363
368 virtual void doxygenDescription(ostream & stream) const;
369
370private:
371
376
382
387
392
397
398};
399
400}
401
402#ifndef ThePEG_TEMPLATES_IN_CC_FILE
403#include "Switch.tcc"
404#endif
405
406#endif /* ThePEG_Switch_H */
This is the main config header file for ThePEG.
The InterfaceBase class defines a generic interface to any class derived from the InterfacedBase clas...
Definition: InterfaceBase.h:59
string className() const
Return the class name for the class this interface is defined for.
InterfacedBase is the base class of all Interfaced objects to be handled by the BaseRepository class.
The Named class is a simple concrete base class to used by classes of objects with a name.
Definition: Named.h:24
const string & name() const
Return name.
Definition: Named.h:42
The Switch class and its base class SwitchBase defines an interface to a class derived from the Inter...
Definition: Switch.h:118
string opttag(long opt) const
Return a string with the option index and its associated tag.
virtual long get(const InterfacedBase &ib) const =0
Return the value of the member variable of ib.
virtual string doxygenType() const
Return a string describing the type of interface to be included in the Doxygen documentation.
virtual string type() const
Return a code for the type of this switch.
virtual string fullDescription(const InterfacedBase &ib) const
Return a complete description of this switch.
virtual long def(const InterfacedBase &ib) const =0
Return the default value for the member variable of ib.
virtual void set(InterfacedBase &ib, long val) const =0
Set the member variable of ib to val.
OptionMap theOptions
The map relating options to their values.
Definition: Switch.h:239
SwitchBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, bool depSafe, bool readonly)
Standard constructor.
Definition: Switch.h:152
void setDef(InterfacedBase &i) const
Set the member variable of ib to its default value.
Definition: Switch.h:199
virtual string exec(InterfacedBase &ib, string action, string arguments) const
The general interface method overriding the one in InterfaceBase.
map< long, SwitchOption > OptionMap
A map with SwitchOptions indexed by their values.
Definition: Switch.h:123
const OptionMap & options() const
Return the map relating options to their values.
Definition: Switch.h:211
map< string, SwitchOption > StringMap
A map with SwitchOptions indexed by their names.
Definition: Switch.h:125
StringMap theOptionNames
The map relating options to their names.
Definition: Switch.h:244
void registerOption(const SwitchOption &o)
Register a new option.
Definition: Switch.h:229
bool check(long newValue) const
Check if val is among the listed options.
Definition: Switch.h:206
SwitchOption is used by the Switch class and its base class SwitchBase to define valid options in a s...
Definition: Switch.h:36
long theValue
The value of this option.
Definition: Switch.h:90
long value() const
The value of this option.
Definition: Switch.h:71
const string & description() const
The description of this option.
Definition: Switch.h:66
string theDescription
The description of this option.
Definition: Switch.h:85
SwitchOption(SwitchBase &theSwitch, string newName, string newDescription, EnumT newValue)
Standard constructor.
SwitchOption()
Default constructor.
Definition: Switch.h:61
The Switch class and its base class SwitchBase defines an interface to a class derived from the Inter...
Definition: Switch.h:273
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by 'get()'.
Definition: Switch.h:357
virtual long def(const InterfacedBase &ib) const
Return the default value for the member variable of ib.
Switch(string newName, string newDescription, Member newMember, Int newDef, bool depSafe=false, bool readonly=false, SetFn newSetFn=0, GetFn newGetFn=0, GetFn newDefFn=0)
Standard constructor.
Definition: Switch.h:324
void setDefaultFunction(GetFn df)
Give a pointer to a member function to be used by 'def()'.
Definition: Switch.h:362
Int T::* Member
Declaration of a direct pointer to the member variable.
Definition: Switch.h:291
Member theMember
The pointer to the member variable.
Definition: Switch.h:375
virtual long get(const InterfacedBase &ib) const
Return the value of the member variable of ib.
virtual void doxygenDescription(ostream &stream) const
Print a description to be included in the Doxygen documentation to the given stream.
GetFn theDefFn
Pointer to member function to be used by def().
Definition: Switch.h:396
GetFn theGetFn
Pointer to member function to be used by get().
Definition: Switch.h:391
virtual void set(InterfacedBase &ib, long val) const
Set the member variable of ib to val.
Int(T::* GetFn)() const
The declaration of member functions which can be used by this Switch interface for the 'get' action.
Definition: Switch.h:286
SetFn theSetFn
A pointer to a member function to be used by 'set()'.
Definition: Switch.h:386
void(T::* SetFn)(Int)
The declaration of member functions which can be used by this Switch interface for the 'set' action.
Definition: Switch.h:281
Int theDef
Default value to be used if no corresponding member function pointers are given.
Definition: Switch.h:381
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by 'set()'.
Definition: Switch.h:352
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
bool member(const Container &c, const Key &k)
Check if a given object is a part of a container.
Definition: std.h:126
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
Conversion between integers and types.
Definition: TemplateTools.h:24