00001 // -*- C++ -*- 00002 // 00003 // Direction.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_Direction_H 00010 #define ThePEG_Direction_H 00011 // This is the declaration of the Direction class. 00012 00013 #include "ThePEG/Config/ThePEG.h" 00014 #include "Direction.xh" 00015 00016 namespace ThePEG { 00017 00018 template <int I> 00041 class Direction { 00042 00043 public: 00044 00046 enum Dir { Neg = -1, 00047 Negative = -1, 00048 Undefined = 0, 00049 Pos = 1, 00050 Positive = 1 00051 }; 00052 00053 public: 00054 00058 Direction(Dir newDirection) 00059 00060 { 00061 if ( theDirection != Undefined ) throw MultipleDirectionException(I); 00062 if ( newDirection == Positive ) theDirection = Positive; 00063 else if ( newDirection == Negative ) theDirection = Negative; 00064 else throw UndefinedDirectionException(I); 00065 } 00066 00071 Direction(double rnd) 00072 { 00073 if ( theDirection != Undefined ) throw MultipleDirectionException(I); 00074 theDirection = rnd > 0 ? Positive : Negative; 00075 } 00076 00081 Direction(bool p) 00082 { 00083 if ( theDirection != Undefined ) throw MultipleDirectionException(I); 00084 theDirection = p ? Positive : Negative; 00085 } 00086 00090 ~Direction() { theDirection = Undefined; } 00091 00092 public: 00093 00097 static void set(Dir newDirection) { 00098 if ( newDirection == Positive ) theDirection = Positive; 00099 else if ( newDirection == Negative ) theDirection = Negative; 00100 else throw UndefinedDirectionException(I); 00101 } 00102 00106 static void reverse() { 00107 theDirection = pos() ? Negative : Positive; 00108 } 00109 00113 static bool pos() { 00114 return dir() == Positive; 00115 } 00116 00120 static bool neg() { 00121 return dir() == Negative; 00122 } 00123 00127 static Dir dir() { 00128 if ( theDirection == Undefined ) throw UndefinedDirectionException(I); 00129 return theDirection; 00130 } 00131 00132 private: 00133 00137 static Dir theDirection; 00138 00139 private: 00140 00144 Direction(); 00148 Direction(const Direction &); 00152 Direction & operator=(const Direction &); 00153 00154 }; 00155 00156 template<int I> 00157 typename Direction<I>::Dir Direction<I>::theDirection = Direction<I>::Undefined; 00158 00159 } 00160 00161 #endif /* ThePEG_Direction_H */