00001 // -*- C++ -*- 00002 // 00003 // Current.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_Current_H 00010 #define ThePEG_Current_H 00011 // This is the declaration of the Current class. 00012 00013 namespace ThePEG { 00014 00038 template <typename T> 00039 class Current { 00040 00041 public: 00042 00046 Current() : pushed(false) {} 00047 00051 Current(const Current<T> &) 00052 : pushed(false) {} 00053 00059 Current(T * t) : pushed(false) { 00060 if ( t ) { 00061 theStack.push_back(t); 00062 pushed = true; 00063 } 00064 } 00065 00070 ~Current() { 00071 if ( pushed ) theStack.pop_back(); 00072 } 00073 00074 public: 00075 00079 static bool isVoid() { 00080 return theStack.empty() || !(theStack.back()); 00081 } 00082 00086 static T & current() { 00087 return *theStack.back(); 00088 } 00089 00093 T * operator->() const { 00094 return theStack.back(); 00095 } 00096 00097 private: 00098 00102 static vector<T *> theStack; 00103 00108 bool pushed; 00109 00110 private: 00111 00115 Current<T> & operator=(const Current<T> &); 00116 00117 }; 00118 00119 template <typename T> 00120 std::vector<T *> ThePEG::Current<T>::theStack; 00121 00122 } 00123 00124 #endif /* ThePEG_Current_H */