ex01
This commit is contained in:
124
ex01/Form/Form.cpp
Normal file
124
ex01/Form/Form.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Form.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 "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, 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 << "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");
|
||||
}
|
||||
56
ex01/Form/Form.hpp
Normal file
56
ex01/Form/Form.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Form.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 FORM_HPP
|
||||
|
||||
# define FORM_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include "../Bureaucrat/Bureaucrat.hpp"
|
||||
|
||||
class Form
|
||||
{
|
||||
private:
|
||||
const std::string name;
|
||||
bool isSigned;
|
||||
const int gradeToSign;
|
||||
const int gradeToExecute;
|
||||
|
||||
public:
|
||||
Form();
|
||||
Form(const Form &other);
|
||||
Form& operator=(const Form &other);
|
||||
~Form();
|
||||
|
||||
Form(std::string name, bool isSigned, int gradeToSign, int gradeToExecute);
|
||||
|
||||
std::string getName() const;
|
||||
bool getIsSigned() const;
|
||||
int getGradeToSign() const;
|
||||
int getGradeToExecute() const;
|
||||
|
||||
void beSigned(const Bureaucrat &br);
|
||||
|
||||
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 Form &form);
|
||||
|
||||
#endif
|
||||
BIN
ex01/Form/Form.o
Normal file
BIN
ex01/Form/Form.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user