resolved one error and one segfault in xpp02

This commit is contained in:
lenovo
2022-12-12 22:34:11 +01:00
parent fecde1a8b1
commit 5b19461090
33 changed files with 567 additions and 326 deletions

View File

@@ -1,50 +1,61 @@
#ifndef SPELLBOOK_HPP
#ifndef SPELLBOOK_HPP
#define SPELLBOOK_HPP
# include <iostream>
# include <string>
# include "ASpell.hpp"
# include <map>
#include <iostream>
#include <string>
#include <map>
class SpellBook {
#include "ASpell.hpp"
class SpellBook
{
private:
SpellBook(SpellBook const & other);
SpellBook & operator=(SpellBook const & other);
std::map<std::string, ASpell *> arr;
std::map<std::string, ASpell*> arr;
public:
SpellBook() {};
~SpellBook() {
std::map<std::string, ASpell *>::iterator it_begin = this->arr.begin();
std::map<std::string, ASpell *>::iterator it_end = this->arr.end();
while (it_begin != it_end) {
delete it_begin->second;
++it_begin;
}
SpellBook()
{}
~SpellBook()
{
std::map<std::string, ASpell*>::iterator it;
for (it = arr.begin(); it != arr.end(); ++it)
delete it->second;
this->arr.clear();
};
}
void learnSpell(ASpell *aspell) {
void learnSpell(ASpell * aspell)
{
if (aspell)
arr.insert(std::pair<std::string, ASpell *>(
{
arr.insert(std::pair<std::string, ASpell*>
(
aspell->getName(),
aspell->clone()
));
};
void forgetSpell(std::string & name) {
std::map<std::string, ASpell *>::iterator it = arr.find(name);
if (it == arr.end())
return;
delete it->second;
arr.erase(name);
};
ASpell * createSpell(std::string & name) {
std::map<std::string, ASpell *>::iterator it = arr.find(name);
if (it == arr.end())
return NULL;
return arr[name];
};
}
}
void forgetSpell(std::string const & spell_name)
{
std::map<std::string, ASpell*>::iterator it;
it = arr.find(spell_name);
if (it != arr.end())
{
delete it->second;
arr.erase(spell_name);
}
}
ASpell * createSpell(std::string const & spell_name)
{
std::map<std::string, ASpell*>::iterator it;
it = arr.find(spell_name);
if (it != arr.end())
return arr[spell_name];
return NULL;
}
};
#endif