aboutsummaryrefslogtreecommitdiff
path: root/cpp04/ex03/MateriaSource.cpp
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-11-13 14:43:17 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-11-13 14:43:17 +0100
commit4c30e98f4a4018a25d3a9f3ee790d589be803cb0 (patch)
tree655a4bd52a7a6633a32782eab935fb01a47040e9 /cpp04/ex03/MateriaSource.cpp
parentb8e39b947890e74d82530e25ad9d02668aae1f0c (diff)
downloadpiscine_cpp-4c30e98f4a4018a25d3a9f3ee790d589be803cb0.tar.gz
piscine_cpp-4c30e98f4a4018a25d3a9f3ee790d589be803cb0.tar.bz2
piscine_cpp-4c30e98f4a4018a25d3a9f3ee790d589be803cb0.zip
Added main for cpp04/ex01 and cpp04/ex02, Fixed cpp04/03 MateriaSource
Diffstat (limited to 'cpp04/ex03/MateriaSource.cpp')
-rw-r--r--cpp04/ex03/MateriaSource.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/cpp04/ex03/MateriaSource.cpp b/cpp04/ex03/MateriaSource.cpp
index 087af3e..774506b 100644
--- a/cpp04/ex03/MateriaSource.cpp
+++ b/cpp04/ex03/MateriaSource.cpp
@@ -6,28 +6,46 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 17:19:10 by charles #+# #+# */
-/* Updated: 2020/11/12 15:45:23 by cacharle ### ########.fr */
+/* Updated: 2020/11/13 14:40:54 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "MateriaSource.hpp"
-MateriaSource::MateriaSource() {}
+MateriaSource::MateriaSource() : m_learned_size(0) {}
-MateriaSource::MateriaSource(MateriaSource const& other) { *this = other; }
+MateriaSource::MateriaSource(MateriaSource const& other)
+ : m_learned_size(0) { *this = other; }
-void MateriaSource::operator=(MateriaSource const& other)
+MateriaSource& MateriaSource::operator=(MateriaSource const& other)
{
+ destroyLearned();
+ m_learned_size = other.m_learned_size;
+ for (int i = 0; i < m_learned_size; i++)
+ m_learned[i] = other.m_learned[i]->clone();
return *this;
}
-MateriaSource::~MateriaSource() {}
+MateriaSource::~MateriaSource() { destroyLearned(); }
void MateriaSource::learnMateria(AMateria* materia)
{
+ if (m_learned_size >= 4)
+ return;
+ m_learned[m_learned_size] = materia->clone();
+ m_learned_size++;
}
AMateria* MateriaSource::createMateria(std::string const& type)
{
+ for (int i = 0; i < m_learned_size; i++)
+ if (m_learned[i]->getType() == type)
+ return m_learned[i]->clone();
return NULL;
}
+
+void MateriaSource::destroyLearned()
+{
+ for (int i = 0; i < m_learned_size; i++)
+ delete m_learned[i];
+}