update: finishing for good the ex05 of the module 01
This commit is contained in:
parent
4e8dc67e65
commit
618ebf8777
4 changed files with 220 additions and 0 deletions
47
cpp01/ex05/Harl.cpp
Normal file
47
cpp01/ex05/Harl.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Harl.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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])();
|
||||
}
|
||||
37
cpp01/ex05/Harl.hpp
Normal file
37
cpp01/ex05/Harl.hpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Harl.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <string>
|
||||
#include <iostream>
|
||||
|
||||
#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
|
||||
109
cpp01/ex05/Makefile
Normal file
109
cpp01/ex05/Makefile
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
# **************************************************************************** #
|
||||
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
27
cpp01/ex05/main.cpp
Normal file
27
cpp01/ex05/main.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue