「🎉」 init: hello world !
This commit is contained in:
95
ex00/Bureaucrat.cpp
Normal file
95
ex00/Bureaucrat.cpp
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Bureaucrat.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/18 20:11:39 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/06/27 13:35:28 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str)
|
||||||
|
{
|
||||||
|
#ifdef VERBOSE
|
||||||
|
if (who.empty())
|
||||||
|
std::cout << "「" << emoji << "」" << what << ": " << str << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str
|
||||||
|
<< std::endl;
|
||||||
|
#else
|
||||||
|
(void)emoji, (void)what, (void)who, (void)str;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(void)
|
||||||
|
: _name("kanel"), _grade(69)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(const Bureaucrat &cpy)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "copy constructor called");
|
||||||
|
if (&cpy != this)
|
||||||
|
{
|
||||||
|
_name = cpy.getName();
|
||||||
|
_grade = cpy.getGrade();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(std::string name, uint8_t grade)
|
||||||
|
: _name(name), _grade(grade)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Bureaucrat::getName(void) const { return _name; }
|
||||||
|
uint8_t Bureaucrat::getGrade(void) const { return _grade; }
|
||||||
|
|
||||||
|
Bureaucrat::~Bureaucrat(void)
|
||||||
|
{
|
||||||
|
_log("➖", "Bureaucrat", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy)
|
||||||
|
{
|
||||||
|
if (&cpy == this)
|
||||||
|
return *this;
|
||||||
|
_grade = cpy._grade;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::IncrementGrade(void)
|
||||||
|
{
|
||||||
|
if (_grade - 1 < MAXGRADE)
|
||||||
|
throw GradeTooHighException();
|
||||||
|
_grade--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::DecrementGrade(void)
|
||||||
|
{
|
||||||
|
if (_grade + 1 > MINGRADE)
|
||||||
|
throw GradeTooLowException();
|
||||||
|
_grade++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, Bureaucrat &val)
|
||||||
|
{
|
||||||
|
os << val.getName() << ", bureaucrat grade " << (int)val.getGrade();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Bureaucrat::GradeTooHighException::what() const throw()
|
||||||
|
{
|
||||||
|
return ("Grade is too high");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Bureaucrat::GradeTooLowException::what() const throw()
|
||||||
|
{
|
||||||
|
return ("Grade is too low");
|
||||||
|
}
|
||||||
59
ex00/Bureaucrat.hpp
Normal file
59
ex00/Bureaucrat.hpp
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Bureaucrat.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/18 20:11:25 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/06/27 13:35:33 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str);
|
||||||
|
|
||||||
|
class Form;
|
||||||
|
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
|
||||||
|
#define MAXGRADE 1
|
||||||
|
#define MINGRADE 150
|
||||||
|
|
||||||
|
class Bureaucrat {
|
||||||
|
public:
|
||||||
|
Bureaucrat(void);
|
||||||
|
Bureaucrat(const Bureaucrat &cpy);
|
||||||
|
Bureaucrat(std::string name, uint8_t grade);
|
||||||
|
~Bureaucrat(void);
|
||||||
|
|
||||||
|
Bureaucrat &operator=(const Bureaucrat& other);
|
||||||
|
|
||||||
|
const std::string &getName(void) const;
|
||||||
|
uint8_t getGrade(void) const;
|
||||||
|
|
||||||
|
void IncrementGrade(void);
|
||||||
|
void DecrementGrade(void);
|
||||||
|
|
||||||
|
class GradeTooHighException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
class GradeTooLowException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
uint8_t _grade;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &, Bureaucrat &);
|
||||||
58
ex00/Makefile
Normal file
58
ex00/Makefile
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2024/01/22 07:21:18 by mmoussou #+# #+# #
|
||||||
|
# Updated: 2025/06/19 01:08:50 by mmoussou ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
SHELL = bash
|
||||||
|
|
||||||
|
RED = \033[0;31m
|
||||||
|
GREEN = \033[0;32m
|
||||||
|
YELLOW = \033[1;33m
|
||||||
|
PURPLE = \e[0;35m
|
||||||
|
NC = \033[0m
|
||||||
|
DELETE = \x1B[2K
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
|
||||||
|
FLAGS = -std=c++98 -Wall -Werror -Wextra
|
||||||
|
|
||||||
|
INCLUDES = .
|
||||||
|
|
||||||
|
NAME = ex00
|
||||||
|
|
||||||
|
SRCS = main.cpp Bureaucrat.cpp
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@$(CC) $(FLAGS) -I$(INCLUDES) $(OBJS) -o $(NAME)
|
||||||
|
@printf "$(NC)$(YELLOW)「✨」 feat($(NAME)): program compiled\n$(NC)"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.cpp
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) $(FLAGS) -I$(INCLUDES) -c $< -o $@
|
||||||
|
@printf "$(NC)$(GREEN)「🔨」 build($<): object compiled\n$(NC)"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJS)
|
||||||
|
@printf "$(NC)$(RED)「🗑️」 clean($(OBJS)): object deleted\n$(NC)"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@rm -Rf $(OBJSDIR)
|
||||||
|
@printf "$(NC)$(RED)「🗑️」 fclean($(NAME)): program deleted\n$(NC)"
|
||||||
|
|
||||||
|
re: fclean
|
||||||
|
@$(MAKE) -s all
|
||||||
|
|
||||||
|
.PHONY: clean fclean all re
|
||||||
49
ex00/main.cpp
Normal file
49
ex00/main.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/18 20:08:53 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/06/18 23:58:04 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
Bureaucrat knl("kanel", 10);
|
||||||
|
|
||||||
|
knl.DecrementGrade();
|
||||||
|
std::cout << knl << std::endl;
|
||||||
|
knl.IncrementGrade();
|
||||||
|
std::cout << knl << std::endl;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
knl.IncrementGrade();
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
std::cerr << "error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << knl << std::endl;
|
||||||
|
}
|
||||||
122
ex01/Bureaucrat.cpp
Normal file
122
ex01/Bureaucrat.cpp
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Bureaucrat.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/18 20:11:39 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/06/27 14:10:53 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include "Form.hpp"
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str)
|
||||||
|
{
|
||||||
|
#ifdef VERBOSE
|
||||||
|
if (who.empty())
|
||||||
|
std::cout << "「" << emoji << "」" << what << ": " << str << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str
|
||||||
|
<< std::endl;
|
||||||
|
#else
|
||||||
|
(void)emoji, (void)what, (void)who, (void)str;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(void)
|
||||||
|
: _name("kanel"), _grade(150)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(const Bureaucrat &cpy)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "copy constructor called");
|
||||||
|
if (&cpy != this)
|
||||||
|
{
|
||||||
|
_name = cpy.getName();
|
||||||
|
_grade = cpy.getGrade();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(uint8_t grade)
|
||||||
|
: _name("kanel"), _grade(grade)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(std::string name)
|
||||||
|
: _name(name), _grade(150)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(std::string name, uint8_t grade)
|
||||||
|
: _name(name), _grade(grade)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Bureaucrat::getName(void) const { return _name; }
|
||||||
|
uint8_t Bureaucrat::getGrade(void) const { return _grade; }
|
||||||
|
|
||||||
|
Bureaucrat::~Bureaucrat(void)
|
||||||
|
{
|
||||||
|
_log("➖", "Bureaucrat", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::signForm(Form &f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
f.beSigned(*this);
|
||||||
|
std::cout << _name << " signed " << f.getName() << std::endl;
|
||||||
|
}
|
||||||
|
catch (std::exception &e)
|
||||||
|
{
|
||||||
|
std::cout << _name << " counldn't sign " << f.getName() << " because " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy)
|
||||||
|
{
|
||||||
|
if (&cpy == this)
|
||||||
|
return *this;
|
||||||
|
_grade = cpy._grade;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::IncrementGrade(void)
|
||||||
|
{
|
||||||
|
if (_grade - 1 < MAXGRADE)
|
||||||
|
throw GradeTooHighException();
|
||||||
|
_grade--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::DecrementGrade(void)
|
||||||
|
{
|
||||||
|
if (_grade + 1 > MINGRADE)
|
||||||
|
throw GradeTooLowException();
|
||||||
|
_grade++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, Bureaucrat &val)
|
||||||
|
{
|
||||||
|
os << val.getName() << ", bureaucrat grade " << (int)val.getGrade();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Bureaucrat::GradeTooHighException::what() const throw()
|
||||||
|
{
|
||||||
|
return ("Grade is too high");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Bureaucrat::GradeTooLowException::what() const throw()
|
||||||
|
{
|
||||||
|
return ("Grade is too low");
|
||||||
|
}
|
||||||
63
ex01/Bureaucrat.hpp
Normal file
63
ex01/Bureaucrat.hpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Bureaucrat.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/18 20:11:25 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/06/27 14:05:55 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str);
|
||||||
|
|
||||||
|
class Form;
|
||||||
|
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
|
||||||
|
#define MAXGRADE 1
|
||||||
|
#define MINGRADE 150
|
||||||
|
|
||||||
|
class Bureaucrat {
|
||||||
|
public:
|
||||||
|
Bureaucrat(void);
|
||||||
|
Bureaucrat(const Bureaucrat &cpy);
|
||||||
|
Bureaucrat(uint8_t grade);
|
||||||
|
Bureaucrat(std::string name);
|
||||||
|
Bureaucrat(std::string name, uint8_t grade);
|
||||||
|
~Bureaucrat(void);
|
||||||
|
|
||||||
|
Bureaucrat &operator=(const Bureaucrat& other);
|
||||||
|
|
||||||
|
const std::string &getName(void) const;
|
||||||
|
uint8_t getGrade(void) const;
|
||||||
|
|
||||||
|
void IncrementGrade(void);
|
||||||
|
void DecrementGrade(void);
|
||||||
|
|
||||||
|
class GradeTooHighException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
class GradeTooLowException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
void signForm(Form &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
uint8_t _grade;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &, Bureaucrat &);
|
||||||
78
ex01/Form.cpp
Normal file
78
ex01/Form.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Form.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/27 13:49:35 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/06/27 15:12:49 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Form.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
|
Form::Form(void)
|
||||||
|
: _name("Form"), _signed(false), _minForSign(1), _minForExec(1)
|
||||||
|
{
|
||||||
|
_log("➕", "Form", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Form::Form(std::string name, uint8_t minForSign, uint8_t minForExec)
|
||||||
|
: _name(name), _signed(false), _minForSign(minForSign), _minForExec(minForExec)
|
||||||
|
{
|
||||||
|
_log("➕", "Form", "", "constructor called");
|
||||||
|
_gradeCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
Form::Form(const Form &f)
|
||||||
|
: _name(f.getName()), _signed(f.getSigned()), _minForSign(f.getMinForSign()), _minForExec(f.getMinForExec())
|
||||||
|
{
|
||||||
|
_log("➕", "Form", "", "copy constructor called");
|
||||||
|
_gradeCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
Form::~Form(void) { _log("➖", "Form", "", "destructor called"); }
|
||||||
|
|
||||||
|
Form &Form::operator=(const Form &f) {
|
||||||
|
if (this == &f)
|
||||||
|
return *this;
|
||||||
|
_name = f.getName();
|
||||||
|
_signed = f.getSigned();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Form::GradeTooHighException::what() const throw() {
|
||||||
|
return ("grade is too high");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Form::GradeTooLowException::what() const throw() {
|
||||||
|
return ("grade is too low");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Form::getName(void) const { return _name; }
|
||||||
|
bool Form::getSigned(void) const { return _signed; }
|
||||||
|
uint8_t Form::getMinForSign(void) const { return _minForSign; }
|
||||||
|
uint8_t Form::getMinForExec(void) const { return _minForExec; }
|
||||||
|
|
||||||
|
void Form::beSigned(Bureaucrat b) {
|
||||||
|
if (_minForSign > b.getGrade()) {
|
||||||
|
throw GradeTooLowException();
|
||||||
|
}
|
||||||
|
_signed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Form::_gradeCheck(void) const {
|
||||||
|
if (_minForExec < MAXGRADE || _minForSign < MAXGRADE)
|
||||||
|
throw GradeTooHighException();
|
||||||
|
if (_minForExec > MINGRADE || _minForExec > MINGRADE)
|
||||||
|
throw GradeTooLowException();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, Form &val) {
|
||||||
|
os << "Form: " << val.getName()
|
||||||
|
<< ", minGrade to sign: " << int(val.getMinForSign())
|
||||||
|
<< ", minGrade to execute: " << int(val.getMinForExec());
|
||||||
|
return (os);
|
||||||
|
}
|
||||||
58
ex01/Form.hpp
Normal file
58
ex01/Form.hpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Form.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/27 13:36:33 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/06/27 15:06:04 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str);
|
||||||
|
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
|
class Form {
|
||||||
|
public:
|
||||||
|
Form(void);
|
||||||
|
Form(std::string name, uint8_t minForSign, uint8_t minForExec);
|
||||||
|
Form(const Form &);
|
||||||
|
~Form(void);
|
||||||
|
|
||||||
|
Form &operator=(const Form &);
|
||||||
|
|
||||||
|
class GradeTooHighException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
class GradeTooLowException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string getName(void) const;
|
||||||
|
bool getSigned(void) const;
|
||||||
|
uint8_t getMinForSign(void) const;
|
||||||
|
uint8_t getMinForExec(void) const;
|
||||||
|
|
||||||
|
void beSigned(Bureaucrat);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
bool _signed;
|
||||||
|
const uint8_t _minForSign;
|
||||||
|
const uint8_t _minForExec;
|
||||||
|
|
||||||
|
void _gradeCheck(void) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &, Form &);
|
||||||
|
|
||||||
58
ex01/Makefile
Normal file
58
ex01/Makefile
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2024/01/22 07:21:18 by mmoussou #+# #+# #
|
||||||
|
# Updated: 2025/06/27 14:11:13 by mmoussou ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
SHELL = bash
|
||||||
|
|
||||||
|
RED = \033[0;31m
|
||||||
|
GREEN = \033[0;32m
|
||||||
|
YELLOW = \033[1;33m
|
||||||
|
PURPLE = \e[0;35m
|
||||||
|
NC = \033[0m
|
||||||
|
DELETE = \x1B[2K
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
|
||||||
|
FLAGS = -std=c++98 -Wall -Werror -Wextra
|
||||||
|
|
||||||
|
INCLUDES = ./
|
||||||
|
|
||||||
|
NAME = ex01
|
||||||
|
|
||||||
|
SRCS = main.cpp Bureaucrat.cpp Form.cpp
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@$(CC) $(FLAGS) -I$(INCLUDES) $(OBJS) -o $(NAME)
|
||||||
|
@printf "$(NC)$(YELLOW)「✨」 feat($(NAME)): program compiled\n$(NC)"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.cpp
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) $(FLAGS) -I$(INCLUDES) -c $< -o $@
|
||||||
|
@printf "$(NC)$(GREEN)「🔨」 build($<): object compiled\n$(NC)"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJS)
|
||||||
|
@printf "$(NC)$(RED)「🗑️」 clean($(OBJS)): object deleted\n$(NC)"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@rm -Rf $(OBJSDIR)
|
||||||
|
@printf "$(NC)$(RED)「🗑️」 fclean($(NAME)): program deleted\n$(NC)"
|
||||||
|
|
||||||
|
re: fclean
|
||||||
|
@$(MAKE) -s all
|
||||||
|
|
||||||
|
.PHONY: clean fclean all re
|
||||||
74
ex01/main.cpp
Normal file
74
ex01/main.cpp
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/19 01:13:45 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/06/29 20:48:03 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Form.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Form test("test form", 175, 15);
|
||||||
|
std::cout << test << std::endl;
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Form test("test form", 120, 10);
|
||||||
|
Form test2(test);
|
||||||
|
Bureaucrat tester("john", 1);
|
||||||
|
std::cout << test << std::endl;
|
||||||
|
std::cout << test2 << std::endl;
|
||||||
|
tester.signForm(test2);
|
||||||
|
std::cout << test << std::endl;
|
||||||
|
std::cout << test2 << std::endl << std::endl;
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Form test;
|
||||||
|
Bureaucrat tester;
|
||||||
|
|
||||||
|
std::cout << test << std::endl;
|
||||||
|
tester.signForm(test);
|
||||||
|
std::cout << test << std::endl;
|
||||||
|
tester.signForm(test);
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Form test("some form", 149, 149);
|
||||||
|
Bureaucrat tester;
|
||||||
|
|
||||||
|
std::cout << test << std::endl;
|
||||||
|
tester.signForm(test);
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
94
ex02/AForm.cpp
Normal file
94
ex02/AForm.cpp
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* AForm.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/27 13:49:35 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 13:15:48 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "AForm.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
|
void AForm::execute(const Bureaucrat &b) const {
|
||||||
|
if (_signed == false) {
|
||||||
|
throw NotSigned();
|
||||||
|
}
|
||||||
|
if (b.getGrade() > _minForExec) {
|
||||||
|
throw GradeTooLowException();
|
||||||
|
}
|
||||||
|
std::cout << b.getName() << " executed " << this->getName() << std::endl;
|
||||||
|
_exec(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AForm::AForm(void)
|
||||||
|
: _name("Form"), _signed(false), _minForSign(1), _minForExec(1)
|
||||||
|
{
|
||||||
|
_log("➕", "AForm", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm::AForm(std::string name, uint8_t minForSign, uint8_t minForExec)
|
||||||
|
: _name(name), _signed(false), _minForSign(minForSign), _minForExec(minForExec)
|
||||||
|
{
|
||||||
|
_log("➕", "AForm", "", "constructor called");
|
||||||
|
_gradeCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm::AForm(const AForm &f)
|
||||||
|
: _name(f.getName()), _signed(f.getSigned()), _minForSign(f.getMinForSign()), _minForExec(f.getMinForExec())
|
||||||
|
{
|
||||||
|
_log("➕", "Form", "", "copy constructor called");
|
||||||
|
_gradeCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm::~AForm(void) { _log("➖", "AForm", "", "destructor called"); }
|
||||||
|
|
||||||
|
AForm &AForm::operator=(const AForm &f) {
|
||||||
|
if (this == &f)
|
||||||
|
return *this;
|
||||||
|
_name = f.getName();
|
||||||
|
_signed = f.getSigned();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *AForm::GradeTooHighException::what() const throw() {
|
||||||
|
return ("grade is too high");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *AForm::GradeTooLowException::what() const throw() {
|
||||||
|
return ("grade is too low");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *AForm::NotSigned::what() const throw() {
|
||||||
|
return "Form exception: Form not signed";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AForm::getName(void) const { return _name; }
|
||||||
|
bool AForm::getSigned(void) const { return _signed; }
|
||||||
|
uint8_t AForm::getMinForSign(void) const { return _minForSign; }
|
||||||
|
uint8_t AForm::getMinForExec(void) const { return _minForExec; }
|
||||||
|
|
||||||
|
void AForm::beSigned(Bureaucrat b) {
|
||||||
|
if (_minForSign > b.getGrade()) {
|
||||||
|
throw GradeTooLowException();
|
||||||
|
}
|
||||||
|
_signed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AForm::_gradeCheck(void) const {
|
||||||
|
if (_minForExec < MAXGRADE || _minForSign < MAXGRADE)
|
||||||
|
throw GradeTooHighException();
|
||||||
|
if (_minForExec > MINGRADE || _minForExec > MINGRADE)
|
||||||
|
throw GradeTooLowException();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, AForm &val) {
|
||||||
|
os << "Form: " << val.getName()
|
||||||
|
<< ", minGrade to sign: " << int(val.getMinForSign())
|
||||||
|
<< ", minGrade to execute: " << int(val.getMinForExec());
|
||||||
|
return (os);
|
||||||
|
}
|
||||||
65
ex02/AForm.hpp
Normal file
65
ex02/AForm.hpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* AForm.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/27 13:36:33 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 13:13:41 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str);
|
||||||
|
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
|
class AForm {
|
||||||
|
public:
|
||||||
|
AForm(void);
|
||||||
|
AForm(std::string name, uint8_t minForSign, uint8_t minForExec);
|
||||||
|
AForm(const AForm &);
|
||||||
|
~AForm(void);
|
||||||
|
|
||||||
|
AForm &operator=(const AForm &);
|
||||||
|
|
||||||
|
class GradeTooHighException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
class GradeTooLowException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
class NotSigned : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string getName(void) const;
|
||||||
|
bool getSigned(void) const;
|
||||||
|
uint8_t getMinForSign(void) const;
|
||||||
|
uint8_t getMinForExec(void) const;
|
||||||
|
|
||||||
|
void execute(const Bureaucrat &) const;
|
||||||
|
|
||||||
|
void beSigned(Bureaucrat);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
bool _signed;
|
||||||
|
const uint8_t _minForSign;
|
||||||
|
const uint8_t _minForExec;
|
||||||
|
|
||||||
|
void _gradeCheck(void) const;
|
||||||
|
virtual void _exec(const Bureaucrat &) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &, AForm &);
|
||||||
|
|
||||||
126
ex02/Bureaucrat.cpp
Normal file
126
ex02/Bureaucrat.cpp
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Bureaucrat.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/18 20:11:39 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 13:14:53 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include "AForm.hpp"
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str)
|
||||||
|
{
|
||||||
|
#ifdef VERBOSE
|
||||||
|
if (who.empty())
|
||||||
|
std::cout << "「" << emoji << "」" << what << ": " << str << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str
|
||||||
|
<< std::endl;
|
||||||
|
#else
|
||||||
|
(void)emoji, (void)what, (void)who, (void)str;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::executeForm(const AForm &form) const {
|
||||||
|
form.execute(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(void)
|
||||||
|
: _name("kanel"), _grade(150)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(const Bureaucrat &cpy)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "copy constructor called");
|
||||||
|
if (&cpy != this)
|
||||||
|
{
|
||||||
|
_name = cpy.getName();
|
||||||
|
_grade = cpy.getGrade();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(uint8_t grade)
|
||||||
|
: _name("kanel"), _grade(grade)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(std::string name)
|
||||||
|
: _name(name), _grade(150)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(std::string name, uint8_t grade)
|
||||||
|
: _name(name), _grade(grade)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Bureaucrat::getName(void) const { return _name; }
|
||||||
|
uint8_t Bureaucrat::getGrade(void) const { return _grade; }
|
||||||
|
|
||||||
|
Bureaucrat::~Bureaucrat(void)
|
||||||
|
{
|
||||||
|
_log("➖", "Bureaucrat", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::signForm(AForm &f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
f.beSigned(*this);
|
||||||
|
std::cout << _name << " signed " << f.getName() << std::endl;
|
||||||
|
}
|
||||||
|
catch (std::exception &e)
|
||||||
|
{
|
||||||
|
std::cout << _name << " counldn't sign " << f.getName() << " because " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy)
|
||||||
|
{
|
||||||
|
if (&cpy == this)
|
||||||
|
return *this;
|
||||||
|
_grade = cpy._grade;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::IncrementGrade(void)
|
||||||
|
{
|
||||||
|
if (_grade - 1 < MAXGRADE)
|
||||||
|
throw GradeTooHighException();
|
||||||
|
_grade--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::DecrementGrade(void)
|
||||||
|
{
|
||||||
|
if (_grade + 1 > MINGRADE)
|
||||||
|
throw GradeTooLowException();
|
||||||
|
_grade++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, Bureaucrat &val)
|
||||||
|
{
|
||||||
|
os << val.getName() << ", bureaucrat grade " << (int)val.getGrade();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Bureaucrat::GradeTooHighException::what() const throw()
|
||||||
|
{
|
||||||
|
return ("Grade is too high");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Bureaucrat::GradeTooLowException::what() const throw()
|
||||||
|
{
|
||||||
|
return ("Grade is too low");
|
||||||
|
}
|
||||||
65
ex02/Bureaucrat.hpp
Normal file
65
ex02/Bureaucrat.hpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Bureaucrat.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/18 20:11:25 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 12:55:32 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str);
|
||||||
|
|
||||||
|
class AForm;
|
||||||
|
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
|
||||||
|
#define MAXGRADE 1
|
||||||
|
#define MINGRADE 150
|
||||||
|
|
||||||
|
class Bureaucrat {
|
||||||
|
public:
|
||||||
|
Bureaucrat(void);
|
||||||
|
Bureaucrat(const Bureaucrat &cpy);
|
||||||
|
Bureaucrat(uint8_t grade);
|
||||||
|
Bureaucrat(std::string name);
|
||||||
|
Bureaucrat(std::string name, uint8_t grade);
|
||||||
|
~Bureaucrat(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void executeForm(const AForm &) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Bureaucrat &operator=(const Bureaucrat& other);
|
||||||
|
const std::string &getName(void) const;
|
||||||
|
uint8_t getGrade(void) const;
|
||||||
|
void IncrementGrade(void);
|
||||||
|
void DecrementGrade(void);
|
||||||
|
class GradeTooHighException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
class GradeTooLowException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
void signForm(AForm &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
uint8_t _grade;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &, Bureaucrat &);
|
||||||
58
ex02/Makefile
Normal file
58
ex02/Makefile
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2024/01/22 07:21:18 by mmoussou #+# #+# #
|
||||||
|
# Updated: 2025/08/02 13:34:02 by mmoussou ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
SHELL = bash
|
||||||
|
|
||||||
|
RED = \033[0;31m
|
||||||
|
GREEN = \033[0;32m
|
||||||
|
YELLOW = \033[1;33m
|
||||||
|
PURPLE = \e[0;35m
|
||||||
|
NC = \033[0m
|
||||||
|
DELETE = \x1B[2K
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
|
||||||
|
FLAGS = -std=c++98 -Wall -Werror -Wextra
|
||||||
|
|
||||||
|
INCLUDES = ./
|
||||||
|
|
||||||
|
NAME = $(shell basename $(PWD))
|
||||||
|
|
||||||
|
SRCS = main.cpp Bureaucrat.cpp AForm.cpp ShrubberyCreationForm.cpp RobotomyRequestForm.cpp PresidentialPardonForm.cpp
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@$(CC) $(FLAGS) -I$(INCLUDES) $(OBJS) -o $(NAME)
|
||||||
|
@printf "$(NC)$(YELLOW)「✨」 feat($(NAME)): program compiled\n$(NC)"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.cpp
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) $(FLAGS) -I$(INCLUDES) -c $< -o $@
|
||||||
|
@printf "$(NC)$(GREEN)「🔨」 build($<): object compiled\n$(NC)"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJS)
|
||||||
|
@printf "$(NC)$(RED)「🗑️」 clean($(OBJS)): object deleted\n$(NC)"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@rm -Rf $(OBJSDIR)
|
||||||
|
@printf "$(NC)$(RED)「🗑️」 fclean($(NAME)): program deleted\n$(NC)"
|
||||||
|
|
||||||
|
re: fclean
|
||||||
|
@$(MAKE) -s all
|
||||||
|
|
||||||
|
.PHONY: clean fclean all re
|
||||||
34
ex02/PresidentialPardonForm.cpp
Normal file
34
ex02/PresidentialPardonForm.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "PresidentialPardonForm.hpp"
|
||||||
|
#include "AForm.hpp"
|
||||||
|
|
||||||
|
PresidentialPardonForm::PresidentialPardonForm(void): AForm("PresidentialPardonForm", 25, 5) {
|
||||||
|
_log("➕", "PresidentialPardonForm", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm &cpy): AForm(cpy) {
|
||||||
|
_log("➕", "PresidentialPardonForm", "", "copy constructor called");
|
||||||
|
if (this != &cpy)
|
||||||
|
*this = cpy;
|
||||||
|
}
|
||||||
|
|
||||||
|
PresidentialPardonForm::PresidentialPardonForm(std::string target): AForm(target, 25, 5) {
|
||||||
|
_log("➕", "PresidentialPardonForm", "", "target constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
PresidentialPardonForm::~PresidentialPardonForm(void) {
|
||||||
|
_log("➖", "PresidentialPardonForm", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
PresidentialPardonForm &
|
||||||
|
PresidentialPardonForm::operator=(const PresidentialPardonForm &cpy) {
|
||||||
|
_log("➕", "PresidentialPardonForm", "",
|
||||||
|
"copy assignement constructor called");
|
||||||
|
(void)cpy;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PresidentialPardonForm::_exec(const Bureaucrat &b) const {
|
||||||
|
(void) b;
|
||||||
|
std::cout << this->getName() << " has been pardoned by Zaphod Beeblebroxm ggs..." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
17
ex02/PresidentialPardonForm.hpp
Normal file
17
ex02/PresidentialPardonForm.hpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include "AForm.hpp"
|
||||||
|
|
||||||
|
class PresidentialPardonForm : public AForm {
|
||||||
|
public:
|
||||||
|
PresidentialPardonForm(void);
|
||||||
|
PresidentialPardonForm(const PresidentialPardonForm &);
|
||||||
|
PresidentialPardonForm(std::string);
|
||||||
|
~PresidentialPardonForm(void);
|
||||||
|
|
||||||
|
PresidentialPardonForm &operator=(const PresidentialPardonForm &);
|
||||||
|
private:
|
||||||
|
void _exec(const Bureaucrat &) const;
|
||||||
|
};
|
||||||
|
|
||||||
42
ex02/RobotomyRequestForm.cpp
Normal file
42
ex02/RobotomyRequestForm.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "RobotomyRequestForm.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
RobotomyRequestForm::RobotomyRequestForm(void): AForm("RobotomyRequestForm", 72, 45) {
|
||||||
|
_log("➕", "RobotomyRequestForm", "", "default constructor called");
|
||||||
|
std::srand(time(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm &cpy) : AForm(cpy) {
|
||||||
|
_log("➕", "RobotomyRequestForm", "", "copy constructor called");
|
||||||
|
std::srand(time(0));
|
||||||
|
if (this != &cpy)
|
||||||
|
*this = cpy;
|
||||||
|
}
|
||||||
|
|
||||||
|
RobotomyRequestForm::RobotomyRequestForm(std::string target): AForm(target, 72, 45) {
|
||||||
|
_log("➕", "RobotomyRequestForm", "", "target constructor called");
|
||||||
|
std::srand(time(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
RobotomyRequestForm::~RobotomyRequestForm(void) {
|
||||||
|
_log("➖", "RobotomyRequestForm", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
RobotomyRequestForm &RobotomyRequestForm::operator=(const RobotomyRequestForm &cpy) {
|
||||||
|
_log("➕", "RobotomyRequestForm", "", "copy assignement constructor called");
|
||||||
|
(void) cpy;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RobotomyRequestForm::_exec(const Bureaucrat &b) const {
|
||||||
|
(void) b;
|
||||||
|
std::cout << "Driling noise or smth idk" << std::endl;
|
||||||
|
|
||||||
|
if (std::rand() % 2) {
|
||||||
|
std::cout << this->getName() << " has been robotomised successfully ! :D" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << this->getName() << " robotomisation failed D:" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
15
ex02/RobotomyRequestForm.hpp
Normal file
15
ex02/RobotomyRequestForm.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AForm.hpp"
|
||||||
|
|
||||||
|
class RobotomyRequestForm : public AForm {
|
||||||
|
public:
|
||||||
|
RobotomyRequestForm(void);
|
||||||
|
RobotomyRequestForm(const RobotomyRequestForm &);
|
||||||
|
RobotomyRequestForm(std::string);
|
||||||
|
~RobotomyRequestForm(void);
|
||||||
|
|
||||||
|
RobotomyRequestForm &operator=(const RobotomyRequestForm &);
|
||||||
|
private:
|
||||||
|
void _exec(const Bureaucrat &) const;
|
||||||
|
};
|
||||||
54
ex02/ShrubberyCreationForm.cpp
Normal file
54
ex02/ShrubberyCreationForm.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "ShrubberyCreationForm.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
ShrubberyCreationForm::ShrubberyCreationForm(void) : AForm("ShrubberyCreationForm", 145, 137) {
|
||||||
|
_log("➕", "ShrubberyCreationForm", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm &cpy) : AForm(cpy) {
|
||||||
|
_log("➕", "ShrubberyCreationForm", "", "copy constructor called");
|
||||||
|
if (this != &cpy)
|
||||||
|
*this = cpy;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShrubberyCreationForm::ShrubberyCreationForm(std::string target) : AForm(target, 145, 137) {
|
||||||
|
_log("➕", "ShrubberyCreationForm", "", "target constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShrubberyCreationForm::~ShrubberyCreationForm(void) {
|
||||||
|
_log("➖", "ShrubberyCreationForm", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShrubberyCreationForm &ShrubberyCreationForm::operator=(const ShrubberyCreationForm &cpy) {
|
||||||
|
_log("➕", "ShrubberyCreationForm", "", "copy assignement constructor called");
|
||||||
|
(void) cpy;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShrubberyCreationForm::_exec(const Bureaucrat &b) const {
|
||||||
|
(void) b;
|
||||||
|
std::ofstream file;
|
||||||
|
|
||||||
|
file.open(std::string(this->getName() + "_shruberry").c_str());
|
||||||
|
if (!file.is_open())
|
||||||
|
throw std::runtime_error("Could not write to " + this->getName() +
|
||||||
|
"_shruberry");
|
||||||
|
|
||||||
|
file << " _-_\n"
|
||||||
|
" /~~ ~~\\\n"
|
||||||
|
" /~~ ~~\\\n"
|
||||||
|
"{ }\n"
|
||||||
|
" \\ _- -_ /\n"
|
||||||
|
" ~ \\ // ~\n"
|
||||||
|
"_- - | | _- _\n"
|
||||||
|
" _ - | | -_\n"
|
||||||
|
" // \\\n";
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
std::cout << "ASCII tree created in : " + this->getName() + "_shruberry"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
18
ex02/ShrubberyCreationForm.hpp
Normal file
18
ex02/ShrubberyCreationForm.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AForm.hpp"
|
||||||
|
#include <cerrno>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class ShrubberyCreationForm : public AForm {
|
||||||
|
public:
|
||||||
|
ShrubberyCreationForm(void);
|
||||||
|
ShrubberyCreationForm(const ShrubberyCreationForm &);
|
||||||
|
ShrubberyCreationForm(std::string);
|
||||||
|
~ShrubberyCreationForm(void);
|
||||||
|
|
||||||
|
ShrubberyCreationForm &operator=(const ShrubberyCreationForm &);
|
||||||
|
private:
|
||||||
|
void _exec(const Bureaucrat &) const;
|
||||||
|
};
|
||||||
|
|
||||||
81
ex02/main.cpp
Normal file
81
ex02/main.cpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/19 01:13:45 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 13:46:10 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ShrubberyCreationForm.hpp"
|
||||||
|
#include "RobotomyRequestForm.hpp"
|
||||||
|
#include "PresidentialPardonForm.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
/*try
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;*/
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Bureaucrat knl("Kanel", 145);
|
||||||
|
Bureaucrat brc("john", 130);
|
||||||
|
|
||||||
|
ShrubberyCreationForm s("home");
|
||||||
|
|
||||||
|
knl.signForm(s);
|
||||||
|
brc.executeForm(s);
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Bureaucrat knl("Kanel", 72);
|
||||||
|
Bureaucrat brc("john", 1);
|
||||||
|
|
||||||
|
RobotomyRequestForm s("adjoly");
|
||||||
|
|
||||||
|
knl.signForm(s);
|
||||||
|
std::cout << "50% chances of working, let's test that." << std::endl;
|
||||||
|
brc.executeForm(s);
|
||||||
|
brc.executeForm(s);
|
||||||
|
brc.executeForm(s);
|
||||||
|
brc.executeForm(s);
|
||||||
|
brc.executeForm(s);
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Bureaucrat knl("Kanel", 25);
|
||||||
|
Bureaucrat brc("john", 1);
|
||||||
|
|
||||||
|
PresidentialPardonForm s("this one specific person");
|
||||||
|
|
||||||
|
knl.signForm(s);
|
||||||
|
brc.executeForm(s);
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
94
ex03/AForm.cpp
Normal file
94
ex03/AForm.cpp
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* AForm.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/27 13:49:35 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 13:15:48 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "AForm.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
|
void AForm::execute(const Bureaucrat &b) const {
|
||||||
|
if (_signed == false) {
|
||||||
|
throw NotSigned();
|
||||||
|
}
|
||||||
|
if (b.getGrade() > _minForExec) {
|
||||||
|
throw GradeTooLowException();
|
||||||
|
}
|
||||||
|
std::cout << b.getName() << " executed " << this->getName() << std::endl;
|
||||||
|
_exec(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AForm::AForm(void)
|
||||||
|
: _name("Form"), _signed(false), _minForSign(1), _minForExec(1)
|
||||||
|
{
|
||||||
|
_log("➕", "AForm", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm::AForm(std::string name, uint8_t minForSign, uint8_t minForExec)
|
||||||
|
: _name(name), _signed(false), _minForSign(minForSign), _minForExec(minForExec)
|
||||||
|
{
|
||||||
|
_log("➕", "AForm", "", "constructor called");
|
||||||
|
_gradeCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm::AForm(const AForm &f)
|
||||||
|
: _name(f.getName()), _signed(f.getSigned()), _minForSign(f.getMinForSign()), _minForExec(f.getMinForExec())
|
||||||
|
{
|
||||||
|
_log("➕", "Form", "", "copy constructor called");
|
||||||
|
_gradeCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm::~AForm(void) { _log("➖", "AForm", "", "destructor called"); }
|
||||||
|
|
||||||
|
AForm &AForm::operator=(const AForm &f) {
|
||||||
|
if (this == &f)
|
||||||
|
return *this;
|
||||||
|
_name = f.getName();
|
||||||
|
_signed = f.getSigned();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *AForm::GradeTooHighException::what() const throw() {
|
||||||
|
return ("grade is too high");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *AForm::GradeTooLowException::what() const throw() {
|
||||||
|
return ("grade is too low");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *AForm::NotSigned::what() const throw() {
|
||||||
|
return "Form exception: Form not signed";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AForm::getName(void) const { return _name; }
|
||||||
|
bool AForm::getSigned(void) const { return _signed; }
|
||||||
|
uint8_t AForm::getMinForSign(void) const { return _minForSign; }
|
||||||
|
uint8_t AForm::getMinForExec(void) const { return _minForExec; }
|
||||||
|
|
||||||
|
void AForm::beSigned(Bureaucrat b) {
|
||||||
|
if (_minForSign > b.getGrade()) {
|
||||||
|
throw GradeTooLowException();
|
||||||
|
}
|
||||||
|
_signed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AForm::_gradeCheck(void) const {
|
||||||
|
if (_minForExec < MAXGRADE || _minForSign < MAXGRADE)
|
||||||
|
throw GradeTooHighException();
|
||||||
|
if (_minForExec > MINGRADE || _minForExec > MINGRADE)
|
||||||
|
throw GradeTooLowException();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, AForm &val) {
|
||||||
|
os << "Form: " << val.getName()
|
||||||
|
<< ", minGrade to sign: " << int(val.getMinForSign())
|
||||||
|
<< ", minGrade to execute: " << int(val.getMinForExec());
|
||||||
|
return (os);
|
||||||
|
}
|
||||||
65
ex03/AForm.hpp
Normal file
65
ex03/AForm.hpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* AForm.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/27 13:36:33 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 13:43:15 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str);
|
||||||
|
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
|
class AForm {
|
||||||
|
public:
|
||||||
|
AForm(void);
|
||||||
|
AForm(std::string name, uint8_t minForSign, uint8_t minForExec);
|
||||||
|
AForm(const AForm &);
|
||||||
|
virtual ~AForm(void);
|
||||||
|
|
||||||
|
AForm &operator=(const AForm &);
|
||||||
|
|
||||||
|
class GradeTooHighException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
class GradeTooLowException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
class NotSigned : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string getName(void) const;
|
||||||
|
bool getSigned(void) const;
|
||||||
|
uint8_t getMinForSign(void) const;
|
||||||
|
uint8_t getMinForExec(void) const;
|
||||||
|
|
||||||
|
void execute(const Bureaucrat &) const;
|
||||||
|
|
||||||
|
void beSigned(Bureaucrat);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
bool _signed;
|
||||||
|
const uint8_t _minForSign;
|
||||||
|
const uint8_t _minForExec;
|
||||||
|
|
||||||
|
void _gradeCheck(void) const;
|
||||||
|
virtual void _exec(const Bureaucrat &) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &, AForm &);
|
||||||
|
|
||||||
126
ex03/Bureaucrat.cpp
Normal file
126
ex03/Bureaucrat.cpp
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Bureaucrat.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/18 20:11:39 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 13:14:53 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include "AForm.hpp"
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str)
|
||||||
|
{
|
||||||
|
#ifdef VERBOSE
|
||||||
|
if (who.empty())
|
||||||
|
std::cout << "「" << emoji << "」" << what << ": " << str << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str
|
||||||
|
<< std::endl;
|
||||||
|
#else
|
||||||
|
(void)emoji, (void)what, (void)who, (void)str;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::executeForm(const AForm &form) const {
|
||||||
|
form.execute(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(void)
|
||||||
|
: _name("kanel"), _grade(150)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(const Bureaucrat &cpy)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "copy constructor called");
|
||||||
|
if (&cpy != this)
|
||||||
|
{
|
||||||
|
_name = cpy.getName();
|
||||||
|
_grade = cpy.getGrade();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(uint8_t grade)
|
||||||
|
: _name("kanel"), _grade(grade)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(std::string name)
|
||||||
|
: _name(name), _grade(150)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bureaucrat::Bureaucrat(std::string name, uint8_t grade)
|
||||||
|
: _name(name), _grade(grade)
|
||||||
|
{
|
||||||
|
_log("➕", "Bureaucrat", "", "constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Bureaucrat::getName(void) const { return _name; }
|
||||||
|
uint8_t Bureaucrat::getGrade(void) const { return _grade; }
|
||||||
|
|
||||||
|
Bureaucrat::~Bureaucrat(void)
|
||||||
|
{
|
||||||
|
_log("➖", "Bureaucrat", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::signForm(AForm &f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
f.beSigned(*this);
|
||||||
|
std::cout << _name << " signed " << f.getName() << std::endl;
|
||||||
|
}
|
||||||
|
catch (std::exception &e)
|
||||||
|
{
|
||||||
|
std::cout << _name << " counldn't sign " << f.getName() << " because " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy)
|
||||||
|
{
|
||||||
|
if (&cpy == this)
|
||||||
|
return *this;
|
||||||
|
_grade = cpy._grade;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::IncrementGrade(void)
|
||||||
|
{
|
||||||
|
if (_grade - 1 < MAXGRADE)
|
||||||
|
throw GradeTooHighException();
|
||||||
|
_grade--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bureaucrat::DecrementGrade(void)
|
||||||
|
{
|
||||||
|
if (_grade + 1 > MINGRADE)
|
||||||
|
throw GradeTooLowException();
|
||||||
|
_grade++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, Bureaucrat &val)
|
||||||
|
{
|
||||||
|
os << val.getName() << ", bureaucrat grade " << (int)val.getGrade();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Bureaucrat::GradeTooHighException::what() const throw()
|
||||||
|
{
|
||||||
|
return ("Grade is too high");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Bureaucrat::GradeTooLowException::what() const throw()
|
||||||
|
{
|
||||||
|
return ("Grade is too low");
|
||||||
|
}
|
||||||
65
ex03/Bureaucrat.hpp
Normal file
65
ex03/Bureaucrat.hpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Bureaucrat.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/18 20:11:25 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 12:55:32 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
void _log(std::string emoji, std::string what, std::string who, std::string str);
|
||||||
|
|
||||||
|
class AForm;
|
||||||
|
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
|
||||||
|
#define MAXGRADE 1
|
||||||
|
#define MINGRADE 150
|
||||||
|
|
||||||
|
class Bureaucrat {
|
||||||
|
public:
|
||||||
|
Bureaucrat(void);
|
||||||
|
Bureaucrat(const Bureaucrat &cpy);
|
||||||
|
Bureaucrat(uint8_t grade);
|
||||||
|
Bureaucrat(std::string name);
|
||||||
|
Bureaucrat(std::string name, uint8_t grade);
|
||||||
|
~Bureaucrat(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void executeForm(const AForm &) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Bureaucrat &operator=(const Bureaucrat& other);
|
||||||
|
const std::string &getName(void) const;
|
||||||
|
uint8_t getGrade(void) const;
|
||||||
|
void IncrementGrade(void);
|
||||||
|
void DecrementGrade(void);
|
||||||
|
class GradeTooHighException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
class GradeTooLowException : public std::exception {
|
||||||
|
public:
|
||||||
|
virtual const char *what() const throw();
|
||||||
|
};
|
||||||
|
void signForm(AForm &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
uint8_t _grade;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &, Bureaucrat &);
|
||||||
52
ex03/Intern.cpp
Normal file
52
ex03/Intern.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#include "Intern.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include "PresidentialPardonForm.hpp"
|
||||||
|
#include "RobotomyRequestForm.hpp"
|
||||||
|
#include "ShrubberyCreationForm.hpp"
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
Intern::Intern(void) {
|
||||||
|
_log("➕", "Intern", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Intern::Intern(const Intern &cpy) {
|
||||||
|
_log("➕", "Intern", "", "copy constructor called");
|
||||||
|
*this = cpy;
|
||||||
|
}
|
||||||
|
|
||||||
|
Intern::~Intern(void) {
|
||||||
|
_log("➖", "Intern", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
Intern &Intern::operator=(const Intern &) {
|
||||||
|
_log("➕", "Intern", "", "copy assignement constructor called");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm *newShrubbery(std::string &target) {
|
||||||
|
return new ShrubberyCreationForm(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm *newPresidential(std::string &target) {
|
||||||
|
return new PresidentialPardonForm(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm *newRobotomy(std::string &target) {
|
||||||
|
return new RobotomyRequestForm(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm *Intern::makeForm(std::string name, std::string target) const {
|
||||||
|
std::string formName[] = {"robotomy request", "shrubbery request", "presidential pardon request"};
|
||||||
|
AForm *(*newForm[])(std::string &) = {&newRobotomy, &newShrubbery, &newPresidential};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 3; i++) {
|
||||||
|
if (formName[i] == name) {
|
||||||
|
AForm *n = newForm[i](target);
|
||||||
|
std::cout << "Intern creates " << name << std::endl;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cerr << "Intern doesn't know " << name << std::endl;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
18
ex03/Intern.hpp
Normal file
18
ex03/Intern.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class AForm;
|
||||||
|
|
||||||
|
class Intern {
|
||||||
|
public:
|
||||||
|
Intern(void);
|
||||||
|
Intern(const Intern &);
|
||||||
|
~Intern(void);
|
||||||
|
Intern &operator=(const Intern &);
|
||||||
|
|
||||||
|
AForm *makeForm(std::string, std::string) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
58
ex03/Makefile
Normal file
58
ex03/Makefile
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2024/01/22 07:21:18 by mmoussou #+# #+# #
|
||||||
|
# Updated: 2025/08/02 13:42:27 by mmoussou ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
SHELL = bash
|
||||||
|
|
||||||
|
RED = \033[0;31m
|
||||||
|
GREEN = \033[0;32m
|
||||||
|
YELLOW = \033[1;33m
|
||||||
|
PURPLE = \e[0;35m
|
||||||
|
NC = \033[0m
|
||||||
|
DELETE = \x1B[2K
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
|
||||||
|
FLAGS = -std=c++98 -Wall -Werror -Wextra
|
||||||
|
|
||||||
|
INCLUDES = ./
|
||||||
|
|
||||||
|
NAME = $(shell basename $(PWD))
|
||||||
|
|
||||||
|
SRCS = main.cpp Bureaucrat.cpp AForm.cpp ShrubberyCreationForm.cpp RobotomyRequestForm.cpp PresidentialPardonForm.cpp Intern.cpp
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@$(CC) $(FLAGS) -I$(INCLUDES) $(OBJS) -o $(NAME)
|
||||||
|
@printf "$(NC)$(YELLOW)「✨」 feat($(NAME)): program compiled\n$(NC)"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.cpp
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) $(FLAGS) -I$(INCLUDES) -c $< -o $@
|
||||||
|
@printf "$(NC)$(GREEN)「🔨」 build($<): object compiled\n$(NC)"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJS)
|
||||||
|
@printf "$(NC)$(RED)「🗑️」 clean($(OBJS)): object deleted\n$(NC)"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@rm -Rf $(OBJSDIR)
|
||||||
|
@printf "$(NC)$(RED)「🗑️」 fclean($(NAME)): program deleted\n$(NC)"
|
||||||
|
|
||||||
|
re: fclean
|
||||||
|
@$(MAKE) -s all
|
||||||
|
|
||||||
|
.PHONY: clean fclean all re
|
||||||
34
ex03/PresidentialPardonForm.cpp
Normal file
34
ex03/PresidentialPardonForm.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "PresidentialPardonForm.hpp"
|
||||||
|
#include "AForm.hpp"
|
||||||
|
|
||||||
|
PresidentialPardonForm::PresidentialPardonForm(void): AForm("PresidentialPardonForm", 25, 5) {
|
||||||
|
_log("➕", "PresidentialPardonForm", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm &cpy): AForm(cpy) {
|
||||||
|
_log("➕", "PresidentialPardonForm", "", "copy constructor called");
|
||||||
|
if (this != &cpy)
|
||||||
|
*this = cpy;
|
||||||
|
}
|
||||||
|
|
||||||
|
PresidentialPardonForm::PresidentialPardonForm(std::string target): AForm(target, 25, 5) {
|
||||||
|
_log("➕", "PresidentialPardonForm", "", "target constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
PresidentialPardonForm::~PresidentialPardonForm(void) {
|
||||||
|
_log("➖", "PresidentialPardonForm", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
PresidentialPardonForm &
|
||||||
|
PresidentialPardonForm::operator=(const PresidentialPardonForm &cpy) {
|
||||||
|
_log("➕", "PresidentialPardonForm", "",
|
||||||
|
"copy assignement constructor called");
|
||||||
|
(void)cpy;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PresidentialPardonForm::_exec(const Bureaucrat &b) const {
|
||||||
|
(void) b;
|
||||||
|
std::cout << this->getName() << " has been pardoned by Zaphod Beeblebroxm ggs..." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
17
ex03/PresidentialPardonForm.hpp
Normal file
17
ex03/PresidentialPardonForm.hpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include "AForm.hpp"
|
||||||
|
|
||||||
|
class PresidentialPardonForm : public AForm {
|
||||||
|
public:
|
||||||
|
PresidentialPardonForm(void);
|
||||||
|
PresidentialPardonForm(const PresidentialPardonForm &);
|
||||||
|
PresidentialPardonForm(std::string);
|
||||||
|
~PresidentialPardonForm(void);
|
||||||
|
|
||||||
|
PresidentialPardonForm &operator=(const PresidentialPardonForm &);
|
||||||
|
private:
|
||||||
|
void _exec(const Bureaucrat &) const;
|
||||||
|
};
|
||||||
|
|
||||||
42
ex03/RobotomyRequestForm.cpp
Normal file
42
ex03/RobotomyRequestForm.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "RobotomyRequestForm.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
RobotomyRequestForm::RobotomyRequestForm(void): AForm("RobotomyRequestForm", 72, 45) {
|
||||||
|
_log("➕", "RobotomyRequestForm", "", "default constructor called");
|
||||||
|
std::srand(time(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm &cpy) : AForm(cpy) {
|
||||||
|
_log("➕", "RobotomyRequestForm", "", "copy constructor called");
|
||||||
|
std::srand(time(0));
|
||||||
|
if (this != &cpy)
|
||||||
|
*this = cpy;
|
||||||
|
}
|
||||||
|
|
||||||
|
RobotomyRequestForm::RobotomyRequestForm(std::string target): AForm(target, 72, 45) {
|
||||||
|
_log("➕", "RobotomyRequestForm", "", "target constructor called");
|
||||||
|
std::srand(time(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
RobotomyRequestForm::~RobotomyRequestForm(void) {
|
||||||
|
_log("➖", "RobotomyRequestForm", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
RobotomyRequestForm &RobotomyRequestForm::operator=(const RobotomyRequestForm &cpy) {
|
||||||
|
_log("➕", "RobotomyRequestForm", "", "copy assignement constructor called");
|
||||||
|
(void) cpy;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RobotomyRequestForm::_exec(const Bureaucrat &b) const {
|
||||||
|
(void) b;
|
||||||
|
std::cout << "Driling noise or smth idk" << std::endl;
|
||||||
|
|
||||||
|
if (std::rand() % 2) {
|
||||||
|
std::cout << this->getName() << " has been robotomised successfully ! :D" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << this->getName() << " robotomisation failed D:" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
15
ex03/RobotomyRequestForm.hpp
Normal file
15
ex03/RobotomyRequestForm.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AForm.hpp"
|
||||||
|
|
||||||
|
class RobotomyRequestForm : public AForm {
|
||||||
|
public:
|
||||||
|
RobotomyRequestForm(void);
|
||||||
|
RobotomyRequestForm(const RobotomyRequestForm &);
|
||||||
|
RobotomyRequestForm(std::string);
|
||||||
|
~RobotomyRequestForm(void);
|
||||||
|
|
||||||
|
RobotomyRequestForm &operator=(const RobotomyRequestForm &);
|
||||||
|
private:
|
||||||
|
void _exec(const Bureaucrat &) const;
|
||||||
|
};
|
||||||
54
ex03/ShrubberyCreationForm.cpp
Normal file
54
ex03/ShrubberyCreationForm.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "ShrubberyCreationForm.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
ShrubberyCreationForm::ShrubberyCreationForm(void) : AForm("ShrubberyCreationForm", 145, 137) {
|
||||||
|
_log("➕", "ShrubberyCreationForm", "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm &cpy) : AForm(cpy) {
|
||||||
|
_log("➕", "ShrubberyCreationForm", "", "copy constructor called");
|
||||||
|
if (this != &cpy)
|
||||||
|
*this = cpy;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShrubberyCreationForm::ShrubberyCreationForm(std::string target) : AForm(target, 145, 137) {
|
||||||
|
_log("➕", "ShrubberyCreationForm", "", "target constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShrubberyCreationForm::~ShrubberyCreationForm(void) {
|
||||||
|
_log("➖", "ShrubberyCreationForm", "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShrubberyCreationForm &ShrubberyCreationForm::operator=(const ShrubberyCreationForm &cpy) {
|
||||||
|
_log("➕", "ShrubberyCreationForm", "", "copy assignement constructor called");
|
||||||
|
(void) cpy;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShrubberyCreationForm::_exec(const Bureaucrat &b) const {
|
||||||
|
(void) b;
|
||||||
|
std::ofstream file;
|
||||||
|
|
||||||
|
file.open(std::string(this->getName() + "_shruberry").c_str());
|
||||||
|
if (!file.is_open())
|
||||||
|
throw std::runtime_error("Could not write to " + this->getName() +
|
||||||
|
"_shruberry");
|
||||||
|
|
||||||
|
file << " _-_\n"
|
||||||
|
" /~~ ~~\\\n"
|
||||||
|
" /~~ ~~\\\n"
|
||||||
|
"{ }\n"
|
||||||
|
" \\ _- -_ /\n"
|
||||||
|
" ~ \\ // ~\n"
|
||||||
|
"_- - | | _- _\n"
|
||||||
|
" _ - | | -_\n"
|
||||||
|
" // \\\n";
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
std::cout << "ASCII tree created in : " + this->getName() + "_shruberry"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
18
ex03/ShrubberyCreationForm.hpp
Normal file
18
ex03/ShrubberyCreationForm.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AForm.hpp"
|
||||||
|
#include <cerrno>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class ShrubberyCreationForm : public AForm {
|
||||||
|
public:
|
||||||
|
ShrubberyCreationForm(void);
|
||||||
|
ShrubberyCreationForm(const ShrubberyCreationForm &);
|
||||||
|
ShrubberyCreationForm(std::string);
|
||||||
|
~ShrubberyCreationForm(void);
|
||||||
|
|
||||||
|
ShrubberyCreationForm &operator=(const ShrubberyCreationForm &);
|
||||||
|
private:
|
||||||
|
void _exec(const Bureaucrat &) const;
|
||||||
|
};
|
||||||
|
|
||||||
67
ex03/main.cpp
Normal file
67
ex03/main.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/19 01:13:45 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2025/08/02 13:49:12 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ShrubberyCreationForm.hpp"
|
||||||
|
#include "RobotomyRequestForm.hpp"
|
||||||
|
#include "PresidentialPardonForm.hpp"
|
||||||
|
#include "Intern.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
/*try
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;*/
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Intern john;
|
||||||
|
|
||||||
|
john.makeForm("the ultimate form", "the ARK");
|
||||||
|
delete john.makeForm("shrubbery request", "home");
|
||||||
|
delete john.makeForm("robotomy request", "test subject 727");
|
||||||
|
delete john.makeForm("presidential pardon request", "you");
|
||||||
|
john.makeForm("", "");
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Intern john;
|
||||||
|
Bureaucrat knl("Kanel", 72);
|
||||||
|
Bureaucrat brc("john", 1);
|
||||||
|
|
||||||
|
AForm *form = john.makeForm("robotomy request", "Bender");
|
||||||
|
|
||||||
|
knl.signForm(*form);
|
||||||
|
std::cout << "still 50% chances of working" << std::endl;
|
||||||
|
brc.executeForm(*form);
|
||||||
|
brc.executeForm(*form);
|
||||||
|
brc.executeForm(*form);
|
||||||
|
brc.executeForm(*form);
|
||||||
|
brc.executeForm(*form);
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception : " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
BIN
ex03/obj/AForm.o
Normal file
BIN
ex03/obj/AForm.o
Normal file
Binary file not shown.
BIN
ex03/obj/Bureaucrat.o
Normal file
BIN
ex03/obj/Bureaucrat.o
Normal file
Binary file not shown.
BIN
ex03/obj/Intern.o
Normal file
BIN
ex03/obj/Intern.o
Normal file
Binary file not shown.
BIN
ex03/obj/PresidentialPardonForm.o
Normal file
BIN
ex03/obj/PresidentialPardonForm.o
Normal file
Binary file not shown.
BIN
ex03/obj/RobotomyRequestForm.o
Normal file
BIN
ex03/obj/RobotomyRequestForm.o
Normal file
Binary file not shown.
BIN
ex03/obj/ShrubberyCreationForm.o
Normal file
BIN
ex03/obj/ShrubberyCreationForm.o
Normal file
Binary file not shown.
BIN
ex03/obj/main.o
Normal file
BIN
ex03/obj/main.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user