thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
Direction.h
1 // -*- C++ -*-
2 //
3 // Direction.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef ThePEG_Direction_H
10 #define ThePEG_Direction_H
11 // This is the declaration of the Direction class.
12 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "Direction.xh"
15 
16 namespace ThePEG {
17 
18 template <int I>
41 class Direction {
42 
43 public:
44 
46  enum Dir { Neg = -1,
47  Negative = -1,
48  Undefined = 0,
49  Pos = 1,
50  Positive = 1
51  };
52 
53 public:
54 
58  Direction(Dir newDirection)
59 
60  {
61  if ( theDirection != Undefined ) throw MultipleDirectionException(I);
62  if ( newDirection == Positive ) theDirection = Positive;
63  else if ( newDirection == Negative ) theDirection = Negative;
64  else throw UndefinedDirectionException(I);
65  }
66 
71  Direction(double rnd)
72  {
73  if ( theDirection != Undefined ) throw MultipleDirectionException(I);
74  theDirection = rnd > 0 ? Positive : Negative;
75  }
76 
81  Direction(bool p)
82  {
83  if ( theDirection != Undefined ) throw MultipleDirectionException(I);
85  }
86 
91 
92 public:
93 
97  static void set(Dir newDirection) {
98  if ( newDirection == Positive ) theDirection = Positive;
99  else if ( newDirection == Negative ) theDirection = Negative;
100  else throw UndefinedDirectionException(I);
101  }
102 
106  static void reverse() {
108  }
109 
113  static bool pos() {
114  return dir() == Positive;
115  }
116 
120  static bool neg() {
121  return dir() == Negative;
122  }
123 
127  static Dir dir() {
128  if ( theDirection == Undefined ) throw UndefinedDirectionException(I);
129  return theDirection;
130  }
131 
132 private:
133 
138 
139 private:
140 
144  Direction();
148  Direction(const Direction &);
152  Direction & operator=(const Direction &) = delete;
153 
154 };
155 
156 template<int I>
158 
159 }
160 
161 #endif /* ThePEG_Direction_H */
static Dir dir()
Return the direction.
Definition: Direction.h:127
Direction(bool p)
Create an object with a positive direction if p is true, otherwise set the negative direction...
Definition: Direction.h:81
static void reverse()
Reverse the direction.
Definition: Direction.h:106
~Direction()
Destructure makeing the static variable undefined.
Definition: Direction.h:90
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Standard (positive) direction.
Definition: Direction.h:50
This is the main config header file for ThePEG.
Reversed direction.
Definition: Direction.h:47
static bool pos()
Return true if the direction is positive.
Definition: Direction.h:113
static Dir theDirection
The direction.
Definition: Direction.h:137
Direction()
Default ctors and assignment is private and not implemented.
Dir
The enum defining the directions.
Definition: Direction.h:46
No direction has been defined.
Definition: Direction.h:48
Direction(double rnd)
Create an object with a positive direction if rnd > 0.5, otherwise set the negative direction...
Definition: Direction.h:71
static bool neg()
Return true if the direction is negative (reversed).
Definition: Direction.h:120
Direction & operator=(const Direction &)=delete
Default ctors and assignment is private and not implemented.
Standard (positive) direction.
Definition: Direction.h:49
Direction(Dir newDirection)
Create an object with a given direction.
Definition: Direction.h:58
A Direction object can be used to specify that some following operations should be assumed to be perf...
Definition: Direction.h:41
Reversed direction.
Definition: Direction.h:46