diff --git a/cpp01/ex05/Harl.cpp b/cpp01/ex05/Harl.cpp index 0423bba..a508b1f 100644 --- a/cpp01/ex05/Harl.cpp +++ b/cpp01/ex05/Harl.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/06 17:41:03 by rparodi #+# #+# */ -/* Updated: 2024/11/06 18:11:34 by rparodi ### ########.fr */ +/* Updated: 2024/11/06 19:43:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,7 +38,7 @@ void Harl::warning() void Harl::complain(std::string level) { - std::string categorie[] = {"debug", "error", "info", "warning"}; + std::string categorie[] = {"debug", "info", "warning", "error"}; void (Harl::*choice[4])(void) = { &Harl::debug, &Harl::error, &Harl::info, &Harl::warning }; for (size_t i = 0; i < 4; i++) diff --git a/cpp01/ex05/Harl.hpp b/cpp01/ex05/Harl.hpp index 4c63c93..fe26d3e 100644 --- a/cpp01/ex05/Harl.hpp +++ b/cpp01/ex05/Harl.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/06 17:37:15 by rparodi #+# #+# */ -/* Updated: 2024/11/06 17:55:57 by rparodi ### ########.fr */ +/* Updated: 2024/11/06 19:43:33 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,9 +29,9 @@ class Harl void complain(std::string level); private: void debug(void); - void error(void); void info(void); void warning(void); + void error(void); }; #endif diff --git a/cpp01/ex05/harl_2.0 b/cpp01/ex05/harl_2.0 new file mode 100755 index 0000000..da42497 Binary files /dev/null and b/cpp01/ex05/harl_2.0 differ diff --git a/cpp01/ex06/Harl.cpp b/cpp01/ex06/Harl.cpp new file mode 100644 index 0000000..c0ec921 --- /dev/null +++ b/cpp01/ex06/Harl.cpp @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/06 17:41:03 by rparodi #+# #+# */ +/* Updated: 2024/11/06 20:10:59 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +Harl::Harl(){} + +Harl::~Harl(){} + +void Harl::debug() +{ + std::cout << "[DEBUG]" << std::endl << DEBUG_MSG << std::endl; + Harl::info(); +} + +void Harl::info() +{ + std::cout << "[INFO]" << std::endl << INFO_MSG << std::endl; + Harl::warning(); +} + +void Harl::warning() +{ + std::cout << "[WARNING]" << std::endl << WARN_MSG << std::endl; + Harl::error(); +} + +void Harl::error() +{ + std::cout << "[ERROR]" << std::endl << ERROR_MSG << std::endl; +} + +void Harl::complain(std::string level) +{ + std::string categorie[] = {"DEBUG", "INFO", "WARNING", "ERROR"}; + size_t i; + + for (i = 0; i < 4; i++) + if (level == categorie[i]) + break ; + switch (i) + { + case 0: + this->debug(); + break; + case 1: + this->info(); + break; + case 2: + this->warning(); + break; + case 3: + this->error(); + break; + default: + return ; + } + +} diff --git a/cpp01/ex06/Harl.hpp b/cpp01/ex06/Harl.hpp new file mode 100644 index 0000000..fe26d3e --- /dev/null +++ b/cpp01/ex06/Harl.hpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/06 17:37:15 by rparodi #+# #+# */ +/* Updated: 2024/11/06 19:43:33 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 info(void); + void warning(void); + void error(void); +}; + +#endif diff --git a/cpp01/ex06/Makefile b/cpp01/ex06/Makefile new file mode 100644 index 0000000..0547a9f --- /dev/null +++ b/cpp01/ex06/Makefile @@ -0,0 +1,109 @@ +# **************************************************************************** # + +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: rparodi +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # +# Updated: 2024/11/06 19:44:47 by rparodi ### ########.fr # +# # +# **************************************************************************** # + +# Variables +# Name +NAME = harlFilter + +# 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/ex06/harlFilter b/cpp01/ex06/harlFilter new file mode 100755 index 0000000..2aa1b02 Binary files /dev/null and b/cpp01/ex06/harlFilter differ diff --git a/cpp01/ex06/main.cpp b/cpp01/ex06/main.cpp new file mode 100644 index 0000000..0588d50 --- /dev/null +++ b/cpp01/ex06/main.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/06 18:11:42 by rparodi #+# #+# */ +/* Updated: 2024/11/06 19:50:18 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +int main(int argc, char *argv[]) +{ + if (argc != 2) + { + std::cerr << "Error:\nThanks to follow this syntax: " << argv[0] << " " << std::endl; + return (1); + } + Harl not_happy_peapol; + + std::string choice(argv[1]); + not_happy_peapol.complain(choice); +}