ThePEG  1.8.0
CurrentGenerator.h
1 // -*- C++ -*-
2 //
3 // CurrentGenerator.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_CurrentGenerator_H
10 #define ThePEG_CurrentGenerator_H
11 // This is the declaration of the CurrentGenerator class.
12 
13 #include "ThePEG/Repository/EventGenerator.h"
14 #include "CurrentGenerator.fh"
15 
16 namespace ThePEG {
17 
34 
35 public:
36 
41 
46  : generatorPushed(false) {}
47 
52  CurrentGenerator(const EGPtr & eg) : generatorPushed(false) {
53  if ( eg ) {
54  theGeneratorStack.push_back(eg);
55  generatorPushed = true;
56  }
57  }
58 
64  if ( generatorPushed ) theGeneratorStack.pop_back();
65  }
66 
67 public:
68 
73  static bool isVoid() {
74  return theGeneratorStack.empty() || !(theGeneratorStack.back());
75  }
76 
80  static EventGenerator & current() {
81  return *theGeneratorStack.back();
82  }
83 
88  return *theGeneratorStack.back();
89  }
90 
95  return theGeneratorStack.back();
96  }
97 
101  static EventGenerator * ptr() {
102  return theGeneratorStack.back();
103  }
104 
108  operator bool() const {
109  return ptr();
110  }
111 
115  bool operator!() const {
116  return !ptr();
117  }
118 
124  return current().standardModel();
125  }
126 
131  static tStrategyPtr strategy() { return current().strategy(); }
132 
139  static ostream & out() { return current().out(); }
140 
147  static ostream & log() { return current().log(); }
148 
155  static ostream & ref() { return current().ref(); }
156 
162  template <typename T>
163  static typename Ptr<T>::pointer getPtr(const T & t) {
164  return current().getPtr(t);
165  }
166 
172  static IBPtr getPointer(string name) {
173  return current().getPointer(name);
174  }
175 
181  template <typename T>
182  static typename Ptr<T>::pointer getObject(string name) {
183  return current().getObject<T>(name);
184  }
185 
190  template <typename T>
191  static typename Ptr<T>::pointer getDefault() {
192  return current().getDefault<T>();
193  }
194 
195 public:
196 
201  class Redirect {
202 
203  public:
204 
213  Redirect(ostream & os, bool internal = false)
214  : theStream(&os), theBuffer(os.rdbuf()) {
215  if ( internal ) theStream->rdbuf(intStream.rdbuf());
216  else if ( !current().useStdOut() )
217  theStream->rdbuf(current().misc().rdbuf());
218  }
219 
225  theStream->rdbuf(theBuffer);
226  }
227 
232  string str() const {
233  return intStream.str();
234  }
235 
239  ostream * theStream;
240 
244  std::streambuf * theBuffer;
245 
250  ostringstream intStream;
251 
252  };
253 
254 private:
255 
259  static vector<EGPtr> theGeneratorStack;
260 
266 
267 private:
268 
273 
274 };
275 
276 }
277 
278 #endif /* ThePEG_CurrentGenerator_H */