Files
cpp05/ex01/Form/Form.cpp
2026-02-21 12:15:22 +01:00

124 lines
3.2 KiB
C++

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