「🏗️」 wip(Ex03): Now with template !
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/09 11:24:41 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) {
|
AMateria::AMateria(std::string const &type) {
|
||||||
log("➕", "AMateria", "", "constructor called");
|
log("➕", "AMateria", "", "copy constructor called");
|
||||||
}
|
}
|
||||||
|
|
||||||
AMateria::~AMateria(void) {
|
AMateria::~AMateria(void) {
|
||||||
|
@ -6,17 +6,18 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/10 14:59:12 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
|
#pragma once
|
||||||
|
|
||||||
#include "AMateria.hpp"
|
#include "AMateria.hpp"
|
||||||
|
#include "ICharacter.hpp"
|
||||||
|
|
||||||
#define ENV_SIZE 4
|
#define ENV_SIZE 4
|
||||||
|
|
||||||
class Character {
|
class Character : public ICharacter{
|
||||||
private:
|
private:
|
||||||
AMateria _materias[ENV_SIZE];
|
AMateria _materias[ENV_SIZE];
|
||||||
public:
|
public:
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* Cube.hpp :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* 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 {
|
|
||||||
|
|
||||||
};
|
|
@ -6,40 +6,14 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/10 12:34:54 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 "Cure.hpp"
|
||||||
#include "AMateria.hpp"
|
|
||||||
#include "ICharacter.hpp"
|
|
||||||
#include "Log.hpp"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Cure::Cure(void) : AMateria("cure") {
|
const std::string Cure::_typeName(void) { return ("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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Cure::use(ICharacter &character) {
|
void Cure::use(ICharacter &character) {
|
||||||
std::cout << "* heals " << character.getName() << "’s wounds *";
|
std::cout << "* heals " << character.getName() << "’s wounds *";
|
||||||
|
@ -6,22 +6,18 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/10 12:35:41 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
|
#pragma once
|
||||||
|
|
||||||
#include "AMateria.hpp"
|
|
||||||
#include "ICharacter.hpp"
|
#include "ICharacter.hpp"
|
||||||
|
#include "MateriaTemplate.hpp"
|
||||||
|
|
||||||
class Cure : public AMateria {
|
class Cure : public MateriaTemplate<Cure>{
|
||||||
public:
|
public:
|
||||||
Cure(void);
|
static const std::string _typeName(void);
|
||||||
~Cure(void);
|
|
||||||
Cure(const Cure &);
|
|
||||||
Cure &operator=(const Cure &);
|
|
||||||
|
|
||||||
Cure *clone(void) const;
|
|
||||||
void use(ICharacter &);
|
void use(ICharacter &);
|
||||||
};
|
};
|
||||||
|
30
ex03/Ice.cpp
30
ex03/Ice.cpp
@ -6,40 +6,14 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/07 12:13:03 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 "Ice.hpp"
|
||||||
#include "AMateria.hpp"
|
|
||||||
#include "ICharacter.hpp"
|
|
||||||
#include "Log.hpp"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Ice::Ice(void) : AMateria("ice") {
|
const std::string Ice::_typeName(void) { return ("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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Ice::use(ICharacter &character) {
|
void Ice::use(ICharacter &character) {
|
||||||
std::cout << "* shoots an ice bolt at " << character.getName() << " *";
|
std::cout << "* shoots an ice bolt at " << character.getName() << " *";
|
||||||
|
11
ex03/Ice.hpp
11
ex03/Ice.hpp
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/06 16:51:34 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 "AMateria.hpp"
|
||||||
#include "ICharacter.hpp"
|
#include "ICharacter.hpp"
|
||||||
|
#include "MateriaTemplate.hpp"
|
||||||
|
|
||||||
class Ice : public AMateria {
|
class Ice : public MateriaTemplate<Ice> {
|
||||||
public:
|
public:
|
||||||
Ice(void);
|
static const std::string _typeName(void);
|
||||||
~Ice(void);
|
|
||||||
Ice(const Ice &);
|
|
||||||
Ice &operator=(const Ice &);
|
|
||||||
|
|
||||||
Ice *clone(void) const;
|
|
||||||
void use(ICharacter &);
|
void use(ICharacter &);
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* MateriaSource.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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);
|
||||||
|
}
|
@ -6,23 +6,24 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/10 13:51:37 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
|
#pragma once
|
||||||
|
|
||||||
#include "AMateria.hpp"
|
#include "AMateria.hpp"
|
||||||
|
#include "IMateriaSource.hpp"
|
||||||
|
|
||||||
class MaterianSource {
|
class MateriaSource : public IMateriaSource {
|
||||||
private:
|
private:
|
||||||
AMateria _materias[4];
|
AMateria *_materias[4];
|
||||||
public:
|
public:
|
||||||
MaterianSource(void);
|
MateriaSource(void);
|
||||||
~MaterianSource(void);
|
~MateriaSource(void);
|
||||||
MaterianSource(const MaterianSource &);
|
MateriaSource(const MateriaSource &);
|
||||||
MaterianSource &operator=(const MaterianSource &);
|
MateriaSource &operator=(const MateriaSource &);
|
||||||
|
|
||||||
void leanrMateria(AMateria *);
|
void learnMateria(AMateria *);
|
||||||
AMateria createMateria(std::string const &);
|
AMateria *createMateria(std::string const &);
|
||||||
};
|
};
|
||||||
|
58
ex03/MateriaTemplate.hpp
Normal file
58
ex03/MateriaTemplate.hpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* MateriaTemplate.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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 <typename T>
|
||||||
|
class MateriaTemplate : public AMateria {
|
||||||
|
public:
|
||||||
|
MateriaTemplate(void);
|
||||||
|
~MateriaTemplate(void);
|
||||||
|
MateriaTemplate(T const &);
|
||||||
|
T &operator=(const T &);
|
||||||
|
|
||||||
|
AMateria *clone(void) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
MateriaTemplate<T>::MateriaTemplate(void) :
|
||||||
|
AMateria(T::_typeName()) {
|
||||||
|
log("➕", T::_typeName(), "", "default constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
MateriaTemplate<T>::~MateriaTemplate(void) {
|
||||||
|
log("➖", T::_typeName(), "", "destructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
MateriaTemplate<T>::MateriaTemplate(T const &cpy) {
|
||||||
|
*this = cpy;
|
||||||
|
log("➕", T::_typeName(), "", "copy constructor called");
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T &MateriaTemplate<T>::operator=(const T &cpy) {
|
||||||
|
log("➕", T::_typeName(), "", "copy assignement constructor called");
|
||||||
|
if (this != &cpy) {
|
||||||
|
this->_type = cpy._type;
|
||||||
|
}
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
AMateria *MateriaTemplate<T>::clone(void) const {
|
||||||
|
return (new T);
|
||||||
|
}
|
Reference in New Issue
Block a user