resolved one error and one segfault in xpp02

This commit is contained in:
lenovo
2022-12-12 22:34:11 +01:00
parent fecde1a8b1
commit 5b19461090
33 changed files with 567 additions and 326 deletions

View File

@@ -1,50 +1,65 @@
#ifndef TARGETGENERATOR_HPP
#ifndef TARGETGENERATOR_HPP
#define TARGETGENERATOR_HPP
# include <iostream>
# include <string>
# include "ATarget.hpp"
# include <map>
#include <iostream>
#include <string>
#include <map>
class TargetGenerator {
#include "ATarget.hpp"
class TargetGenerator
{
private:
TargetGenerator(TargetGenerator const & other);
TargetGenerator & operator=(TargetGenerator const & other);
std::map<std::string, ATarget *> arr;
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;
}
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) {
void learnTargetType(ATarget * atarget)
{
if (atarget)
arr.insert(std::pair<std::string, 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);
}
}
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(name);
};
ATarget * createTarget(std::string const & name) {
std::map<std::string, ATarget *>::iterator it = arr.find(name);
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[name];
return arr[type]->clone();
return NULL;
};
}
};
#endif