blob: 12b0a95300b1076215b22f0dfaf3053232d222bd (
plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Form.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 19:26:39 by charles #+# #+# */
/* Updated: 2020/10/19 13:20:29 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "Form.hpp"
Form::Form()
: m_name(""),
m_gradeSign(1),
m_gradeExecute(1)
{}
Form::Form(Form const& other)
: m_name(other.m_name),
m_signed(other.m_signed),
m_gradeSign(other.m_gradeSign),
m_gradeExecute(other.m_gradeExecute)
{}
Form& Form::operator=(Form const& other)
{
m_signed = other.m_signed;
return *this;
}
Form::~Form() {}
Form::Form(std::string const& name)
: m_name(name),
m_signed(false),
m_gradeSign(1),
m_gradeExecute(1)
{}
std::string const& Form::getName() const { return m_name; }
bool Form::getSigned() const { return m_signed; }
int Form::getGradeSign() const { return m_gradeSign; }
int Form::getGradeExecute() const { return m_gradeExecute; }
void Form::beSigned(Bureaucrat const& b)
{
if (b.getGrade() >= m_gradeSign)
m_signed = true;
}
///////////////////////////////////////////////////////////////////////////////
// Exceptions
///////////////////////////////////////////////////////////////////////////////
Form::GradeTooHighException::GradeTooHighException() : std::exception() {}
Form::GradeTooHighException::GradeTooHighException(GradeTooHighException const& other)
: std::exception(other)
{}
Form::GradeTooHighException&
Form::GradeTooHighException::operator=(GradeTooHighException const& other)
{
std::exception::operator=(other);
return *this;
}
Form::GradeTooHighException::~GradeTooHighException()
{}
char const* Form::GradeTooHighException::what() const throw()
{
return "Grade is too high for form";
}
Form::GradeTooLowException::GradeTooLowException() : std::exception()
{}
Form::GradeTooLowException::GradeTooLowException(GradeTooLowException const& other)
: std::exception(other)
{}
Form::GradeTooLowException&
Form::GradeTooLowException::operator=(GradeTooLowException const& other)
{
std::exception::operator=(other);
return *this;
}
Form::GradeTooLowException::~GradeTooLowException()
{}
char const* Form::GradeTooLowException::what() const throw()
{
return "Grade is too low for form";
}
std::ostream& operator<<(std::ostream& out, Form const& f)
{
out << f.getName() << " is "
<< (f.getSigned() ? "" : "not ") << "signed and needs at least"
<< f.getGradeSign() << " to be signed and "
<< f.getGradeExecute() << " to be executed" << std::endl;
return out;
}
|