#ifndef SPELLBOOK_HPP #define SPELLBOOK_HPP # include # include # include "ASpell.hpp" # include class SpellBook { private: SpellBook(SpellBook const & other); SpellBook & operator=(SpellBook const & other); std::map arr; public: SpellBook() {}; ~SpellBook() { std::map::iterator it_begin = this->arr.begin(); std::map::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( aspell->getName(), aspell->clone() )); }; void forgetSpell(std::string & name) { std::map::iterator it = arr.find(name); if (it == arr.end()) return; delete it->second; arr.erase(name); }; ASpell * createSpell(std::string & name) { std::map::iterator it = arr.find(name); if (it == arr.end()) return NULL; return arr[name]; }; }; #endif