1
0

」 feat: finished ex01 (normally)

This commit is contained in:
2025-03-30 16:18:58 +02:00
parent e5bf6c151c
commit 2b136d90f4
6 changed files with 27 additions and 24 deletions

View File

@ -6,11 +6,12 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 13:59:45 by adjoly #+# #+# */ /* Created: 2024/12/23 13:59:45 by adjoly #+# #+# */
/* Updated: 2025/03/29 16:49:20 by adjoly ### ########.fr */ /* Updated: 2025/03/30 15:13:43 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "Bureaucrat.hpp" #include "Bureaucrat.hpp"
#include "Form.hpp"
#include <exception> #include <exception>
void _log(std::string emoji, std::string what, std::string who, void _log(std::string emoji, std::string what, std::string who,
@ -102,9 +103,9 @@ const char *Bureaucrat::GradeTooLowException::what() const throw() {
void Bureaucrat::signForm(Form &f) { void Bureaucrat::signForm(Form &f) {
try { try {
f.getSigned(); f.beSigned(*this);
std::cout << _name << " signed " << f.getName() << std::endl; std::cout << _name << " signed " << f.getName() << std::endl;
} catch (std::exception &e) { } catch (std::exception &e) {
std::cout << _name << "counldn't sign " << f.getName() << " because " << e.what() << std::endl; std::cout << _name << " counldn't sign " << f.getName() << " because " << e.what() << std::endl;
} }
} }

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 13:59:43 by adjoly #+# #+# */ /* Created: 2024/12/23 13:59:43 by adjoly #+# #+# */
/* Updated: 2025/03/29 15:42:43 by adjoly ### ########.fr */ /* Updated: 2025/03/30 15:10:46 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,14 +6,14 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/09 17:38:19 by adjoly #+# #+# */ /* Created: 2025/03/09 17:38:19 by adjoly #+# #+# */
/* Updated: 2025/03/29 16:49:11 by adjoly ### ########.fr */ /* Updated: 2025/03/30 15:14:17 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "Form.hpp" #include "Form.hpp"
#include "Bureaucrat.hpp" #include "Bureaucrat.hpp"
Form::Form(void) : _name(""), _signed(false), _minForExec(1), _minForSign(1) { Form::Form(void) : _name(""), _signed(false), _minForSign(1), _minForExec(1) {
_log("", "Form", "", "default constructor called"); _log("", "Form", "", "default constructor called");
} }
Form::Form(std::string name, uint8_t minForSign, uint8_t minForExec) Form::Form(std::string name, uint8_t minForSign, uint8_t minForExec)
@ -25,17 +25,17 @@ Form::Form(std::string name, uint8_t minForSign, uint8_t minForExec)
Form::~Form(void) { _log("", "Form", "", "destructor called"); } Form::~Form(void) { _log("", "Form", "", "destructor called"); }
const char *Form::GradeTooHighException::what() const throw() { const char *Form::GradeTooHighException::what() const throw() {
return ("Grade is too high"); return ("grade is too high");
} }
const char *Form::GradeTooLowException::what() const throw() { const char *Form::GradeTooLowException::what() const throw() {
return ("Grade is too low"); return ("grade is too low");
} }
const std::string Form::getName(void) const { return _name; } std::string Form::getName(void) const { return _name; }
bool Form::getSigned(void) { return _signed; } bool Form::getSigned(void) const { return _signed; }
const uint8_t Form::getMinForSign(void) { return _minForSign; } uint8_t Form::getMinForSign(void) const { return _minForSign; }
const uint8_t Form::getMinForExec(void) { return _minForExec; } uint8_t Form::getMinForExec(void) const { return _minForExec; }
void Form::beSigned(Bureaucrat b) { void Form::beSigned(Bureaucrat b) {
if (_minForSign > b.getGrade()) { if (_minForSign > b.getGrade()) {
@ -45,5 +45,6 @@ void Form::beSigned(Bureaucrat b) {
} }
std::ostream &operator<<(std::ostream &os, Form &val) { std::ostream &operator<<(std::ostream &os, Form &val) {
os << "Form: " << val.getName() << ", minGrade to sign: " << os << "Form: " << val.getName() << ", minGrade to sign: " << val.getMinForSign() << ", min grade to execute: " << val.getMinForExec() << std::endl;
return (os);
} }

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/08 20:10:59 by adjoly #+# #+# */ /* Created: 2025/03/08 20:10:59 by adjoly #+# #+# */
/* Updated: 2025/03/29 15:43:02 by adjoly ### ########.fr */ /* Updated: 2025/03/30 15:11:58 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,8 @@ void _log(std::string emoji, std::string what, std::string who,
typedef unsigned char uint8_t; typedef unsigned char uint8_t;
class Bureaucrat; #include "Bureaucrat.hpp"
//class Bureaucrat;
class Form { class Form {
public: public:
@ -36,10 +37,10 @@ class Form {
virtual const char *what() const throw(); virtual const char *what() const throw();
}; };
const std::string getName(void) const; std::string getName(void) const;
bool getSigned(void); bool getSigned(void) const;
const uint8_t getMinForSign(void); uint8_t getMinForSign(void) const;
const uint8_t getMinForExec(void); uint8_t getMinForExec(void) const;
void beSigned(Bureaucrat); void beSigned(Bureaucrat);

View File

@ -6,13 +6,13 @@
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ # # By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# # # Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
# Updated: 2025/03/08 20:20:59 by adjoly ### ########.fr # # Updated: 2025/03/30 15:14:32 by adjoly ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
SHELL = bash SHELL = bash
NAME = Bureaucrat NAME = Form
CC = c++ CC = c++

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 14:01:11 by adjoly #+# #+# */ /* Created: 2024/12/23 14:01:11 by adjoly #+# #+# */
/* Updated: 2025/03/29 15:44:03 by adjoly ### ########.fr */ /* Updated: 2025/03/30 15:13:07 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -43,7 +43,7 @@ int main(void) {
} catch (const std::exception &e) { } catch (const std::exception &e) {
std::cerr << "Error : " << e.what() << std::endl; std::cerr << "Error : " << e.what() << std::endl;
} }
Form f; Form f("le contrattt", 5, 5);
su.signForm(f); su.signForm(f);