CPP05 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
AForm.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* AForm.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/06/30 12:11:36 by kamitsui #+# #+# */
9/* Updated: 2025/06/30 12:11:43 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
18#include "AForm.hpp"
19
20AForm::AForm(const std::string &name, int gradeToSign, int gradeToExecute, const std::string &target)
21 : _name(name), _isSigned(false), _gradeToSign(gradeToSign), _gradeToExecute(gradeToExecute), _target(target) {
22 if (gradeToSign < 1 || gradeToExecute < 1)
24 if (gradeToSign > 150 || gradeToExecute > 150)
26}
27
28AForm::AForm(const AForm &other)
29 : _name(other._name), _isSigned(other._isSigned), _gradeToSign(other._gradeToSign),
30 _gradeToExecute(other._gradeToExecute), _target(other._target) {}
31
33 if (this != &other) {
34 _isSigned = other._isSigned;
35 }
36 return *this;
37}
38
40
41// Getters
42const std::string &AForm::getName() const { return _name; }
43bool AForm::getIsSigned() const { return _isSigned; }
44int AForm::getGradeToSign() const { return _gradeToSign; }
45int AForm::getGradeToExecute() const { return _gradeToExecute; }
46const std::string &AForm::getTarget() const { return _target; }
47
48void AForm::beSigned(const Bureaucrat &bureaucrat) {
49 if (bureaucrat.getGrade() > _gradeToSign) {
51 }
52 _isSigned = true;
53}
54
61void AForm::execute(Bureaucrat const &executor) const {
62 if (!this->getIsSigned()) {
64 }
65 if (executor.getGrade() > this->getGradeToExecute()) {
67 }
68 this->performAction();
69}
70
71// --- Exception Implementations ---
72const char *AForm::GradeTooHighException::what() const throw() { return "Grade is too high"; }
73const char *AForm::GradeTooLowException::what() const throw() { return "Grade is too low"; }
74const char *AForm::FormNotSignedException::what() const throw() { return "Form is not signed"; }
75
76// --- Operator Overload ---
78 os << "Form '" << form.getName() << "' (Target: " << form.getTarget() << ")\n"
79 << " - Signed Status: " << (form.getIsSigned() ? "Signed" : "Not Signed") << "\n"
80 << " - Grade to Sign: " << form.getGradeToSign() << "\n"
81 << " - Grade to Execute: " << form.getGradeToExecute();
82 return os;
83}
virtual const char * what() const
Definition AForm.cpp:74
virtual const char * what() const
Definition AForm.cpp:72
virtual const char * what() const
Definition AForm.cpp:73
An abstract base class for forms.
Definition AForm.hpp:34
virtual ~AForm()
Definition AForm.cpp:39
void execute(Bureaucrat const &executor) const
Central execution logic. Checks requirements before calling specific action.
Definition AForm.cpp:61
int getGradeToSign() const
Definition AForm.cpp:44
int getGradeToExecute() const
Definition AForm.cpp:45
bool getIsSigned() const
Definition AForm.cpp:43
const std::string & getName() const
Definition AForm.cpp:42
virtual void performAction() const =0
const std::string & getTarget() const
Definition AForm.cpp:46
void beSigned(const Bureaucrat &bureaucrat)
Definition AForm.cpp:48
AForm & operator=(const AForm &other)
Definition AForm.cpp:32
Represents a bureaucrat with a name and a grade.
int getGrade() const
Gets the grade of the Bureaucrat.
Defines the abstract base class AForm for all specific forms.
std::ostream & operator<<(std::ostream &os, const AForm &form)
Definition AForm.cpp:77