diff --git a/ex02/Makefile b/ex02/Makefile new file mode 100644 index 0000000..43d85ad --- /dev/null +++ b/ex02/Makefile @@ -0,0 +1,60 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: adjoly +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/10/25 16:09:27 by adjoly #+# #+# # +# Updated: 2025/04/16 10:44:14 by adjoly ### ########.fr # +# # +# **************************************************************************** # + +SHELL = bash + +NAME = MutantStack + +CC = c++ + +OBJSDIR = obj/ + +SRCS = $(shell find . -name '*.cpp') + +OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o)) + +FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP -g + +RED = \033[0;31m +GREEN = \033[0;32m +YELLOW = \033[1;33m +PURPLE = \e[0;35m +NC = \033[0m +DELETE = \x1B[2K\r + +ifeq ($(VERBOSE),true) + FLAGS += -D VERBOSE +endif + +all: $(NAME) + +$(NAME): $(OBJS) + @$(CC) $(FLAGS) -I . $(OBJS) -o $(NAME) + @printf "$(YELLOW)「✨」($(NAME)) Program compiled\n" + +$(OBJSDIR)%.o: %.cpp + @mkdir -p $(@D) + @$(CC) $(FLAGS) -I . -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/ex02/MutantStack b/ex02/MutantStack new file mode 100755 index 0000000..fcd6489 Binary files /dev/null and b/ex02/MutantStack differ diff --git a/ex02/MutantStack.hpp b/ex02/MutantStack.hpp new file mode 100644 index 0000000..4da0a71 --- /dev/null +++ b/ex02/MutantStack.hpp @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* MutantStack.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/16 10:44:35 by adjoly #+# #+# */ +/* Updated: 2025/04/19 20:51:25 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include +#include + +static 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 +} + +template class MutantStack : public std::stack { + public: + MutantStack(void) { + _log("➕", "MutantStack", "", "default constructor called"); + } + MutantStack(const MutantStack &cpy) : std::stack(cpy) { + _log("➕", "MutantStack", "", "copy constructor called"); + } + ~MutantStack(void) { _log("➖", "MutantStack", "", "destructor called"); } + + MutantStack &operator=(const MutantStack &cpy) { + if (this != &cpy) { + std::stack::operator=(cpy); + } + return *this; + } + + typedef typename std::stack::container_type::iterator iterator; + iterator begin(void) { return std::stack::c.begin(); } + iterator end(void) { return std::stack::c.end(); } + + typedef + typename std::stack::container_type::const_iterator const_iterator; + const_iterator begin(void) const { return std::stack::c.begin(); } + const_iterator end(void) const { return std::stack::c.end(); } + + private: +}; diff --git a/ex02/main.cpp b/ex02/main.cpp new file mode 100644 index 0000000..733fd71 --- /dev/null +++ b/ex02/main.cpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/16 10:53:23 by adjoly #+# #+# */ +/* Updated: 2025/04/19 20:55:37 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "MutantStack.hpp" + +int main(void) { + MutantStack stack; + + stack.push(5); + stack.push(17); + stack.pop(); + std::cout << "size = " << stack.size() << std::endl; + stack.push(3); + stack.push(5); + stack.push(737); + //[...] + for (MutantStack::iterator it = stack.begin(); it != stack.end(); it++) { + std::cout << *it << std::endl; + } + + return 0; +}