00001 // -*- C++ -*- 00002 // 00003 // CurrentGenerator.h is a part of ThePEG - Toolkit for HEP Event Generation 00004 // Copyright (C) 1999-2007 Leif Lonnblad 00005 // 00006 // ThePEG is licenced under version 2 of the GPL, see COPYING for details. 00007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 00008 // 00009 #ifndef ThePEG_CurrentGenerator_H 00010 #define ThePEG_CurrentGenerator_H 00011 // This is the declaration of the CurrentGenerator class. 00012 00013 #include "ThePEG/Repository/EventGenerator.h" 00014 #include "CurrentGenerator.fh" 00015 00016 namespace ThePEG { 00017 00033 class CurrentGenerator { 00034 00035 public: 00036 00040 CurrentGenerator() : generatorPushed(false) {} 00041 00045 CurrentGenerator(const CurrentGenerator &) 00046 : generatorPushed(false) {} 00047 00052 CurrentGenerator(const EGPtr & eg) : generatorPushed(false) { 00053 if ( eg ) { 00054 theGeneratorStack.push_back(eg); 00055 generatorPushed = true; 00056 } 00057 } 00058 00063 ~CurrentGenerator() { 00064 if ( generatorPushed ) theGeneratorStack.pop_back(); 00065 } 00066 00067 public: 00068 00073 static bool isVoid() { 00074 return theGeneratorStack.empty() || !(theGeneratorStack.back()); 00075 } 00076 00080 static EventGenerator & current() { 00081 return *theGeneratorStack.back(); 00082 } 00083 00088 static tSMPtr standardModel() { 00089 return current().standardModel(); 00090 } 00091 00096 static tStrategyPtr strategy() { return current().strategy(); } 00097 00104 static ostream & out() { return current().out(); } 00105 00112 static ostream & log() { return current().log(); } 00113 00120 static ostream & ref() { return current().ref(); } 00121 00127 template <typename T> 00128 static typename Ptr<T>::pointer getPtr(const T & t) { 00129 return current().getPtr(t); 00130 } 00131 00137 static IBPtr getPointer(string name) { 00138 return current().getPointer(name); 00139 } 00140 00146 template <typename T> 00147 static typename Ptr<T>::pointer getObject(string name) { 00148 return current().getObject<T>(name); 00149 } 00150 00155 template <typename T> 00156 static typename Ptr<T>::pointer getDefault() { 00157 return current().getDefault<T>(); 00158 } 00159 00160 public: 00161 00166 class Redirect { 00167 00168 public: 00169 00173 Redirect(ostream & os) : theStream(&os), theBuffer(os.rdbuf()) { 00174 theStream->rdbuf(current().misc().rdbuf()); 00175 } 00176 00181 ~Redirect() { 00182 theStream->rdbuf(theBuffer); 00183 } 00184 00188 ostream * theStream; 00189 00193 std::streambuf * theBuffer; 00194 00195 }; 00196 00197 private: 00198 00202 static vector<EGPtr> theGeneratorStack; 00203 00208 bool generatorPushed; 00209 00210 private: 00211 00215 CurrentGenerator & operator=(const CurrentGenerator &); 00216 00217 }; 00218 00219 } 00220 00221 #endif /* ThePEG_CurrentGenerator_H */