one implementation of the exam

This commit is contained in:
hugogogo
2022-12-01 15:47:19 +01:00
parent 16dcd06da6
commit c91d23a5d4
43 changed files with 925 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
#ifndef SPELLBOOK_HPP
#define SPELLBOOK_HPP
# include <iostream>
# include <string>
# include "ASpell.hpp"
# include <map>
class SpellBook {
private:
SpellBook(SpellBook const & other);
SpellBook & operator=(SpellBook const & other);
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;
}
this->arr.clear();
};
void learnSpell(ASpell *aspell) {
if (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];
};
};
#endif