| 1 |
tim |
1501 |
#include "applications/simpleBuilder/LatticeFactory.hpp" |
| 2 |
|
|
#include "applications/simpleBuilder/BaseLattice.hpp" |
| 3 |
|
|
#include "applications/simpleBuilder/LatticeCreator.hpp" |
| 4 |
|
|
|
| 5 |
tim |
1891 |
namespace oopse { |
| 6 |
|
|
|
| 7 |
tim |
1501 |
LatticeFactory* LatticeFactory::instance = NULL; |
| 8 |
|
|
LatticeFactory::~LatticeFactory(){ |
| 9 |
tim |
1826 |
std::map<string, BaseLatticeCreator*>::iterator mapIter; |
| 10 |
tim |
1501 |
for (mapIter = creatorMap.begin(); mapIter == creatorMap.end(); ++mapIter) { |
| 11 |
|
|
delete mapIter->second; |
| 12 |
|
|
} |
| 13 |
|
|
} |
| 14 |
|
|
|
| 15 |
|
|
LatticeFactory* LatticeFactory::getInstance(){ |
| 16 |
|
|
if (instance == NULL) |
| 17 |
|
|
instance = new LatticeFactory(); |
| 18 |
|
|
|
| 19 |
|
|
return instance; |
| 20 |
|
|
} |
| 21 |
|
|
|
| 22 |
|
|
bool LatticeFactory::registerCreator( BaseLatticeCreator* latCreator ){ |
| 23 |
tim |
1829 |
std::string latticeType = latCreator->getType(); |
| 24 |
tim |
1826 |
std::map<string, BaseLatticeCreator*>::iterator mapIter; |
| 25 |
tim |
1501 |
|
| 26 |
|
|
mapIter = creatorMap.find(latticeType); |
| 27 |
|
|
|
| 28 |
|
|
if (mapIter == creatorMap.end()) { |
| 29 |
|
|
creatorMap[ latticeType ] = latCreator; |
| 30 |
|
|
return true; |
| 31 |
|
|
} |
| 32 |
|
|
else{ |
| 33 |
|
|
delete mapIter->second; |
| 34 |
|
|
mapIter->second = latCreator; |
| 35 |
|
|
return false; |
| 36 |
|
|
} |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
tim |
1832 |
BaseLattice* LatticeFactory::createLattice( const std::string& latticeType ){ |
| 40 |
tim |
1826 |
std::map<string, BaseLatticeCreator*>::iterator mapIter; |
| 41 |
tim |
1501 |
|
| 42 |
|
|
mapIter = creatorMap.find(latticeType); |
| 43 |
|
|
|
| 44 |
|
|
if (mapIter != creatorMap.end()) { |
| 45 |
|
|
return (mapIter->second)->createLattice(); |
| 46 |
|
|
} |
| 47 |
|
|
else |
| 48 |
|
|
return NULL; |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
tim |
1832 |
bool LatticeFactory::hasLatticeCreator( const std::string& latticeType ){ |
| 52 |
tim |
1826 |
std::map<string, BaseLatticeCreator*>::iterator mapIter; |
| 53 |
tim |
1501 |
|
| 54 |
|
|
mapIter = creatorMap.find(latticeType); |
| 55 |
|
|
|
| 56 |
|
|
if (mapIter != creatorMap.end()) |
| 57 |
|
|
return true; |
| 58 |
|
|
else |
| 59 |
|
|
return false; |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
tim |
1829 |
const std::string LatticeFactory::toString(){ |
| 63 |
|
|
std::string result; |
| 64 |
tim |
1826 |
std::map<string, BaseLatticeCreator*>::iterator mapIter; |
| 65 |
tim |
1501 |
|
| 66 |
|
|
result = "Avaliable lattice creators in LatticeFactory are:\n"; |
| 67 |
|
|
|
| 68 |
|
|
for(mapIter = creatorMap.begin(); mapIter != creatorMap.end(); ++mapIter){ |
| 69 |
|
|
result += mapIter->first + " "; |
| 70 |
|
|
} |
| 71 |
|
|
|
| 72 |
|
|
result += "\n"; |
| 73 |
|
|
|
| 74 |
|
|
return result; |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
tim |
1891 |
|
| 78 |
|
|
} |