thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "ThePEG/Utilities/Named.h"
15 #include "ThePEG/Utilities/ClassDescription.h"
16 #include "ThePEG/Utilities/HoldFlag.h"
17 #include "InterfacedBase.xh"
18 
19 namespace ThePEG {
20 
45 class InterfacedBase: public PersistentBase, public Named {
46 
48  friend class BaseRepository;
49 
51  friend class InterfaceBase;
52 
54  friend class EventGenerator;
55 
56 public:
57 
61  enum InitState {
62  initializing = -1,
68  runready = 2
70  };
71 
72 public:
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 
120 protected:
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 
227 public:
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 
325  void persistentOutput(PersistentOStream & os) const;
326 
332  void persistentInput(PersistentIStream & is, int version);
334 
338  static void Init();
339 
340 protected:
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 
370 private:
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 
392 private:
393 
397  string addComment(string);
398 
399 private:
400 
404  bool isLocked;
405 
410  bool isTouched;
411 
417 
421  string theComment;
422 
426  map<string,string> objectDefaults;
427 
428 public:
429 
434  virtual void debugme() const;
435 
436 private:
437 
442 
446  InterfacedBase & operator=(const InterfacedBase &) = delete;
447 
448 protected:
449 
453  struct UpdateChecker {
455  UpdateChecker(bool & touched) : isTouched(touched) {}
457  UpdateChecker(const UpdateChecker & uc) : isTouched(uc.isTouched) {}
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 
473  UpdateMapChecker(bool & touched) : isTouched(touched) {}
475  UpdateMapChecker(const UpdateMapChecker & uc) : isTouched(uc.isTouched) {}
477  template <typename ref> void operator()(const ref & i) {
478  UpdateChecker::check(i.second, isTouched);
479  }
481  bool & isTouched;
482  };
483 
484 };
485 
492 template <>
495  typedef PersistentBase NthBase;
496 };
497 
502 template <>
503 struct ClassTraits<InterfacedBase>: public ClassTraitsBase<InterfacedBase> {
505  static string className() { return "ThePEG::InterfacedBase"; }
506 };
507 
510 }
511 
512 #endif /* ThePEG_InterfacedBase_H */
void finish()
Calls the dofinish() function with recursion prevention.
PersistentIStream is used to read persistent objects from a stream where they were previously written...
virtual IBPtr clone() const =0
Return a simple clone of this object.
UpdateChecker(bool &touched)
Constructor.
void name(string newName)
Set a new name (full name including path).
void clear()
Calls reset() and unTouch().
virtual void debugme() const
Print out debugging information for this object on std::cerr.
Define the base class from which all (polymorphic) classes in ThePEG are derived. ...
Definition: ThePEG.h:54
void setup(istream &is)
Read setup info from a standard istream is.
virtual void doinitrun()
Initialize this object.
ClassTraitsType is an empty, non-polymorphic, base class.
Definition: ClassTraits.h:30
Functor class to be used to update a range of dependent object in a map.
InterfacedBase(const InterfacedBase &i)
Protected copy-constructor.
The InterfaceBase class defines a generic interface to any class derived from the InterfacedBase clas...
Definition: InterfaceBase.h:59
void lock()
Lock this object.
void operator()(const ptr &i)
Function call operator.
UpdateMapChecker(const UpdateMapChecker &uc)
Constructor.
The object has been initialized.
bool isTouched
True if this object has been chaged since the last call to update().
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
A concreate implementation of ClassDescriptionBase describing an abstract class with persistent data...
The object is currently being initialized.
UpdateChecker(const UpdateChecker &uc)
Constructor.
void touch()
This function should be called every time something in this object has changed in a way that a sanity...
string path() const
Returns the path to this object including the trailing &#39;/&#39;.
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
Functor class to be used to update a range of dependent object.
virtual void doupdate()
Check sanity of the object during the setup phase.
Rebinder is a class associating pairs of pointers to objects.
Definition: Rebinder.h:27
virtual IBPtr fullclone() const
Return a full clone of this object possibly doing things to the clone to make it sane.
map< string, string > objectDefaults
A map listing object-specific defaults set for the given interfaces.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
static AbstractClassDescription< InterfacedBase > initInterfacedBase
Standard Initialization object.
bool locked() const
Return true if the BaseRepository is not allowed to change the state of this object.
The Named class is a simple concrete base class to used by classes of objects with a name...
Definition: Named.h:24
This is the main config header file for ThePEG.
The object has not been initialized.
InitState initState
Indicate if this object has been initialized or not, or if it is being initialized.
InitState state() const
Return the state of initialization of this object.
InterfacedBase()
Protected default constructor.
static void Init()
Standard Init function.
string comment() const
Returns a comment assigned to this object.
virtual ~InterfacedBase()
The virtual (empty) destructor;.
static void check(tIBPtr, bool &)
Call the check function for an object.
void initrun()
Calls the doinitrun() function with recursion prevention.
bool isLocked
True if this object is not to be changed by the user interface.
void reset()
Set the state of this object to uninitialized.
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
bool & isTouched
Reference to the bool variable to be set.
InitState
Enumeration reflecting the state of an InterfacedBase object.
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
void init()
Calls the doinit() function with recursion prevention.
BaseRepository is a purely static class which keeps a set of InterfacedBase objects indexed by their ...
InterfacedBase is the base class of all Interfaced objects to be handled by the BaseRepository class...
void unlock()
Unlock this object.
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
virtual void dofinish()
Finalize this object.
const string & name() const
Return name.
Definition: Named.h:42
string theComment
A comment assigned to this object.
void operator()(const ref &i)
Function call operator.
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.
virtual bool preInitialize() const
Return true if this object needs to be initialized before all other objects (except those for which t...
virtual void doinit()
Initialize this object after the setup phase before saving an EventGenerator to disk.
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
The object is initialized and the initrun() method has been called.
string addComment(string)
Used by the interface to add comments.
string name() const
Returns the name of this object, without the path.
void untouch()
Clear the isTouched flag.
virtual IVector getReferences()
Return a vector of all pointers to Interfaced objects used in this object.
HoldFlag objects are used to temporarily change the value of an object, restoring the original value ...
Definition: HoldFlag.h:23
vector< IBPtr > IVector
A vector of pointers to InterfacedBase objects.
Definition: Containers.h:67
void update()
Calls the doupdate() function with recursion prevention.
virtual void readSetup(istream &is)
Read setup info from a standard istream is.
virtual void rebind(const TranslationMap &)
Rebind pointer to other Interfaced objects.
BaseClassTraits describes the base classes of the templated class.
Definition: ClassTraits.h:156
InterfacedBase(string newName)
Protected constructor with the name given as argument.
The EventGenerator class manages a whole event generator run.
bool touched() const
Return true if the state of this object has been changed since the last call to update().
bool & isTouched
set to false if any check() call fails.
The templated ClassTraitsBase class defines a set of default information about classes used by ThePEG...
Definition: ClassTraits.h:52
UpdateMapChecker(bool &touched)
Constructor.