125 lines
3.2 KiB
C++
125 lines
3.2 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* AForm.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/02/21 12:12:17 by aortigos #+# #+# */
|
|
/* Updated: 2026/02/21 12:12:17 by aortigos ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "AForm.hpp"
|
|
#include "../Bureaucrat/Bureaucrat.hpp"
|
|
|
|
//////////////////
|
|
//Constructores //
|
|
//////////////////
|
|
|
|
AForm::AForm() : name("NULL"), isSigned(false), gradeToSign(1), gradeToExecute(1)
|
|
{
|
|
//std::cout << "AForm default constructor called" << std::endl;
|
|
}
|
|
|
|
AForm::AForm(std::string name, int gradeToSign, int gradeToExecute)
|
|
: name(name), isSigned(false),
|
|
gradeToSign(gradeToSign), gradeToExecute(gradeToExecute)
|
|
{
|
|
if (gradeToSign > 150 || gradeToExecute > 150)
|
|
throw GradeTooLowException();
|
|
else if (gradeToSign < 1 || gradeToExecute < 1)
|
|
throw GradeTooHighException();
|
|
//std::cout << "AForm constructor with params called" << std::endl;
|
|
}
|
|
|
|
AForm::AForm(const AForm &other) :
|
|
name (other.getName()), isSigned(other.getIsSigned()),
|
|
gradeToSign(other.getGradeToSign()),
|
|
gradeToExecute(other.getGradeToExecute())
|
|
{
|
|
//std::cout << "AForm copy constructor called" << std::endl;
|
|
}
|
|
|
|
AForm& AForm::operator=(const AForm &other)
|
|
{
|
|
if (this != &other)
|
|
this->isSigned = other.getIsSigned();
|
|
//std::cout << "AForm copy assigment operator called" << std::endl;
|
|
return (*this);
|
|
}
|
|
|
|
AForm::~AForm()
|
|
{
|
|
//std::cout << "Destructor called"
|
|
}
|
|
|
|
//////////////////
|
|
// Getters //
|
|
//////////////////
|
|
|
|
std::string AForm::getName() const
|
|
{
|
|
return (this->name);
|
|
}
|
|
|
|
bool AForm::getIsSigned() const
|
|
{
|
|
return (this->isSigned);
|
|
}
|
|
|
|
int AForm::getGradeToSign() const
|
|
{
|
|
return (this->gradeToSign);
|
|
}
|
|
|
|
int AForm::getGradeToExecute() const
|
|
{
|
|
return (this->gradeToExecute);
|
|
}
|
|
|
|
|
|
//////////////////
|
|
// SignAForm //
|
|
//////////////////
|
|
|
|
void AForm::beSigned(const Bureaucrat &br)
|
|
{
|
|
if (this->gradeToSign < br.getGrade())
|
|
throw GradeTooLowException();
|
|
this->isSigned = true;
|
|
}
|
|
|
|
|
|
//////////////////
|
|
// << //
|
|
//////////////////
|
|
|
|
std::ostream& operator<<(std::ostream &os, const AForm &form)
|
|
{
|
|
std::string isItSigned;
|
|
|
|
if (form.getIsSigned())
|
|
{
|
|
isItSigned = " is signed.";
|
|
} else {
|
|
isItSigned = " is not signed.";
|
|
}
|
|
|
|
os << form.getName() << isItSigned;
|
|
return (os);
|
|
}
|
|
|
|
|
|
//////////////////
|
|
// Excepciones //
|
|
//////////////////
|
|
const char* AForm::GradeTooLowException::what() const throw()
|
|
{
|
|
return ("grade too low");
|
|
}
|
|
|
|
const char* AForm::GradeTooHighException::what() const throw()
|
|
{
|
|
return ("grade too high");
|
|
} |