MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
marley::Parity Class Reference

Type-safe representation of a parity value (either +1 or -1) More...

#include <Parity.hh>

Public Member Functions

constexpr Parity ()
 Default constructor chooses positive parity.
 
constexpr Parity (bool is_positive)
 Create a Parity object from a boolean value.
 
 Parity (int i)
 Create a Parity object from an integer.
 
void from_char (const char c)
 Assign a value to this Parity object from a char.
 
constexpr operator bool () const
 Convert the Parity object to a bool (true for +1, false for -1)
 
 operator int () const
 
Parityoperator! ()
 Unary operator that flips a Parity value in place.
 
bool operator!= (const marley::Parity &p) const
 
int operator* (const int &i) const
 
marley::Parity operator* (const marley::Parity &p) const
 
constexpr marley::Parity operator- () const
 Creates a copy of the Parity object with a flipped value.
 
marley::Parityoperator= (const int &i)
 Assigns a parity value using an integer.
 
bool operator== (const marley::Parity &p) const
 
char to_char () const
 Convert the Parity object to a char.
 

Protected Attributes

bool is_positive_
 Boolean representation of the parity value that is true when the parity is +1 and false when it is -1.
 

Detailed Description

Type-safe representation of a parity value (either +1 or -1)

Definition at line 25 of file Parity.hh.

Constructor & Destructor Documentation

◆ Parity() [1/3]

marley::Parity::Parity ( )
inlineconstexpr

Default constructor chooses positive parity.

Definition at line 30 of file Parity.hh.

30: is_positive_(true) {}
bool is_positive_
Boolean representation of the parity value that is true when the parity is +1 and false when it is -1...
Definition Parity.hh:104

References is_positive_.

Referenced by operator!().

◆ Parity() [2/3]

marley::Parity::Parity ( bool is_positive)
inlineexplicitconstexpr

Create a Parity object from a boolean value.

Parameters
is_positiveBoolean parameter that is true for +1, or false for -1.

Definition at line 35 of file Parity.hh.

36 : is_positive_(is_positive) {}

References is_positive_.

◆ Parity() [3/3]

marley::Parity::Parity ( int i)
explicit

Create a Parity object from an integer.

If an int value other than +1 or -1 is passed to this constructor, a marley::Error will be thrown.

Definition at line 25 of file Parity.cc.

25 {
26 if (i == 1) is_positive_ = true;
27 else if (i == -1) is_positive_ = false;
28 else throw marley::Error( "Invalid parity " + std::to_string(i)
29 + " passed to constructor of marley::Parity" );
30}

References is_positive_.

Member Function Documentation

◆ from_char()

void marley::Parity::from_char ( const char c)

Assign a value to this Parity object from a char.

Definition at line 46 of file Parity.cc.

46 {
47 if ( c == '+' ) is_positive_ = true;
48 else if ( c == '-' ) is_positive_ = false;
49 else throw marley::Error( std::string("Invalid parity character \"") + c
50 + "\" encountered in marley::Parity::from_char()" );
51}

References is_positive_.

◆ operator bool()

marley::Parity::operator bool ( ) const
inlineexplicitconstexpr

Convert the Parity object to a bool (true for +1, false for -1)

Definition at line 44 of file Parity.hh.

44{ return is_positive_; }

References is_positive_.

◆ operator int()

marley::Parity::operator int ( ) const
inlineexplicit
Todo
See comments for marley::TargetAtom::operator int(). A similar situation occurs for this function.

Definition at line 86 of file Parity.hh.

86 {
87 if (is_positive_) return 1;
88 else return -1;
89 }

References is_positive_.

◆ operator!()

Parity & marley::Parity::operator! ( )
inline

Unary operator that flips a Parity value in place.

Definition at line 52 of file Parity.hh.

52 {
54 return *this;
55 }

References Parity(), and is_positive_.

◆ operator!=()

bool marley::Parity::operator!= ( const marley::Parity & p) const
inline

Definition at line 67 of file Parity.hh.

68 {
69 return is_positive_ != p.is_positive_;
70 }

◆ operator*() [1/2]

int marley::Parity::operator* ( const int & i) const
inline

Definition at line 77 of file Parity.hh.

78 {
79 if (is_positive_) return i;
80 else return -i;
81 }

◆ operator*() [2/2]

marley::Parity marley::Parity::operator* ( const marley::Parity & p) const
inline

Definition at line 72 of file Parity.hh.

73 {
74 return marley::Parity(is_positive_ == p.is_positive_);
75 }

◆ operator-()

marley::Parity marley::Parity::operator- ( ) const
inlineconstexpr

Creates a copy of the Parity object with a flipped value.

Definition at line 47 of file Parity.hh.

47 {
48 return marley::Parity(!is_positive_);
49 }

References is_positive_.

◆ operator=()

marley::Parity & marley::Parity::operator= ( const int & i)

Assigns a parity value using an integer.

If an int value other than +1 or -1 is used, a marley::Error will be thrown.

Definition at line 35 of file Parity.cc.

35 {
36 // Do the assignment
37 if (i == 1) is_positive_ = true;
38 else if (i == -1) is_positive_ = false;
39 else throw marley::Error( "Invalid parity " + std::to_string(i)
40 + " assigned to variable of type marley::Parity" );
41
42 // Return the existing object
43 return *this;
44}

References is_positive_.

◆ operator==()

bool marley::Parity::operator== ( const marley::Parity & p) const
inline

Definition at line 62 of file Parity.hh.

63 {
64 return is_positive_ == p.is_positive_;
65 }

◆ to_char()

char marley::Parity::to_char ( ) const
inline

Convert the Parity object to a char.

Definition at line 92 of file Parity.hh.

92 {
93 if (is_positive_) return '+';
94 else return '-';
95 }

References is_positive_.

Member Data Documentation

◆ is_positive_

bool marley::Parity::is_positive_
protected

Boolean representation of the parity value that is true when the parity is +1 and false when it is -1.

Definition at line 104 of file Parity.hh.

Referenced by Parity(), Parity(), Parity(), from_char(), operator bool(), operator int(), operator!(), operator-(), operator=(), and to_char().


The documentation for this class was generated from the following files: