thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
InterfacedBase.h
1// -*- C++ -*-
2//
3// InterfacedBase.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_InterfacedBase_H
10#define ThePEG_InterfacedBase_H
11// This is the declaration of the InterfacedBase class.
12
14#include "ThePEG/Utilities/Named.h"
15#include "ThePEG/Utilities/ClassDescription.h"
16#include "ThePEG/Utilities/HoldFlag.h"
17#include "InterfacedBase.xh"
18
19namespace ThePEG {
20
45class InterfacedBase: public PersistentBase, public Named {
46
48 friend class BaseRepository;
49
51 friend class InterfaceBase;
52
54 friend class EventGenerator;
55
56public:
57
61 enum InitState {
62 initializing = -1,
68 runready = 2
70 };
71
72public:
73
77 virtual ~InterfacedBase();
78
83 string fullName() const { return Named::name(); }
84
88 string name() const {
89 return Named::name().substr(Named::name().rfind('/')+1);
90 }
91
96 string path() const {
97 string::size_type slash = Named::name().rfind('/');
98 string ret;
99 if ( slash != string::npos ) ret = Named::name().substr(0,slash);
100 return ret;
101 }
102
106 string comment() const { return theComment; }
107
115 void setup(istream & is) {
116 readSetup(is);
117 getline(is, theComment);
118 }
119
120protected:
121
132 virtual void readSetup(istream & is);
133
156 virtual void doupdate() {}
157
179 virtual void doinit() {}
180
196 virtual void doinitrun() {}
197
208 virtual void dofinish() {}
209
215 virtual IVector getReferences() { return IVector(); }
216
224 virtual void rebind(const TranslationMap &) {}
226
227public:
228
234 void update() {
235 if ( initState ) return;
237 doupdate();
238 }
239
243 void init() {
244 if ( initState ) return;
246 doinit();
247 }
248
255 virtual bool preInitialize() const;
256
260 void initrun() {
261 if ( initState == runready || initState == initializing ) return;
263 doinitrun();
264 }
265
269 void finish() {
270 if ( initState == uninitialized || initState == initializing ) return;
272 dofinish();
273 }
274
280 void touch() { isTouched = true; }
281
286
290 void clear() {
291 reset();
292 untouch();
293 }
294
298 InitState state() const { return initState; }
299
304 bool locked() const { return isLocked; }
305
310 bool touched() const { return isTouched; }
312
317 virtual IBPtr fullclone() const { return clone(); }
318
326
332 void persistentInput(PersistentIStream & is, int version);
334
338 static void Init();
339
340protected:
341
346 virtual IBPtr clone() const = 0;
347
352 : Named(""), isLocked(false), isTouched(true),
354
358 InterfacedBase(string newName)
359 : Named(newName), isLocked(false), isTouched(true),
361
366 : Base(i), Named(i), isLocked(false), isTouched(true),
369
370private:
371
375 void name(string newName) { Named::name(newName); }
376
380 void lock() { isLocked = true; }
381
385 void unlock() { isLocked = false; }
386
390 void untouch() { isTouched = false; }
391
392private:
393
397 string addComment(string);
398
399private:
400
405
411
417
422
426 map<string,string> objectDefaults;
427
428public:
429
434 virtual void debugme() const;
435
436private:
437
442
447
448protected:
449
459 static void check(tIBPtr, bool &);
461 template <typename ptr> void operator()(const ptr & i) {
462 check(i, isTouched);
463 }
465 bool & isTouched;
466 };
467
477 template <typename ref> void operator()(const ref & i) {
479 }
481 bool & isTouched;
482 };
483
484};
485
492template <>
495 typedef PersistentBase NthBase;
496};
497
502template <>
503struct ClassTraits<InterfacedBase>: public ClassTraitsBase<InterfacedBase> {
505 static string className() { return "ThePEG::InterfacedBase"; }
506};
507
510}
511
512#endif /* ThePEG_InterfacedBase_H */
This is the main config header file for ThePEG.
A concreate implementation of ClassDescriptionBase describing an abstract class with persistent data.
BaseRepository is a purely static class which keeps a set of InterfacedBase objects indexed by their ...
The EventGenerator class manages a whole event generator run.
HoldFlag objects are used to temporarily change the value of an object, restoring the original value ...
Definition: HoldFlag.h:23
The InterfaceBase class defines a generic interface to any class derived from the InterfacedBase clas...
Definition: InterfaceBase.h:59
InterfacedBase is the base class of all Interfaced objects to be handled by the BaseRepository class.
virtual void dofinish()
Finalize this object.
virtual ~InterfacedBase()
The virtual (empty) destructor;.
virtual void doinit()
Initialize this object after the setup phase before saving an EventGenerator to disk.
bool touched() const
Return true if the state of this object has been changed since the last call to update().
void setup(istream &is)
Read setup info from a standard istream is.
virtual IBPtr clone() const =0
Return a simple clone of this object.
void clear()
Calls reset() and unTouch().
InitState
Enumeration reflecting the state of an InterfacedBase object.
@ initialized
The object has been initialized.
@ uninitialized
The object has not been initialized.
@ runready
The object is initialized and the initrun() method has been called.
@ initializing
The object is currently being initialized.
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
InterfacedBase(string newName)
Protected constructor with the name given as argument.
virtual IBPtr fullclone() const
Return a full clone of this object possibly doing things to the clone to make it sane.
static void Init()
Standard Init function.
InitState state() const
Return the state of initialization of this object.
InitState initState
Indicate if this object has been initialized or not, or if it is being initialized.
void initrun()
Calls the doinitrun() function with recursion prevention.
bool isTouched
True if this object has been chaged since the last call to update().
virtual bool preInitialize() const
Return true if this object needs to be initialized before all other objects (except those for which t...
static AbstractClassDescription< InterfacedBase > initInterfacedBase
Standard Initialization object.
string name() const
Returns the name of this object, without the path.
string addComment(string)
Used by the interface to add comments.
string theComment
A comment assigned to this object.
virtual void rebind(const TranslationMap &)
Rebind pointer to other Interfaced objects.
InterfacedBase()
Protected default constructor.
void name(string newName)
Set a new name (full name including path).
void reset()
Set the state of this object to uninitialized.
virtual void doupdate()
Check sanity of the object during the setup phase.
map< string, string > objectDefaults
A map listing object-specific defaults set for the given interfaces.
void untouch()
Clear the isTouched flag.
void touch()
This function should be called every time something in this object has changed in a way that a sanity...
void lock()
Lock this object.
void init()
Calls the doinit() function with recursion prevention.
virtual void readSetup(istream &is)
Read setup info from a standard istream is.
string path() const
Returns the path to this object including the trailing '/'.
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
bool locked() const
Return true if the BaseRepository is not allowed to change the state of this object.
InterfacedBase(const InterfacedBase &i)
Protected copy-constructor.
void update()
Calls the doupdate() function with recursion prevention.
void unlock()
Unlock this object.
string comment() const
Returns a comment assigned to this object.
virtual IVector getReferences()
Return a vector of all pointers to Interfaced objects used in this object.
InterfacedBase & operator=(const InterfacedBase &)=delete
Private and non-existent assignment operator.
string fullName() const
Returns the full name of this object including its path, e.g.
bool isLocked
True if this object is not to be changed by the user interface.
virtual void debugme() const
Print out debugging information for this object on std::cerr.
virtual void doinitrun()
Initialize this object.
void finish()
Calls the dofinish() function with recursion prevention.
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
PersistentIStream is used to read persistent objects from a stream where they were previously written...
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
Rebinder is a class associating pairs of pointers to objects.
Definition: Rebinder.h:27
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
vector< IBPtr > IVector
A vector of pointers to InterfacedBase objects.
Definition: Containers.h:67
BaseClassTraits describes the base classes of the templated class.
Definition: ClassTraits.h:156
int NthBase
The type of the BaseN'th base class (int means there are no further base classes).
Definition: ClassTraits.h:161
Define the base class from which all (polymorphic) classes in ThePEG are derived.
Definition: ThePEG.h:54
static string className()
Return the name of class T.
Definition: ClassTraits.h:66
ClassTraitsType is an empty, non-polymorphic, base class.
Definition: ClassTraits.h:30
Functor class to be used to update a range of dependent object.
UpdateChecker(bool &touched)
Constructor.
static void check(tIBPtr, bool &)
Call the check function for an object.
UpdateChecker(const UpdateChecker &uc)
Constructor.
void operator()(const ptr &i)
Function call operator.
bool & isTouched
set to false if any check() call fails.
Functor class to be used to update a range of dependent object in a map.
bool & isTouched
Reference to the bool variable to be set.
UpdateMapChecker(const UpdateMapChecker &uc)
Constructor.
UpdateMapChecker(bool &touched)
Constructor.
void operator()(const ref &i)
Function call operator.