-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticleType.cpp
executable file
·68 lines (49 loc) · 1.77 KB
/
ParticleType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Created by paolo on 02/11/2023.
//
#include "ParticleType.h"
#include <iostream>
#include <stdexcept>
ParticleType::ParticleType()
: name_{"undefined"}, isResonance_{false}, mass_{-1}, charge_{1},
width_{0} {}
ParticleType::ParticleType(const std::string &name, double mass, int charge)
: name_{name}, isResonance_{false}, mass_{mass}, charge_{charge} {
if (mass <= 0) {
throw std::runtime_error("Mass can't be negative!");
}
}
ParticleType::ParticleType(const std::string &name, double mass, int charge,
double width)
: name_{name}, isResonance_{true}, mass_{mass}, charge_{charge},
width_{width} {
if (mass <= 0) {
throw std::runtime_error("Mass can't be negative!");
}
}
ParticleType &ParticleType::operator=(ParticleType const &particle_type) {
auto name = const_cast<std::string *>(&name_);
*name = particle_type.name_;
auto mass = const_cast<double *>(&mass_);
*mass = particle_type.mass_;
auto isResonance = const_cast<bool *>(&isResonance_);
*isResonance = particle_type.isResonance_;
auto charge = const_cast<int *>(&charge_);
*charge = particle_type.charge_;
auto width = const_cast<double *>(&width_);
*width = particle_type.width_;
return *this;
}
bool ParticleType::isResonance() const { return isResonance_; }
const std::string &ParticleType::getName() const { return name_; }
double ParticleType::getMass() const { return mass_; }
int ParticleType::getCharge() const { return charge_; }
double ParticleType::getWidth() const { return width_; }
void ParticleType::print() const {
std::cout << "Tipo: " << name_ << '\n'
<< "Massa: " << mass_ << '\n'
<< "Carica: " << charge_ << '\n';
if (isResonance_) {
std::cout << "Larghezza" << width_ << '\n';
}
}