ex02 created
This commit is contained in:
124
ex02/AForm/AForm.cpp
Normal file
124
ex02/AForm/AForm.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* AForm.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/02/15 18:00:27 by aortigos #+# #+# */
|
||||
/* Updated: 2026/02/06 02:28:09 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "AForm.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, bool isSigned, int gradeToSign, int gradeToExecute)
|
||||
: name(name), isSigned(isSigned),
|
||||
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");
|
||||
}
|
||||
Reference in New Issue
Block a user