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 |
static LatticeFactory::LatticeFactory* getInstance(){ |
13 |
if (instance == NULL) |
14 |
instance = new LatticeFactory(); |
15 |
|
16 |
return instance; |
17 |
} |
18 |
|
19 |
bool LatticeFactory::registerCreator( const LatticeCreator* 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 |
string latticeType = latCreator->GetType(); |
38 |
map<string, BaseLatticeCreator*>::iterator mapIter; |
39 |
BaseLatticeCreator* creator; |
40 |
|
41 |
mapIter = creatorMap.find(latticeType); |
42 |
|
43 |
if (mapIter != creatorMap.end()) { |
44 |
creator = mapIter->second; |
45 |
return creator->createLattice(); |
46 |
} |
47 |
else |
48 |
return NULL; |
49 |
} |
50 |
|
51 |
bool LatticeFactory::hasLatticeCreator( const string& latticeType ){ |
52 |
map<string, BaseLatticeCreator*>::iterator mapIter; |
53 |
|
54 |
mapIter = creatorMap.find(latticeType); |
55 |
|
56 |
if (mapIter != creatorMap.end()) |
57 |
return true; |
58 |
else |
59 |
return false; |
60 |
} |
61 |
|
62 |
const string LatticeFactory::toString(){ |
63 |
string result; |
64 |
map<string, BaseLatticeCreator*>::iterator mapIter; |
65 |
|
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 |
|