-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAForm.cpp
More file actions
95 lines (80 loc) · 1.74 KB
/
AForm.cpp
File metadata and controls
95 lines (80 loc) · 1.74 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
92
93
94
95
#include "AForm.hpp"
#include "Bureaucrat.hpp"
#include "print.hpp"
#include <iostream>
AForm::AForm ()
: _name ("default"), _signGrade (150), _execGrade (150), _isSigned (false)
{
}
AForm::AForm (const AForm &other)
: _name (other._name), _signGrade (other._signGrade),
_execGrade (other._execGrade), _isSigned (other._isSigned)
{
}
AForm &
AForm::operator= (const AForm &other)
{
this->_isSigned = other._isSigned;
return *this;
}
AForm::~AForm () {}
std::string
AForm::getName () const
{
return _name;
}
int
AForm::getSignGrade () const
{
return _signGrade;
}
int
AForm::getExecGrade () const
{
return _execGrade;
}
bool
AForm::isSigned () const
{
return _isSigned;
}
void
AForm::beSigned (const Bureaucrat &bureaucrat)
{
if (bureaucrat.getGrade () > _signGrade)
throw Bureaucrat::GradeTooLowException ();
_isSigned = true;
}
std::ostream &
operator<< (std::ostream &out, const AForm &object)
{
out << "AForm: " << object.getName ()
<< ", sign grade: " << object.getSignGrade ()
<< ", exec grade: " << object.getExecGrade ()
<< ", signed: " << object.isSigned ();
return out;
}
AForm::AForm (int signGrade, int execGrade, std::string name)
: _name (name), _signGrade (signGrade), _execGrade (execGrade),
_isSigned (false)
{
if (signGrade < 1 || execGrade < 1)
throw AForm::GradeTooHighException ();
else if (signGrade > 150 || execGrade > 150)
throw AForm::GradeTooLowException ();
}
const char *
AForm::GradeTooLowException::what () const throw ()
{
return "Grade is too low";
}
const char *
AForm::GradeTooHighException::what () const throw ()
{
return "Grade is too high";
}
const char *
AForm::FormNotSignedException::what () const throw ()
{
return "Form is not signed";
}