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