one implementation of the exam
This commit is contained in:
50
cpp_module_02/SpellBook.hpp
Normal file
50
cpp_module_02/SpellBook.hpp
Normal 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
|
||||
Reference in New Issue
Block a user