ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/applications/simpleBuilder/LatticeFactory.cpp
Revision: 1903
Committed: Thu Jan 6 00:16:07 2005 UTC (19 years, 7 months ago) by tim
File size: 1954 byte(s)
Log Message:
simpleBuilder in progress

File Contents

# Content
1 #include "applications/simpleBuilder/LatticeFactory.hpp"
2 #include "applications/simpleBuilder/BaseLattice.hpp"
3 #include "applications/simpleBuilder/LatticeCreator.hpp"
4
5 namespace oopse {
6
7 LatticeFactory* LatticeFactory::instance = NULL;
8 LatticeFactory::~LatticeFactory(){
9 std::map<std::string, BaseLatticeCreator*>::iterator mapIter;
10 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 std::string latticeType = latCreator->getType();
24 std::map<std::string, BaseLatticeCreator*>::iterator mapIter;
25
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 BaseLattice* LatticeFactory::createLattice( const std::string& latticeType ){
40 std::map<std::string, BaseLatticeCreator*>::iterator mapIter;
41
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 bool LatticeFactory::hasLatticeCreator( const std::string& latticeType ){
52 std::map<std::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 std::string LatticeFactory::toString(){
63 std::string result;
64 std::map<std::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
77
78 }