diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-11-12 15:46:07 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-11-12 15:46:07 +0100 |
| commit | b8e39b947890e74d82530e25ad9d02668aae1f0c (patch) | |
| tree | f59acfdecb0711137c200a4c5acb854e351f9cf9 /cpp04/ex03 | |
| parent | 96dcf214a8c40529b251ea31ef037868583dd1da (diff) | |
| download | piscine_cpp-b8e39b947890e74d82530e25ad9d02668aae1f0c.tar.gz piscine_cpp-b8e39b947890e74d82530e25ad9d02668aae1f0c.tar.bz2 piscine_cpp-b8e39b947890e74d82530e25ad9d02668aae1f0c.zip | |
Reformating cpp04 classes
Diffstat (limited to 'cpp04/ex03')
| -rw-r--r-- | cpp04/ex03/AMateria.cpp | 28 | ||||
| -rw-r--r-- | cpp04/ex03/AMateria.hpp | 6 | ||||
| -rw-r--r-- | cpp04/ex03/Character.cpp | 24 | ||||
| -rw-r--r-- | cpp04/ex03/Character.hpp | 8 | ||||
| -rw-r--r-- | cpp04/ex03/Cure.cpp | 23 | ||||
| -rw-r--r-- | cpp04/ex03/Cure.hpp | 4 | ||||
| -rw-r--r-- | cpp04/ex03/ICharacter.hpp | 6 | ||||
| -rw-r--r-- | cpp04/ex03/Ice.cpp | 23 | ||||
| -rw-r--r-- | cpp04/ex03/Ice.hpp | 4 | ||||
| -rw-r--r-- | cpp04/ex03/MateriaSource.cpp | 20 | ||||
| -rw-r--r-- | cpp04/ex03/MateriaSource.hpp | 5 |
11 files changed, 53 insertions, 98 deletions
diff --git a/cpp04/ex03/AMateria.cpp b/cpp04/ex03/AMateria.cpp index 77e674b..1dc7ca9 100644 --- a/cpp04/ex03/AMateria.cpp +++ b/cpp04/ex03/AMateria.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 16:26:57 by charles #+# #+# */ -/* Updated: 2020/04/14 16:35:09 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:40:23 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,35 +18,23 @@ AMateria::AMateria(AMateria const& other) m_type = ""; } -void AMateria::operator=(AMateria const& other) +AMateria& AMateria::operator=(AMateria const& other) { _xp = other._xp; + return *this; } -AMateria::~AMateria() -{ -} +AMateria::~AMateria() {} -AMateria::AMateria(std::string const& type) - : m_type(type), _xp(0) -{ -} +AMateria::AMateria(std::string const& type) : m_type(type), _xp(0) {} std::string const& AMateria::getType() const { return m_type; } -unsigned int AMateria::getXP() const -{ - return _xp; -} +unsigned int AMateria::getXP() const { return _xp; } -void AMateria::use(ICharacter& target) -{ - _xp += 10; -} +void AMateria::use(ICharacter& target) { _xp += 10; } -AMateria::AMateria() -{ -} +AMateria::AMateria() {} diff --git a/cpp04/ex03/AMateria.hpp b/cpp04/ex03/AMateria.hpp index 65d5cc5..7fef1c8 100644 --- a/cpp04/ex03/AMateria.hpp +++ b/cpp04/ex03/AMateria.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 16:24:00 by charles #+# #+# */ -/* Updated: 2020/04/14 17:55:18 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:41:54 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,11 +16,13 @@ # include <string> # include "ICharacter.hpp" +class ICharacter; + class AMateria { public: AMateria(AMateria const& other); - void operator=(AMateria const& other); + AMateria& operator=(AMateria const& other); virtual ~AMateria(); AMateria(std::string const& type); diff --git a/cpp04/ex03/Character.cpp b/cpp04/ex03/Character.cpp index 34aaa48..ee03e63 100644 --- a/cpp04/ex03/Character.cpp +++ b/cpp04/ex03/Character.cpp @@ -6,22 +6,17 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 16:45:54 by charles #+# #+# */ -/* Updated: 2020/04/14 17:59:57 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:43:14 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "Character.hpp" -Character::Character() : m_name(""), m_inventory_size(0) -{ -} +Character::Character() : m_name(""), m_inventory_size(0) {} -Character::Character(Character const& other) -{ - *this = other; -} +Character::Character(Character const& other) { *this = other; } -void Character::operator=(Character const& other) +Character& Character::operator=(Character const& other) { for (int i = 0; i < m_inventory_size; i++) delete m_inventory[i]; @@ -29,6 +24,7 @@ void Character::operator=(Character const& other) for (int i = 0; i < m_inventory_size; i++) m_inventory[i] = other.m_inventory[i]->clone(); m_name = other.m_name; + return *this; } Character::~Character() @@ -37,15 +33,9 @@ Character::~Character() delete m_inventory[i]; } -Character::Character(std::string const& name) - : m_name(name), m_inventory_size(0) -{ -} +Character::Character(std::string const& name) : m_name(name), m_inventory_size(0) {} -std::string const& Character::getName() const -{ - return m_name; -} +std::string const& Character::getName() const { return m_name; } void Character::equip(AMateria* m) { diff --git a/cpp04/ex03/Character.hpp b/cpp04/ex03/Character.hpp index c6ffc7b..6526ba2 100644 --- a/cpp04/ex03/Character.hpp +++ b/cpp04/ex03/Character.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 16:44:43 by charles #+# #+# */ -/* Updated: 2020/04/14 17:31:49 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:42:43 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ class Character : public ICharacter public: Character(); Character(Character const& other); - void operator=(Character const& other); + Character& operator=(Character const& other); virtual ~Character(); Character(std::string const& name); @@ -32,8 +32,8 @@ public: virtual void use(int idx, ICharacter& target); private: - AMateria* m_inventory[INVENTORY_MAX_SIZE]; - int m_inventory_size; + AMateria* m_inventory[INVENTORY_MAX_SIZE]; + int m_inventory_size; std::string m_name; }; diff --git a/cpp04/ex03/Cure.cpp b/cpp04/ex03/Cure.cpp index 1f3e0d5..e27ae26 100644 --- a/cpp04/ex03/Cure.cpp +++ b/cpp04/ex03/Cure.cpp @@ -6,34 +6,25 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 17:38:01 by charles #+# #+# */ -/* Updated: 2020/04/14 17:41:32 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:43:44 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "Cure.hpp" -Cure::Cure() : AMateria("cure") -{ -} +Cure::Cure() : AMateria("cure") {} -Cure::Cure(Cure const& other) -{ - *this = other; -} +Cure::Cure(Cure const& other) { *this = other; } -void Cure::operator=(Cure const& other) +Cure& Cure::operator=(Cure const& other) { AMateria::operator=(other); + return *this; } -Cure::~Cure() -{ -} +Cure::~Cure() {} -AMateria* Cure::clone() const -{ - return new Cure(*this); -} +AMateria* Cure::clone() const { return new Cure(*this); } void Cure::use(ICharacter& target) { diff --git a/cpp04/ex03/Cure.hpp b/cpp04/ex03/Cure.hpp index 4c7a6dd..ccc86d5 100644 --- a/cpp04/ex03/Cure.hpp +++ b/cpp04/ex03/Cure.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 17:37:11 by charles #+# #+# */ -/* Updated: 2020/04/14 17:42:52 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:43:24 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ class Cure : public AMateria public: Cure(); Cure(Cure const& other); - void operator=(Cure const& other); + Cure& operator=(Cure const& other); ~Cure(); virtual AMateria* clone() const; diff --git a/cpp04/ex03/ICharacter.hpp b/cpp04/ex03/ICharacter.hpp index ea56d47..bb84d7e 100644 --- a/cpp04/ex03/ICharacter.hpp +++ b/cpp04/ex03/ICharacter.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 16:40:25 by charles #+# #+# */ -/* Updated: 2020/04/14 17:55:14 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:42:12 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,8 @@ # include <string> # include "AMateria.hpp" +class IMateria; + class ICharacter { public: @@ -28,7 +30,7 @@ public: protected: ICharacter(); ICharacter(ICharacter const& other); - void operator=(ICharacter const& other); + ICharacter& operator=(ICharacter const& other); }; #endif diff --git a/cpp04/ex03/Ice.cpp b/cpp04/ex03/Ice.cpp index 976cb84..c663104 100644 --- a/cpp04/ex03/Ice.cpp +++ b/cpp04/ex03/Ice.cpp @@ -6,34 +6,25 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 16:32:27 by charles #+# #+# */ -/* Updated: 2020/04/14 17:36:26 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:44:48 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "Ice.hpp" -Ice::Ice() : AMateria("ice") -{ -} +Ice::Ice() : AMateria("ice") {} -Ice::Ice(Ice const& other) -{ - *this = other; -} +Ice::Ice(Ice const& other) { *this = other; } -void Ice::operator=(Ice const& other) +Ice& Ice::operator=(Ice const& other) { AMateria::operator=(other); + return *this; } -Ice::~Ice() -{ -} +Ice::~Ice() {} -AMateria* Ice::clone() const -{ - return new Ice(*this); -} +AMateria* Ice::clone() const { return new Ice(*this); } void Ice::use(ICharacter& target) { diff --git a/cpp04/ex03/Ice.hpp b/cpp04/ex03/Ice.hpp index 55011c0..8b670f6 100644 --- a/cpp04/ex03/Ice.hpp +++ b/cpp04/ex03/Ice.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 16:31:34 by charles #+# #+# */ -/* Updated: 2020/04/14 17:38:30 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:44:31 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ class Ice : public AMateria public: Ice(); Ice(Ice const& other); - void operator=(Ice const& other); + Ice& operator=(Ice const& other); ~Ice(); virtual AMateria* clone() const; diff --git a/cpp04/ex03/MateriaSource.cpp b/cpp04/ex03/MateriaSource.cpp index f5aaf60..087af3e 100644 --- a/cpp04/ex03/MateriaSource.cpp +++ b/cpp04/ex03/MateriaSource.cpp @@ -6,35 +6,25 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 17:19:10 by charles #+# #+# */ -/* Updated: 2020/04/15 10:05:47 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:45:23 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "MateriaSource.hpp" -MateriaSource::MateriaSource() -{ - -} +MateriaSource::MateriaSource() {} -MateriaSource::MateriaSource(MateriaSource const& other) -{ - *this = other; -} +MateriaSource::MateriaSource(MateriaSource const& other) { *this = other; } void MateriaSource::operator=(MateriaSource const& other) { - + return *this; } -MateriaSource::~MateriaSource() -{ - -} +MateriaSource::~MateriaSource() {} void MateriaSource::learnMateria(AMateria* materia) { - } AMateria* MateriaSource::createMateria(std::string const& type) diff --git a/cpp04/ex03/MateriaSource.hpp b/cpp04/ex03/MateriaSource.hpp index a8b4c0e..eb233eb 100644 --- a/cpp04/ex03/MateriaSource.hpp +++ b/cpp04/ex03/MateriaSource.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 17:17:40 by charles #+# #+# */ -/* Updated: 2020/04/14 17:33:50 by charles ### ########.fr */ +/* Updated: 2020/11/12 15:45:28 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,13 @@ # include "IMateriaSource.hpp" # define LEARNED_MAX_SIZE 4 + class MateriaSource : public IMateriaSource { public: MateriaSource(); MateriaSource(MateriaSource const& other); - void operator=(MateriaSource const& other); + MateriaSource& operator=(MateriaSource const& other); virtual ~MateriaSource(); virtual void learnMateria(AMateria* materia); |
