ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/utils/sysbuilder/LatticeFactory.cpp
Revision: 1429
Committed: Wed Jul 28 20:29:49 2004 UTC (20 years, 1 month ago) by tim
File size: 1719 byte(s)
Log Message:
simpleBuilder in progress

File Contents

# User Rev Content
1 tim 1423 #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 tim 1429 LatticeFactory* LatticeFactory::getInstance(){
13 tim 1423 if (instance == NULL)
14     instance = new LatticeFactory();
15    
16     return instance;
17     }
18    
19 tim 1429 bool LatticeFactory::registerCreator( BaseLatticeCreator* latCreator ){
20     string latticeType = latCreator->getType();
21 tim 1423 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 tim 1429 BaseLattice* LatticeFactory::createLattice( const string& latticeType ){
37     map<string, BaseLatticeCreator*>::iterator mapIter;
38 tim 1423
39     mapIter = creatorMap.find(latticeType);
40    
41     if (mapIter != creatorMap.end()) {
42 tim 1429 return (mapIter->second)->createLattice();
43 tim 1423 }
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