diff --git a/d04/ex00/Cat.cpp b/d04/ex00/Cat.cpp index e1eff33..bae88b1 100644 --- a/d04/ex00/Cat.cpp +++ b/d04/ex00/Cat.cpp @@ -12,7 +12,7 @@ Cat::Cat() { return; } -Cat::Cat( Cat const & src ) { +Cat::Cat( Cat const & src ) : Animal(src) { std::cout << COPLIEN_COLOR "Cat copy constructor" RESET "\n"; *this = src; return; diff --git a/d04/ex00/Dog.cpp b/d04/ex00/Dog.cpp index bb66bf2..b9aacb2 100644 --- a/d04/ex00/Dog.cpp +++ b/d04/ex00/Dog.cpp @@ -12,7 +12,7 @@ Dog::Dog() { return; } -Dog::Dog( Dog const & src ) { +Dog::Dog( Dog const & src ) : Animal(src) { std::cout << COPLIEN_COLOR "Dog copy constructor" RESET "\n"; *this = src; return; diff --git a/d04/ex00/Makefile b/d04/ex00/Makefile index 50eca1c..26cc22a 100644 --- a/d04/ex00/Makefile +++ b/d04/ex00/Makefile @@ -72,6 +72,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%) $(NAME): $(OBJS) $(CC) $(OBJS) -o $@ $(LIBS) +leaks: $(NAME) + valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) + clean: $(RM_OBJS) diff --git a/d04/ex00/WrongCat.cpp b/d04/ex00/WrongCat.cpp index 1c27203..4f0f279 100644 --- a/d04/ex00/WrongCat.cpp +++ b/d04/ex00/WrongCat.cpp @@ -12,7 +12,7 @@ WrongCat::WrongCat() { return; } -WrongCat::WrongCat( WrongCat const & src ) { +WrongCat::WrongCat( WrongCat const & src ) : WrongAnimal(src) { std::cout << COPLIEN_COLOR "WrongCat copy constructor" RESET "\n"; *this = src; return; diff --git a/d04/ex01/Makefile b/d04/ex01/Makefile index 5de1a7f..a0f2376 100644 --- a/d04/ex01/Makefile +++ b/d04/ex01/Makefile @@ -70,6 +70,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%) $(NAME): $(OBJS) $(CC) $(OBJS) -o $@ $(LIBS) +leaks: $(NAME) + valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) + clean: $(RM_OBJS) diff --git a/d04/ex01/burn b/d04/ex01/burn deleted file mode 100755 index 4345fd3..0000000 Binary files a/d04/ex01/burn and /dev/null differ diff --git a/d04/ex02/Makefile b/d04/ex02/Makefile index fd3eed7..41d7f5a 100644 --- a/d04/ex02/Makefile +++ b/d04/ex02/Makefile @@ -9,10 +9,6 @@ NAME = pure #TYPE = c TYPE = cpp -ifndef TYPE -echo hello -endif - ifeq "$(TYPE)" "c" CC = c EXT = c @@ -74,6 +70,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%) $(NAME): $(OBJS) $(CC) $(OBJS) -o $@ $(LIBS) +leaks: $(NAME) + valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) + clean: $(RM_OBJS) diff --git a/d04/ex02/a.out b/d04/ex02/a.out deleted file mode 100755 index 9701802..0000000 Binary files a/d04/ex02/a.out and /dev/null differ diff --git a/d04/ex02/main.cpp b/d04/ex02/main.cpp index 8292f33..e83576d 100644 --- a/d04/ex02/main.cpp +++ b/d04/ex02/main.cpp @@ -17,31 +17,31 @@ int main() { Animal* j = new Cat("I am just a cat"); std::cout << std::endl; - std::cout << "cat i : "; + std::cout << B_BLUE "cat i : " RESET; i->getBrain()->printIdea(0); - std::cout << "cat j : "; + std::cout << B_BLUE "cat j : " RESET; j->getBrain()->printIdea(0); - std::cout << "\n*i = *j\n"; + std::cout << "\n" B_BLUE "*i = *j" RESET "\n"; *i = *j; - std::cout << "cat i : "; + std::cout << B_BLUE "cat i : " RESET; i->getBrain()->printIdea(0); - std::cout << "cat j : "; + std::cout << B_BLUE "cat j : " RESET; j->getBrain()->printIdea(0); - std::cout << "\nj->getBrain->putIdea(\"I am not a cat\")\n"; + std::cout << "\n" B_BLUE "j->getBrain->putIdea(\"I am not a cat\")" RESET "\n"; j->getBrain()->putIdea(0, "I am not a cat");; - std::cout << "cat i : "; + std::cout << B_BLUE "cat i : " RESET; i->getBrain()->printIdea(0); - std::cout << "cat j : "; + std::cout << B_BLUE "cat j : " RESET; j->getBrain()->printIdea(0); std::cout << std::endl; - std::cout << "delete i\n"; + std::cout << B_BLUE "delete i" RESET "\n"; delete i; - std::cout << "delete j\n"; + std::cout << B_BLUE "delete j" RESET "\n"; delete j; } diff --git a/d04/ex02/pure b/d04/ex02/pure deleted file mode 100755 index 956ca8d..0000000 Binary files a/d04/ex02/pure and /dev/null differ diff --git a/d04/ex02/test_assignement.cpp b/d04/ex02/test_assignement.cpp deleted file mode 100644 index f01af24..0000000 --- a/d04/ex02/test_assignement.cpp +++ /dev/null @@ -1,38 +0,0 @@ -# include -# include - -class Animal { -public: - virtual Animal & operator=( Animal const & rhs ) { - std::cout << "Animal operator=\n"; - return *this; - } -}; - -class Cat : public Animal { -public: - Cat & operator=( Cat const & rhs ) { - Animal::operator=(rhs); - std::cout << "Cat operator=\n"; - return *this; - } - Cat & operator=( Animal const & rhs ) { - Animal::operator=(rhs); - std::cout << "Cat operator=\n"; - return *this; - } - void catSpeak() {std::cout << "I am a cat\n";} -}; - -int main() { - Animal* i = new Cat(); - Animal* j = new Cat(); - - i->catSpeak(); - j->catSpeak(); - *i = *j; - - delete i; - delete j; -} - diff --git a/d04/ex03/Makefile b/d04/ex03/Makefile deleted file mode 100644 index 710467d..0000000 --- a/d04/ex03/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -# . name = value \ . += append to a variable # -# VARIABLES . value . != set result of command # -# . name is case sensitive . ?= set if not already set # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - -NAME = materia - -#TYPE = c -TYPE = cpp - -ifeq "$(TYPE)" "c" - CC = c - EXT = c -else ifeq "$(TYPE)" "cpp" - CC = c++ - EXT = cpp -endif - -CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -ifeq "$(TYPE)" "cpp" - CFLAGS += -std=c++98 -endif - -VPATH = $(D_SRCS) - -LIBS = - -INCLUDES = -I$(D_HEADERS) - -D_SRCS = srcs -SRCS = main.cpp \ - Animal.cpp \ - Dog.cpp \ - Cat.cpp \ - Brain.cpp - -D_HEADERS = headers -HEADERS = Animal.hpp \ - Dog.hpp \ - Cat.hpp \ - Brain.hpp - -D_OBJS = builds -OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) - -ifeq "$(D_OBJS)" "." - RM_OBJS = rm -f $(OBJS) -else - RM_OBJS = rm -rf $(D_OBJS) -endif - - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -# . target: prerequisites . $@ : target # -# RULES . recipe . $< : 1st prerequisite # -# . recipe . $^ : all prerequisites # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - -all: $(NAME) - -$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS) - $(CC) $(CFLAGS) -c $< -o $@ - -$(D_OBJS): - mkdir $@ - -$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) - -$(NAME): $(OBJS) - $(CC) $(OBJS) -o $@ $(LIBS) - -clean: - $(RM_OBJS) - -fclean: clean - rm -f $(NAME) - -re: fclean all - -.PHONY : all clean fclean re - diff --git a/d04/ex03/headers/AMateria.hpp b/d04/ex03/headers/AMateria.hpp deleted file mode 100644 index 096f251..0000000 --- a/d04/ex03/headers/AMateria.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef AMATERIA_HPP -# define AMATERIA_HPP - -# include - -#include "ICharacter.hpp" - -class AMateria { - -public: - AMateria(std::string const & type); - virtual ~AMateria(); - - std::string const & getType() const; //Returns the materia type - - virtual AMateria* clone() const = 0; - virtual void use(ICharacter& target); - -protected: - std::string _type; - -}; - -#endif diff --git a/d04/ex03/headers/Character.hpp b/d04/ex03/headers/Character.hpp deleted file mode 100644 index 73e2c10..0000000 --- a/d04/ex03/headers/Character.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef CHARACTER_HPP -# define CHARACTER_HPP - -#include "ICharacter.hpp" - -class Character : public ICharacter { - -public: - Character(); - Character( Character const & src ); - ~Character(); - Character & operator=( Character const & rhs ); - -private: - -}; - -#endif diff --git a/d04/ex03/headers/Cure.hpp b/d04/ex03/headers/Cure.hpp deleted file mode 100644 index 1ca03c8..0000000 --- a/d04/ex03/headers/Cure.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef CURE_HPP -# define CURE_HPP - -#include "AMateria.hpp" - -class Cure : public AMateria { - -public: - Cure(); - Cure( Cure const & src ); - ~Cure(); - Cure & operator=( Cure const & rhs ); - -private: - -}; - -#endif - diff --git a/d04/ex03/headers/ICharacter.hpp b/d04/ex03/headers/ICharacter.hpp deleted file mode 100644 index 11fa9fc..0000000 --- a/d04/ex03/headers/ICharacter.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ICE_HPP -# define ICE_HPP - -class ICharacter { - -public: - virtual ~ICharacter() {} - virtual std::string const & getName() const = 0; - virtual void equip(AMateria* m) = 0; - virtual void unequip(int idx) = 0; - virtual void use(int idx, ICharacter& target) = 0; -}; - -#endif - diff --git a/d04/ex03/headers/Ice.hpp b/d04/ex03/headers/Ice.hpp deleted file mode 100644 index 52e3419..0000000 --- a/d04/ex03/headers/Ice.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef ICE_HPP -# define ICE_HPP - -#include "AMateria.hpp" - -class Ice : public AMateria { - -public: - Ice(); - Ice( Ice const & src ); - ~Ice(); - Ice & operator=( Ice const & rhs ); - -private: - -}; - -#endif diff --git a/d04/ex03/main.cpp b/d04/ex03/main.cpp deleted file mode 100644 index 245e05a..0000000 --- a/d04/ex03/main.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "AMateria.hpp" -#include "Ice.hpp" -#include "Cure.hpp" -#include "ICharacter" -#include "IMateriaSource" - -int main() { - - IMateriaSource* src = new MateriaSource(); - src->learnMateria(new Ice()); - src->learnMateria(new Cure()); - - ICharacter* me = new Character("me"); - - AMateria* tmp; - tmp = src->createMateria("ice"); - me->equip(tmp); - tmp = src->createMateria("cure"); - me->equip(tmp); - - ICharacter* bob = new Character("bob"); - - me->use(0, *bob); - me->use(1, *bob); - - delete bob; - delete me; - delete src; - - return 0; -} - diff --git a/d04/ex03/srcs/AMateria.cpp b/d04/ex03/srcs/AMateria.cpp deleted file mode 100644 index fca370d..0000000 --- a/d04/ex03/srcs/AMateria.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "AMateria.hpp" - -AMateria::AMateria(std::string const & type) { - _type = type; -} - -std::string const & AMateria::getType() const { - return _type; -} - -virtual AMateria * AMateria::clone() const { - AMateria clone = new AMateria; - return clone; -} diff --git a/d04/ex03/srcs/Cure.cpp b/d04/ex03/srcs/Cure.cpp deleted file mode 100644 index d804128..0000000 --- a/d04/ex03/srcs/Cure.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Cure.hpp" - -Cure::Cure() : _type("cure") {} - -Cure::Cure( Cure const & src ) { - *this = src -} - -Cure & Cure::operator=( Cure const & rhs ) { - return *this; -} - -virtual void Ice::use(ICharacter & target) { - std::cout << "* heals " << target.name << "’s wounds *" -} diff --git a/d04/ex03/srcs/Ice.cpp b/d04/ex03/srcs/Ice.cpp deleted file mode 100644 index 06f7379..0000000 --- a/d04/ex03/srcs/Ice.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Ice.hpp" - -Ice::Ice() : _type("ice") {} - -Ice::Ice( Ice const & src ) { - *this = src -} - -Ice & Ice::operator=( Ice const & rhs ) { - return *this; -} - -virtual void Ice::use(ICharacter & target) { - std::cout << "* shoots an ice bolt at " << target.name << " *" -}