#ifndef WARLOCK_HPP # define WARLOCK_HPP # include # include # include # include "ASpell.hpp" # include "ATarget.hpp" class Warlock { private: Warlock(); Warlock(Warlock const & other); Warlock & operator=(Warlock const & other); std::string name; std::string title; std::map arr; public: Warlock(std::string const & name, std::string const & title) { this->name = name; this->title = title; std::cout << this->name << ": This looks like another boring day.\n"; }; ~Warlock() { std::cout << this->name << ": My job here is done!\n"; 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(); }; std::string const & getName() const { return (this->name); }; std::string const & getTitle() const { return (this->title); }; void setTitle(std::string const & title) { this->title = title; }; void introduce() const { std::cout << this->name << ": I am " << this->name << ", " << this->title << "!\n"; }; 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); }; void launchSpell(std::string name, ATarget const & target) { ASpell * spell = arr[name]; if (spell) spell->launch(target); }; }; #endif