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