one implementation of the exam
This commit is contained in:
50
cpp_module_02/TargetGenerator.hpp
Normal file
50
cpp_module_02/TargetGenerator.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef TARGETGENERATOR_HPP
|
||||
#define TARGETGENERATOR_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
# include "ATarget.hpp"
|
||||
# include <map>
|
||||
|
||||
class TargetGenerator {
|
||||
private:
|
||||
TargetGenerator(TargetGenerator const & other);
|
||||
TargetGenerator & operator=(TargetGenerator const & other);
|
||||
|
||||
std::map<std::string, ATarget *> arr;
|
||||
|
||||
public:
|
||||
TargetGenerator() {
|
||||
};
|
||||
~TargetGenerator() {
|
||||
std::map<std::string, ATarget *>::iterator it_begin = this->arr.begin();
|
||||
std::map<std::string, ATarget *>::iterator it_end = this->arr.end();
|
||||
while (it_begin != it_end) {
|
||||
delete it_begin->second;
|
||||
++it_begin;
|
||||
}
|
||||
this->arr.clear();
|
||||
};
|
||||
|
||||
void learnTargetType(ATarget * atarget) {
|
||||
if (atarget)
|
||||
arr.insert(std::pair<std::string, ATarget *>(
|
||||
atarget->getType(),
|
||||
atarget->clone()
|
||||
));
|
||||
};
|
||||
void forgetTargetType(std::string const & name) {
|
||||
std::map<std::string, ATarget *>::iterator it = arr.find(name);
|
||||
if (it != arr.end())
|
||||
delete it->second;
|
||||
arr.erase(name);
|
||||
};
|
||||
ATarget * createTarget(std::string const & name) {
|
||||
std::map<std::string, ATarget *>::iterator it = arr.find(name);
|
||||
if (it != arr.end())
|
||||
return arr[name];
|
||||
return NULL;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user