Starting ex03

This commit is contained in:
2026-02-18 10:31:00 +01:00
parent f96fb516ff
commit 39ec747514
14 changed files with 960 additions and 0 deletions

125
ex03/AForm/AForm.cpp Normal file
View File

@@ -0,0 +1,125 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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"
#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");
}

60
ex03/AForm/AForm.hpp Normal file
View File

@@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* AForm.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#ifndef AForm_HPP
# define AForm_HPP
# include <iostream>
# include <string>
class Bureaucrat;
class AForm
{
private:
const std::string name;
bool isSigned;
const int gradeToSign;
const int gradeToExecute;
public:
AForm();
AForm(const AForm &other);
AForm& operator=(const AForm &other);
virtual ~AForm();
AForm(std::string name, int gradeToSign, int gradeToExecute);
std::string getName() const;
bool getIsSigned() const;
int getGradeToSign() const;
int getGradeToExecute() const;
void beSigned(const Bureaucrat &br);
virtual void execute(Bureaucrat const &executor) const = 0;
class GradeTooLowException : public std::exception {
public:
virtual const char *what() const throw();
};
class GradeTooHighException : public std::exception {
public:
virtual const char *what() const throw();
};
};
std::ostream& operator<<(std::ostream &os, const AForm &AForm);
#endif