CPP05 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Form.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* Form.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/06/26 10:32:59 by kamitsui #+# #+# */
9/* Updated: 2025/06/29 06:18:19 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
18#include "Form.hpp"
19
20// --- Orthodox Canonical Form ---
30Form::Form(const std::string &name, int gradeToSign, int gradeToExecute)
31 : _name(name), _isSigned(false), _gradeToSign(gradeToSign), _gradeToExecute(gradeToExecute) {
32 if (gradeToSign < 1 || gradeToExecute < 1) {
34 }
35 if (gradeToSign > 150 || gradeToExecute > 150) {
37 }
38 std::cout << "Form " << _name << " created." << std::endl;
39}
40
44Form::Form(const Form &other)
45 : _name(other._name), _isSigned(other._isSigned), _gradeToSign(other._gradeToSign),
46 _gradeToExecute(other._gradeToExecute) {
47 std::cout << "Form " << _name << " has been copied." << std::endl;
48}
49
54Form &Form::operator=(const Form &other) {
55 if (this != &other) {
56 _isSigned = other._isSigned;
57 }
58 std::cout << "Form " << _name << "'s status has been assigned from " << other._name << "." << std::endl;
59 return *this;
60}
61
65Form::~Form() { std::cout << "Form " << _name << " destroyed." << std::endl; }
66
67// --- Getters ---
68const std::string &Form::getName() const { return _name; }
69bool Form::getIsSigned() const { return _isSigned; }
70int Form::getGradeToSign() const { return _gradeToSign; }
71int Form::getGradeToExecute() const { return _gradeToExecute; }
72
73// --- Member Functions ---
79void Form::beSigned(const Bureaucrat &bureaucrat) {
80 if (bureaucrat.getGrade() > _gradeToSign) {
82 }
83 _isSigned = true;
84}
85
86// --- Exception Implementations ---
91const char *Form::GradeTooHighException::what() const throw() { return "Form grade is too high"; }
92
97const char *Form::GradeTooLowException::what() const throw() { return "Form grade is too low"; }
98
99// --- Operator Overload ---
107 os << "Form '" << form.getName() << "':\n"
108 << " Signed Status: " << (form.getIsSigned() ? "Signed" : "Not Signed") << "\n"
109 << " Grade to Sign: " << form.getGradeToSign() << "\n"
110 << " Grade to Execute: " << form.getGradeToExecute();
111 return os;
112}
Defines the Form class and its exceptions.
std::ostream & operator<<(std::ostream &os, const Form &form)
Overloads the << operator to print Form information.
Definition Form.cpp:106
Represents a bureaucrat with a name and a grade.
int getGrade() const
Gets the grade of the Bureaucrat.
virtual const char * what() const
Definition Form.cpp:91
virtual const char * what() const
Definition Form.cpp:97
Represents a form that needs to be signed and executed.
Definition Form.hpp:32
void beSigned(const Bureaucrat &bureaucrat)
Sets the form's status to signed if the bureaucrat's grade is sufficient.
Definition Form.cpp:79
bool getIsSigned() const
Definition Form.cpp:69
Form & operator=(const Form &other)
Assignment operator for Form. Only the signed status is copied as other members are const.
Definition Form.cpp:54
const std::string & getName() const
Definition Form.cpp:68
~Form()
Destroys the Form object.
Definition Form.cpp:65
int getGradeToExecute() const
Definition Form.cpp:71
int getGradeToSign() const
Definition Form.cpp:70
T endl(T... args)