-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAForm.cpp
More file actions
91 lines (78 loc) · 2.86 KB
/
AForm.cpp
File metadata and controls
91 lines (78 loc) · 2.86 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* AForm.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zelhajou <zelhajou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/26 10:18:51 by zelhajou #+# #+# */
/* Updated: 2024/12/30 16:29:34 by zelhajou ### ########.fr */
/* */
/* ************************************************************************** */
#include "AForm.hpp"
#include "Bureaucrat.hpp"
AForm::AForm() : _name("default"), _isSigned(false), _gradeToSign(150), _gradeToExecute(150) {}
AForm::AForm(const std::string &name, int gradeToSign, int gradeToExecute) : _name(name), _isSigned(false), _gradeToSign(gradeToSign), _gradeToExecute(gradeToExecute)
{
if (gradeToSign < 1 || gradeToExecute < 1)
throw GradeTooHighException();
if (gradeToSign > 150 || gradeToExecute > 150)
throw GradeTooLowException();
}
AForm::AForm(const AForm &src) : _name(src._name), _isSigned(src._isSigned), _gradeToSign(src._gradeToSign), _gradeToExecute(src._gradeToExecute) {}
AForm::~AForm() {}
AForm &AForm::operator=(const AForm &src)
{
if (this != &src)
_isSigned = src._isSigned;
return *this;
}
const std::string &AForm::getName() const
{
return _name;
}
bool AForm::getIsSigned() const
{
return _isSigned;
}
int AForm::getGradeToSign() const
{
return _gradeToSign;
}
int AForm::getGradeToExecute() const
{
return _gradeToExecute;
}
void AForm::beSigned(const Bureaucrat &bureaucrat)
{
if (bureaucrat.getGrade() > _gradeToSign)
throw GradeTooLowException();
_isSigned = true;
}
void AForm::checkExecution(const Bureaucrat &executor) const
{
if (!_isSigned)
throw FormNotSignedException();
if (executor.getGrade() > _gradeToExecute)
throw GradeTooLowException();
}
const char *AForm::GradeTooHighException::what() const throw()
{
return "Grade too high";
}
const char *AForm::GradeTooLowException::what() const throw()
{
return "Grade too low";
}
const char *AForm::FormNotSignedException::what() const throw()
{
return "Form must be signed before execution";
}
std::ostream &operator<<(std::ostream &os, const AForm &form)
{
os << "Form " << form.getName()
<< "\n- Status: " << (form.getIsSigned() ? "signed" : "not signed")
<< "\n- Grade to sign: " << form.getGradeToSign()
<< "\n- Grade to execute: " << form.getGradeToExecute();
return os;
}