diff --git a/ex03/AMateria.cpp b/ex03/AMateria.cpp index 2ba0f04..e2efc87 100644 --- a/ex03/AMateria.cpp +++ b/ex03/AMateria.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/09 11:24:41 by adjoly #+# #+# */ -/* Updated: 2024/12/10 12:28:09 by adjoly ### ########.fr */ +/* Updated: 2024/12/11 11:03:42 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ AMateria::AMateria(void) : _type("") { } AMateria::AMateria(std::string const &type) { - log("➕", "AMateria", "", "constructor called"); + log("➕", "AMateria", "", "copy constructor called"); } AMateria::~AMateria(void) { diff --git a/ex03/Character.hpp b/ex03/Character.hpp index a98151e..d5f345e 100644 --- a/ex03/Character.hpp +++ b/ex03/Character.hpp @@ -6,17 +6,18 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/10 14:59:12 by adjoly #+# #+# */ -/* Updated: 2024/12/10 15:15:46 by adjoly ### ########.fr */ +/* Updated: 2024/12/10 15:43:54 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #include "AMateria.hpp" +#include "ICharacter.hpp" #define ENV_SIZE 4 -class Character { +class Character : public ICharacter{ private: AMateria _materias[ENV_SIZE]; public: diff --git a/ex03/Cube.hpp b/ex03/Cube.hpp deleted file mode 100644 index 4da3521..0000000 --- a/ex03/Cube.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* Cube.hpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: adjoly +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/12/06 16:47:20 by adjoly #+# #+# */ -/* Updated: 2024/12/06 16:51:31 by adjoly ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#pragma once - -#include "AMateria.hpp" - -class Cube : public AMateria { - -}; diff --git a/ex03/Cure.cpp b/ex03/Cure.cpp index c5e2a8a..30a6e6f 100644 --- a/ex03/Cure.cpp +++ b/ex03/Cure.cpp @@ -6,40 +6,14 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/10 12:34:54 by adjoly #+# #+# */ -/* Updated: 2024/12/10 13:47:54 by adjoly ### ########.fr */ +/* Updated: 2024/12/11 12:08:03 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "Cure.hpp" -#include "AMateria.hpp" -#include "ICharacter.hpp" -#include "Log.hpp" #include -Cure::Cure(void) : AMateria("cure") { - log("➕", "Cure", "", "default constructor called"); -} - -Cure::Cure(const Cure &cpy) { - log("➕", "Cure", "", "copy constructor called"); - *this = cpy; -} - -Cure::~Cure(void) { - log("➖", "Cure", "", "destructor called"); -} - -Cure &Cure::operator=(const Cure &cpy) { - log("➕", "Cure", "", "copy assignement constructor called"); - if (this != &cpy) { - _type = cpy._type; - } - return (*this); -} - -Cure *Cure::clone(void) const { - return (new Cure); -} +const std::string Cure::_typeName(void) { return ("cure"); } void Cure::use(ICharacter &character) { std::cout << "* heals " << character.getName() << "’s wounds *"; diff --git a/ex03/Cure.hpp b/ex03/Cure.hpp index dc21584..bd9f78f 100644 --- a/ex03/Cure.hpp +++ b/ex03/Cure.hpp @@ -6,22 +6,18 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/10 12:35:41 by adjoly #+# #+# */ -/* Updated: 2024/12/10 12:36:22 by adjoly ### ########.fr */ +/* Updated: 2024/12/11 12:07:54 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once -#include "AMateria.hpp" #include "ICharacter.hpp" +#include "MateriaTemplate.hpp" -class Cure : public AMateria { +class Cure : public MateriaTemplate{ public: - Cure(void); - ~Cure(void); - Cure(const Cure &); - Cure &operator=(const Cure &); + static const std::string _typeName(void); - Cure *clone(void) const; - void use(ICharacter &); + void use(ICharacter &); }; diff --git a/ex03/Ice.cpp b/ex03/Ice.cpp index f584401..b19601d 100644 --- a/ex03/Ice.cpp +++ b/ex03/Ice.cpp @@ -6,40 +6,14 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/07 12:13:03 by adjoly #+# #+# */ -/* Updated: 2024/12/10 12:25:11 by adjoly ### ########.fr */ +/* Updated: 2024/12/11 12:08:18 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "Ice.hpp" -#include "AMateria.hpp" -#include "ICharacter.hpp" -#include "Log.hpp" #include -Ice::Ice(void) : AMateria("ice") { - log("➕", "Ice", "", "default constructor called"); -} - -Ice::Ice(const Ice &cpy) { - log("➕", "Ice", "", "copy constructor called"); - *this = cpy; -} - -Ice::~Ice(void) { - log("➖", "Ice", "", "destructor called"); -} - -Ice &Ice::operator=(const Ice &cpy) { - log("➕", "Ice", "", "copy assignement constructor called"); - if (this != &cpy) { - _type = cpy._type; - } - return (*this); -} - -Ice *Ice::clone(void) const { - return (new Ice); -} +const std::string Ice::_typeName(void) { return ("ice"); } void Ice::use(ICharacter &character) { std::cout << "* shoots an ice bolt at " << character.getName() << " *"; diff --git a/ex03/Ice.hpp b/ex03/Ice.hpp index 4a2b5a0..58d47b6 100644 --- a/ex03/Ice.hpp +++ b/ex03/Ice.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/06 16:51:34 by adjoly #+# #+# */ -/* Updated: 2024/12/07 12:29:29 by adjoly ### ########.fr */ +/* Updated: 2024/12/11 12:07:40 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,14 +14,11 @@ #include "AMateria.hpp" #include "ICharacter.hpp" +#include "MateriaTemplate.hpp" -class Ice : public AMateria { +class Ice : public MateriaTemplate { public: - Ice(void); - ~Ice(void); - Ice(const Ice &); - Ice &operator=(const Ice &); + static const std::string _typeName(void); - Ice *clone(void) const; - void use(ICharacter &); + void use(ICharacter &); }; diff --git a/ex03/MateriaSource.cpp b/ex03/MateriaSource.cpp index e69de29..554ab60 100644 --- a/ex03/MateriaSource.cpp +++ b/ex03/MateriaSource.cpp @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* MateriaSource.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/11 12:17:06 by adjoly #+# #+# */ +/* Updated: 2024/12/11 12:31:04 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "MateriaSource.hpp" +#include "Log.hpp" + +MateriaSource::MateriaSource(void) { + log("➕", "MateriaSource", "", "default constructor called"); +} + +MateriaSource::~MateriaSource(void) { + log("➖", "MateriaSource", "", "destructor called"); + +} + +MateriaSource::MateriaSource(const MateriaSource &cpy) { + *this = cpy; + log("➕", "MateriaSource", "", "copy constructor called"); +} + +MateriaSource &MateriaSource::operator=(const MateriaSource &cpy) { + log("➕", "MateriaSource", "", "copy assignement constructor called"); + for (int i = 0; i < 4; i++) { + this->_materias[i] = cpy._materias[i]; + } + return (*this); +} diff --git a/ex03/MateriaSource.hpp b/ex03/MateriaSource.hpp index 6635415..0ff8cb2 100644 --- a/ex03/MateriaSource.hpp +++ b/ex03/MateriaSource.hpp @@ -6,23 +6,24 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/10 13:51:37 by adjoly #+# #+# */ -/* Updated: 2024/12/10 14:50:48 by adjoly ### ########.fr */ +/* Updated: 2024/12/11 12:18:02 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #include "AMateria.hpp" +#include "IMateriaSource.hpp" -class MaterianSource { +class MateriaSource : public IMateriaSource { private: - AMateria _materias[4]; + AMateria *_materias[4]; public: - MaterianSource(void); - ~MaterianSource(void); - MaterianSource(const MaterianSource &); - MaterianSource &operator=(const MaterianSource &); + MateriaSource(void); + ~MateriaSource(void); + MateriaSource(const MateriaSource &); + MateriaSource &operator=(const MateriaSource &); - void leanrMateria(AMateria *); - AMateria createMateria(std::string const &); + void learnMateria(AMateria *); + AMateria *createMateria(std::string const &); }; diff --git a/ex03/MateriaTemplate.hpp b/ex03/MateriaTemplate.hpp new file mode 100644 index 0000000..7da7fe5 --- /dev/null +++ b/ex03/MateriaTemplate.hpp @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* MateriaTemplate.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/11 10:59:31 by adjoly #+# #+# */ +/* Updated: 2024/12/11 12:06:51 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "AMateria.hpp" +#include "Log.hpp" + +template +class MateriaTemplate : public AMateria { + public: + MateriaTemplate(void); + ~MateriaTemplate(void); + MateriaTemplate(T const &); + T &operator=(const T &); + + AMateria *clone(void) const; +}; + +template +MateriaTemplate::MateriaTemplate(void) : + AMateria(T::_typeName()) { + log("➕", T::_typeName(), "", "default constructor called"); +} + +template +MateriaTemplate::~MateriaTemplate(void) { + log("➖", T::_typeName(), "", "destructor called"); +} + +template +MateriaTemplate::MateriaTemplate(T const &cpy) { + *this = cpy; + log("➕", T::_typeName(), "", "copy constructor called"); +} + +template +T &MateriaTemplate::operator=(const T &cpy) { + log("➕", T::_typeName(), "", "copy assignement constructor called"); + if (this != &cpy) { + this->_type = cpy._type; + } + return (*this); +} + +template +AMateria *MateriaTemplate::clone(void) const { + return (new T); +}