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