ThePEG  1.8.0
InterfacedBase.h
1 // -*- C++ -*-
2 //
3 // InterfacedBase.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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 
447 
448 protected:
449 
453  struct UpdateChecker {
455  UpdateChecker(bool & touched) : isTouched(touched) {}
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) {}
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 */