thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
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
14#include "Direction.xh"
15
16namespace ThePEG {
17
18template <int I>
41class Direction {
42
43public:
44
46 enum Dir { Neg = -1,
47 Negative = -1,
49 Pos = 1,
50 Positive = 1
51 };
52
53public:
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
92public:
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
132private:
133
138
139private:
140
152 Direction & operator=(const Direction &) = delete;
153
154};
155
156template<int I>
158
159}
160
161#endif /* ThePEG_Direction_H */
This is the main config header file for ThePEG.
A Direction object can be used to specify that some following operations should be assumed to be perf...
Definition: Direction.h:41
static Dir theDirection
The direction.
Definition: Direction.h:137
static bool neg()
Return true if the direction is negative (reversed).
Definition: Direction.h:120
Direction(bool p)
Create an object with a positive direction if p is true, otherwise set the negative direction.
Definition: Direction.h:81
Direction()
Default ctors and assignment is private and not implemented.
static void set(Dir newDirection)
Set the direction.
Definition: Direction.h:97
Direction(const Direction &)
Default ctors and assignment is private and not implemented.
static Dir dir()
Return the direction.
Definition: Direction.h:127
static bool pos()
Return true if the direction is positive.
Definition: Direction.h:113
Direction(Dir newDirection)
Create an object with a given direction.
Definition: Direction.h:58
Dir
The enum defining the directions.
Definition: Direction.h:46
@ Undefined
No direction has been defined.
Definition: Direction.h:48
@ Negative
Reversed direction.
Definition: Direction.h:47
@ Neg
Reversed direction.
Definition: Direction.h:46
@ Pos
Standard (positive) direction.
Definition: Direction.h:49
@ Positive
Standard (positive) direction.
Definition: Direction.h:50
Direction & operator=(const Direction &)=delete
Default ctors and assignment is private and not implemented.
~Direction()
Destructure makeing the static variable undefined.
Definition: Direction.h:90
static void reverse()
Reverse the direction.
Definition: Direction.h:106
Direction(double rnd)
Create an object with a positive direction if rnd > 0.5, otherwise set the negative direction.
Definition: Direction.h:71
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28