66 lines
1.1 KiB
C++
66 lines
1.1 KiB
C++
#ifndef TARGETGENERATOR_HPP
|
|
#define TARGETGENERATOR_HPP
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <map>
|
|
|
|
#include "ATarget.hpp"
|
|
|
|
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;
|
|
for (it = arr.begin(); it != arr.end(); ++it)
|
|
delete it->second;
|
|
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 & type)
|
|
{
|
|
std::map<std::string, ATarget*>::iterator it;
|
|
it = arr.find(type);
|
|
if (it != arr.end())
|
|
{
|
|
delete it->second;
|
|
arr.erase(type);
|
|
}
|
|
}
|
|
|
|
ATarget * createTarget(std::string const & type)
|
|
{
|
|
std::map<std::string, ATarget*>::iterator it;
|
|
it = arr.find(type);
|
|
if (it != arr.end())
|
|
return arr[type]->clone();
|
|
return NULL;
|
|
}
|
|
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|