From 618ebf877715aaadbf495f2d600e151d21784587 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 6 Nov 2024 18:16:09 +0100 Subject: [PATCH] update: finishing for good the ex05 of the module 01 --- cpp01/ex05/Harl.cpp | 47 +++++++++++++++++++ cpp01/ex05/Harl.hpp | 37 +++++++++++++++ cpp01/ex05/Makefile | 109 ++++++++++++++++++++++++++++++++++++++++++++ cpp01/ex05/main.cpp | 27 +++++++++++ 4 files changed, 220 insertions(+) create mode 100644 cpp01/ex05/Harl.cpp create mode 100644 cpp01/ex05/Harl.hpp create mode 100644 cpp01/ex05/Makefile create mode 100644 cpp01/ex05/main.cpp diff --git a/cpp01/ex05/Harl.cpp b/cpp01/ex05/Harl.cpp new file mode 100644 index 0000000..0423bba --- /dev/null +++ b/cpp01/ex05/Harl.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/06 17:41:03 by rparodi #+# #+# */ +/* Updated: 2024/11/06 18:11:34 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +Harl::Harl(){} + +Harl::~Harl(){} + +void Harl::debug() +{ + std::cout << DEBUG_MSG << std::endl; +} + +void Harl::error() +{ + std::cout << ERROR_MSG << std::endl; +} + +void Harl::info() +{ + std::cout << INFO_MSG << std::endl; +} + +void Harl::warning() +{ + std::cout << WARN_MSG << std::endl; +} + +void Harl::complain(std::string level) +{ + std::string categorie[] = {"debug", "error", "info", "warning"}; + void (Harl::*choice[4])(void) = { &Harl::debug, &Harl::error, &Harl::info, &Harl::warning }; + + for (size_t i = 0; i < 4; i++) + if (level == categorie[i]) + (this->*choice[i])(); +} diff --git a/cpp01/ex05/Harl.hpp b/cpp01/ex05/Harl.hpp new file mode 100644 index 0000000..4c63c93 --- /dev/null +++ b/cpp01/ex05/Harl.hpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/06 17:37:15 by rparodi #+# #+# */ +/* Updated: 2024/11/06 17:55:57 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HARL_HPP +#define HARL_HPP + +#include +#include + +#define DEBUG_MSG "I love having extra bacon for my 7XL-double-cheese-triple-pickle-special- ketchup burger. I really do!" +#define ERROR_MSG "This is unacceptable! I want to speak to the manager now." +#define INFO_MSG "I cannot believe adding extra bacon costs more money. You didn’t put enough bacon in my burger! If you did, I wouldn’t be asking for more!" +#define WARN_MSG "I think I deserve to have some extra bacon for free. I’ve been coming for years whereas you started working here since last month." + +class Harl +{ + public: + Harl(); + ~Harl(); + void complain(std::string level); + private: + void debug(void); + void error(void); + void info(void); + void warning(void); +}; + +#endif diff --git a/cpp01/ex05/Makefile b/cpp01/ex05/Makefile new file mode 100644 index 0000000..cba50a1 --- /dev/null +++ b/cpp01/ex05/Makefile @@ -0,0 +1,109 @@ +# **************************************************************************** # + +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: rparodi +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # +# Updated: 2024/11/06 17:56:48 by rparodi ### ########.fr # +# # +# **************************************************************************** # + +# Variables +# Name +NAME = harl_2.0 + +# Commands +CXX = c++ +RM = rm -rf + +# Flags +# Mandatory flags for 42 cpp +CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/ +# Flags to debug and have the dependences (can be removed for correction) +CXXFLAGS += -MMD -g3 +# Flag to debug (TO REMOVE) +# CXXFLAGS += -D DEBUG=1 +# Sources +SRC = Harl.cpp \ + main.cpp + +# Objects +OBJDIRNAME = ./build +OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o)) + +# Colors +GREEN = \033[32m +GREY = \033[0;90m +RED = \033[0;31m +GOLD = \033[38;5;220m +END = \033[0m + +# Rules + +# All (make all) +all: header $(NAME) footer + +# Clean (make clean) +clean: + @printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n' + @printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n' + @$(RM) $(OBJDIRNAME) + +# Clean (make fclean) +fclean: clean + @printf '$(GREY) Removing $(END)$(RED)Program$(END)\n' + @$(RM) $(NAME) + @echo "" + +# Restart (make re) +re: header fclean all + +# Dependences for all +$(NAME): $(OBJ) + @mkdir -p $(OBJDIRNAME) + @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' + @$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ) + +# Creating the objects +$(OBJDIRNAME)/%.o: %.cpp + @mkdir -p $(dir $@) + @printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n' + @$(CXX) $(CXXFLAGS) -o $@ -c $< + +# Header +header: + @clear + @printf '\n\n' + @printf '$(GOLD) ******* ****** ******* $(END)\n' + @printf '$(GOLD) ****** *** ******* $(END)\n' + @printf '$(GOLD) ******* * ******* $(END)\n' + @printf '$(GOLD) ****** ******* $(END)\n' + @printf '$(GOLD) ******* ******* $(END)\n' + @printf '$(GOLD) ******************* ******* * $(END)\n' + @printf '$(GOLD) ******************* ******* *** $(END)\n' + @printf '$(GOLD) ****** ******* ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GREY) Made by rparodi$(END)\n\n' + +# Footer +footer: + @printf "\n" + @printf "$(GOLD) ,_ _,$(END)\n" + @printf "$(GOLD) | \\___//|$(END)\n" + @printf "$(GOLD) |=6 6=|$(END)\n" + @printf "$(GOLD) \\=._Y_.=/$(END)\n" + @printf "$(GOLD) ) \` ( ,$(END)\n" + @printf "$(GOLD) / \\ (('$(END)\n" + @printf "$(GOLD) | | ))$(END)\n" + @printf "$(GOLD) /| | | |\\_//$(END)\n" + @printf "$(GOLD) \\| |._.| |/-\`$(END)\n" + @printf "$(GOLD) '\"' '\"'$(END)\n" + @printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n' + +# Phony +.PHONY: all bonus clean fclean re + +-include ${OBJ:.o=.d} diff --git a/cpp01/ex05/main.cpp b/cpp01/ex05/main.cpp new file mode 100644 index 0000000..7170dfa --- /dev/null +++ b/cpp01/ex05/main.cpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/06 18:11:42 by rparodi #+# #+# */ +/* Updated: 2024/11/06 18:15:28 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +int main(void) +{ + Harl not_happy_peapol; + + std::cout << std::endl << "DEBUG MSG:" << std::endl; + not_happy_peapol.complain("debug"); + std::cout << std::endl << "ERROR MSG:" << std::endl; + not_happy_peapol.complain("error"); + std::cout << std::endl << "INFO MSG:" << std::endl; + not_happy_peapol.complain("info"); + std::cout << std::endl << "WARNING MSG:" << std::endl; + not_happy_peapol.complain("warning"); +}