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
Parity.cc
1
4//
5// This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6//
7// MARLEY is free software: you can redistribute it and/or modify it under the
8// terms of version 3 of the GNU General Public License as published by the
9// Free Software Foundation.
10//
11// For the full text of the license please see COPYING or
12// visit http://opensource.org/licenses/GPL-3.0
13//
14// Please respect the MCnet academic usage guidelines. See GUIDELINES
15// or visit https://www.montecarlonet.org/GUIDELINES for details.
16
17// Standard library includes
18#include <istream>
19#include <string>
20
21// MARLEY includes
22#include "marley/Error.hh"
23#include "marley/Parity.hh"
24
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}
31
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}
45
46void marley::Parity::from_char( const char c ) {
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}
52
53std::istream& operator>>(std::istream& in, marley::Parity& p) {
54 // Read in the next non-whitespace character
55 char c;
56 in >> std::ws >> c;
57
58 // If we suceeded in reading one, then convert it to a parity value
59 if ( in ) p.from_char( c );
60
61 // Either way, return the input stream
62 return in;
63}
Base class for all exceptions thrown by MARLEY functions.
Definition Error.hh:26
Type-safe representation of a parity value (either +1 or -1)
Definition Parity.hh:25
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
void from_char(const char c)
Assign a value to this Parity object from a char.
Definition Parity.cc:46
constexpr Parity()
Default constructor chooses positive parity.
Definition Parity.hh:30
marley::Parity & operator=(const int &i)
Assigns a parity value using an integer.
Definition Parity.cc:35