From e292dcc32ee387c4e62af07a4b61b221f13a0ae2 Mon Sep 17 00:00:00 2001 From: Adam JOLY Date: Sat, 9 Nov 2024 17:43:25 +0100 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=E2=9C=A8=E3=80=8D=20feat(Harl=202.0):?= =?UTF-8?q?=20Ex05=20finished?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + ex05/Makefile | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ ex05/harl.cpp | 42 +++++++++++++++++++++++++++++++++++++++ ex05/harl.hpp | 28 ++++++++++++++++++++++++++ ex05/main.cpp | 22 +++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 ex05/Makefile create mode 100644 ex05/harl.cpp create mode 100644 ex05/harl.hpp create mode 100644 ex05/main.cpp diff --git a/.gitignore b/.gitignore index 39be181..bc125af 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ zombieHorde thisisabrain violence sed +harl diff --git a/ex05/Makefile b/ex05/Makefile new file mode 100644 index 0000000..030f3fa --- /dev/null +++ b/ex05/Makefile @@ -0,0 +1,55 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: adjoly +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/10/25 16:09:27 by adjoly #+# #+# # +# Updated: 2024/11/09 16:15:35 by adjoly ### ########.fr # +# # +# **************************************************************************** # + +NAME = harl + +CC = c++ + +OBJSDIR = obj/ + +SRCS = main.cpp \ + harl.cpp + +OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o)) + +FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP + +RED = \033[0;31m +GREEN = \033[0;32m +YELLOW = \033[1;33m +PURPLE = \e[0;35m +NC = \033[0m +DELETE = \x1B[2K\r + +all: $(NAME) + +$(NAME): $(OBJS) + @$(CC) $(FLAGS) $(OBJS) -o $(NAME) + @printf "$(YELLOW)「✨」($(NAME)) Program compiled\n" + +$(OBJSDIR)%.o: %.cpp + @mkdir -p $(@D) + @$(CC) $(FLAGS) -c $< -o $@ + @printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n" + +clean: + @rm -f $(OBJS) + @printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n" + +fclean: clean + @rm -f $(NAME) + @rm -Rf $(OBJSDIR) + @printf "$(RED)「🗑️」($(NAME)) Program deleted\n" + +re: fclean all + +.PHONY: clean fclean all re diff --git a/ex05/harl.cpp b/ex05/harl.cpp new file mode 100644 index 0000000..ce8ae73 --- /dev/null +++ b/ex05/harl.cpp @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/09 17:15:01 by adjoly #+# #+# */ +/* Updated: 2024/11/09 17:39:12 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "harl.hpp" +#include + +void Harl::complain(std::string level) { + std::string complainLevel[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; + void (Harl::*func[4])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error}; + uint8_t i = 0; + + while (i < 4 && level != complainLevel[i]) + i++; + if (i < 4) + (this->*func[i])(); + return ; +} + +void Harl::debug(void) { + std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!" << std::endl; +} + +void Harl::info(void) { + std::cout << "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!" << std::endl; +} + +void Harl::warning(void) { + std::cout << "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." << std::endl; +} + +void Harl::error(void) { + std::cout << "This is unacceptable! I want to speak to the manager now." << std::endl; +} diff --git a/ex05/harl.hpp b/ex05/harl.hpp new file mode 100644 index 0000000..c3aac1f --- /dev/null +++ b/ex05/harl.hpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/09 16:13:40 by adjoly #+# #+# */ +/* Updated: 2024/11/09 17:35:57 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include + +#define uint8_t unsigned char + +class Harl { + private: + void debug(void); + void info(void); + void warning(void); + void error(void); + + public: + void complain(std::string level); +}; diff --git a/ex05/main.cpp b/ex05/main.cpp new file mode 100644 index 0000000..77a718f --- /dev/null +++ b/ex05/main.cpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/09 16:12:06 by adjoly #+# #+# */ +/* Updated: 2024/11/09 17:42:31 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "harl.hpp" + +int main(void) { + Harl harl; + + /* harl.complain("INFO"); */ + /* harl.complain("DEBUG"); */ + harl.complain("WARNING"); + /* harl.complain("ERROR"); */ +}