thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Interface
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
13
#include "
ThePEG/Config/ThePEG.h
"
14
#include "Switch.fh"
15
#include "Switch.xh"
16
#include "InterfaceBase.h"
17
18
namespace
ThePEG
{
19
36
class
SwitchOption
:
public
Named
{
37
38
public
:
39
54
template
<
typename
EnumT>
55
SwitchOption
(
SwitchBase
& theSwitch,
string
newName,
56
string
newDescription,
EnumT
newValue);
57
61
SwitchOption
() :
theValue
(-999) {}
62
66
const
string
&
description
()
const
{
return
theDescription
; }
67
71
long
value
()
const
{
return
theValue
; }
72
76
operator
long ()
const
;
77
78
protected
:
79
80
private
:
81
85
string
theDescription
;
86
90
long
theValue
;
91
92
};
93
118
class
SwitchBase
:
public
InterfaceBase
{
119
120
public
:
121
123
typedef
map<long, SwitchOption>
OptionMap
;
125
typedef
map<string, SwitchOption>
StringMap
;
126
128
friend
class
SwitchOption
;
129
130
public
:
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
224
protected
:
225
229
void
registerOption
(
const
SwitchOption
& o) {
230
theOptions
[o.
value
()] = o;
231
theOptionNames
[o.
name
()] = o;
232
}
233
234
private
:
235
239
OptionMap
theOptions
;
240
244
StringMap
theOptionNames
;
245
246
};
247
272
template
<
typename
T,
typename
Int>
273
class
Switch
:
public
SwitchBase
{
274
275
public
:
276
281
typedef
void (T::*
SetFn
)(Int);
286
typedef
Int (T::*
GetFn
)()
const
;
287
291
typedef
Int T::*
Member
;
292
293
public
:
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
362
void
setDefaultFunction
(
GetFn
df) {
theDefFn
= df; }
363
368
virtual
void
doxygenDescription
(ostream & stream)
const
;
369
370
private
:
371
375
Member
theMember
;
376
381
Int
theDef
;
382
386
SetFn
theSetFn
;
387
391
GetFn
theGetFn
;
392
396
GetFn
theDefFn
;
397
398
};
399
400
}
401
402
#ifndef ThePEG_TEMPLATES_IN_CC_FILE
403
#include "Switch.tcc"
404
#endif
405
406
#endif
/* ThePEG_Switch_H */
ThePEG.h
This is the main config header file for ThePEG.
ThePEG::InterfaceBase
The InterfaceBase class defines a generic interface to any class derived from the InterfacedBase clas...
Definition:
InterfaceBase.h:59
ThePEG::InterfaceBase::className
string className() const
Return the class name for the class this interface is defined for.
Definition:
InterfaceBase.h:166
ThePEG::InterfacedBase
InterfacedBase is the base class of all Interfaced objects to be handled by the BaseRepository class.
Definition:
InterfacedBase.h:45
ThePEG::Named
The Named class is a simple concrete base class to used by classes of objects with a name.
Definition:
Named.h:24
ThePEG::Named::name
const string & name() const
Return name.
Definition:
Named.h:42
ThePEG::SwitchBase
The Switch class and its base class SwitchBase defines an interface to a class derived from the Inter...
Definition:
Switch.h:118
ThePEG::SwitchBase::opttag
string opttag(long opt) const
Return a string with the option index and its associated tag.
ThePEG::SwitchBase::get
virtual long get(const InterfacedBase &ib) const =0
Return the value of the member variable of ib.
ThePEG::SwitchBase::doxygenType
virtual string doxygenType() const
Return a string describing the type of interface to be included in the Doxygen documentation.
ThePEG::SwitchBase::type
virtual string type() const
Return a code for the type of this switch.
ThePEG::SwitchBase::fullDescription
virtual string fullDescription(const InterfacedBase &ib) const
Return a complete description of this switch.
ThePEG::SwitchBase::def
virtual long def(const InterfacedBase &ib) const =0
Return the default value for the member variable of ib.
ThePEG::SwitchBase::set
virtual void set(InterfacedBase &ib, long val) const =0
Set the member variable of ib to val.
ThePEG::SwitchBase::theOptions
OptionMap theOptions
The map relating options to their values.
Definition:
Switch.h:239
ThePEG::SwitchBase::SwitchBase
SwitchBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, bool depSafe, bool readonly)
Standard constructor.
Definition:
Switch.h:152
ThePEG::SwitchBase::setDef
void setDef(InterfacedBase &i) const
Set the member variable of ib to its default value.
Definition:
Switch.h:199
ThePEG::SwitchBase::exec
virtual string exec(InterfacedBase &ib, string action, string arguments) const
The general interface method overriding the one in InterfaceBase.
ThePEG::SwitchBase::OptionMap
map< long, SwitchOption > OptionMap
A map with SwitchOptions indexed by their values.
Definition:
Switch.h:123
ThePEG::SwitchBase::options
const OptionMap & options() const
Return the map relating options to their values.
Definition:
Switch.h:211
ThePEG::SwitchBase::StringMap
map< string, SwitchOption > StringMap
A map with SwitchOptions indexed by their names.
Definition:
Switch.h:125
ThePEG::SwitchBase::theOptionNames
StringMap theOptionNames
The map relating options to their names.
Definition:
Switch.h:244
ThePEG::SwitchBase::registerOption
void registerOption(const SwitchOption &o)
Register a new option.
Definition:
Switch.h:229
ThePEG::SwitchBase::check
bool check(long newValue) const
Check if val is among the listed options.
Definition:
Switch.h:206
ThePEG::SwitchOption
SwitchOption is used by the Switch class and its base class SwitchBase to define valid options in a s...
Definition:
Switch.h:36
ThePEG::SwitchOption::theValue
long theValue
The value of this option.
Definition:
Switch.h:90
ThePEG::SwitchOption::value
long value() const
The value of this option.
Definition:
Switch.h:71
ThePEG::SwitchOption::description
const string & description() const
The description of this option.
Definition:
Switch.h:66
ThePEG::SwitchOption::theDescription
string theDescription
The description of this option.
Definition:
Switch.h:85
ThePEG::SwitchOption::SwitchOption
SwitchOption(SwitchBase &theSwitch, string newName, string newDescription, EnumT newValue)
Standard constructor.
ThePEG::SwitchOption::SwitchOption
SwitchOption()
Default constructor.
Definition:
Switch.h:61
ThePEG::Switch
The Switch class and its base class SwitchBase defines an interface to a class derived from the Inter...
Definition:
Switch.h:273
ThePEG::Switch::setGetFunction
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by 'get()'.
Definition:
Switch.h:357
ThePEG::Switch::def
virtual long def(const InterfacedBase &ib) const
Return the default value for the member variable of ib.
ThePEG::Switch::Switch
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
ThePEG::Switch::setDefaultFunction
void setDefaultFunction(GetFn df)
Give a pointer to a member function to be used by 'def()'.
Definition:
Switch.h:362
ThePEG::Switch::Member
Int T::* Member
Declaration of a direct pointer to the member variable.
Definition:
Switch.h:291
ThePEG::Switch::theMember
Member theMember
The pointer to the member variable.
Definition:
Switch.h:375
ThePEG::Switch::get
virtual long get(const InterfacedBase &ib) const
Return the value of the member variable of ib.
ThePEG::Switch::doxygenDescription
virtual void doxygenDescription(ostream &stream) const
Print a description to be included in the Doxygen documentation to the given stream.
ThePEG::Switch::theDefFn
GetFn theDefFn
Pointer to member function to be used by def().
Definition:
Switch.h:396
ThePEG::Switch::theGetFn
GetFn theGetFn
Pointer to member function to be used by get().
Definition:
Switch.h:391
ThePEG::Switch::set
virtual void set(InterfacedBase &ib, long val) const
Set the member variable of ib to val.
ThePEG::Switch::GetFn
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
ThePEG::Switch::theSetFn
SetFn theSetFn
A pointer to a member function to be used by 'set()'.
Definition:
Switch.h:386
ThePEG::Switch::SetFn
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
ThePEG::Switch::theDef
Int theDef
Default value to be used if no corresponding member function pointers are given.
Definition:
Switch.h:381
ThePEG::Switch::setSetFunction
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by 'set()'.
Definition:
Switch.h:352
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
ThePEG::member
bool member(const Container &c, const Key &k)
Check if a given object is a part of a container.
Definition:
std.h:126
ThePEG::ClassTraits
The default concrete implementation of ClassTraitsBase.
Definition:
ClassTraits.h:134
ThePEG::Int2Type
Conversion between integers and types.
Definition:
TemplateTools.h:24
Generated on Thu Jun 20 2024 14:47:00 for ThePEG by
1.9.6