ThePEG  1.8.0
Interfaced.h
1 // -*- C++ -*-
2 //
3 // Interfaced.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_Interfaced_H
10 #define ThePEG_Interfaced_H
11 // This is the declaration of the Interfaced class.
12 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "InterfacedBase.h"
15 #include "ThePEG/PDT/PID.h"
16 
17 namespace ThePEG {
18 
38 class Interfaced: public InterfacedBase {
39 
41  friend class Repository;
42 
44  friend class EventGenerator;
45 
46 public:
47 
51  virtual ~Interfaced();
52 
57 public:
58 
68  virtual bool defaultInit();
69 
76  PPtr getParticle(PID) const;
77 
82  PDPtr getParticleData(PID) const;
83 
87  bool used() const { return theUseFlag; }
88 
93  void useMe() const { if ( !used() ) setUsed(); }
94 
99  tEGPtr generator() const { return theGenerator; }
101 
102 public:
103 
110  void persistentOutput(PersistentOStream & os) const;
111 
117  void persistentInput(PersistentIStream & is, int version);
119 
123  static void Init();
124 
125 protected:
126 
130  static void registerRepository(IBPtr);
131 
136  static void registerRepository(IBPtr, string newName);
137 
145  void reporeg(IBPtr object, string name) const;
146 
153  template <typename PtrT>
154  bool setDefaultReference(PtrT & ptr, string classname, string objectname) {
155  if ( ptr ) return true;
156  const ClassDescriptionBase * db = DescriptionList::find(classname);
157  if ( !db ) return false;
158  ptr = dynamic_ptr_cast<PtrT>(db->create());
159  if ( !ptr ) return false;
160  reporeg(ptr, objectname);
161  if ( !ptr->defaultInit() ) return false;
162  return true;
163  }
164 
168  Interfaced() : theUseFlag(false) {}
169 
173  Interfaced(const string & newName)
174  : InterfacedBase(newName), theUseFlag(false) {}
175 
181 
182 protected:
183 
189 
190 private:
191 
195  void setUsed() const;
196 
201 
205  mutable bool theUseFlag;
206 
210  string doDefaultInit(string);
211 
212 private:
213 
218 
222  Interfaced & operator=(const Interfaced &);
223 
224 };
225 
232 template <>
233 struct BaseClassTrait<Interfaced,1>: public ClassTraitsType {
235  typedef InterfacedBase NthBase;
236 };
237 
242 template <>
243 struct ClassTraits<Interfaced>: public ClassTraitsBase<Interfaced> {
245  static string className() { return "ThePEG::Interfaced"; }
246 };
247 
250 }
251 
252 #endif /* ThePEG_Interfaced_H */