ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/utils/sysbuilder/LatticeFactory.cpp
Revision: 1432
Committed: Thu Jul 29 03:31:50 2004 UTC (20 years, 1 month ago) by tim
File size: 1768 byte(s)
Log Message:
simpleBuilder is built but Makefile is broken

File Contents

# User Rev Content
1 tim 1423 #include "LatticeFactory.hpp"
2     #include "BaseLattice.hpp"
3     #include "LatticeCreator.hpp"
4    
5 tim 1432 LatticeFactory* LatticeFactory::instance = NULL;
6 tim 1423 LatticeFactory::~LatticeFactory(){
7     map<string, BaseLatticeCreator*>::iterator mapIter;
8     for (mapIter = creatorMap.begin(); mapIter == creatorMap.end(); ++mapIter) {
9     delete mapIter->second;
10     }
11     }
12    
13 tim 1429 LatticeFactory* LatticeFactory::getInstance(){
14 tim 1423 if (instance == NULL)
15     instance = new LatticeFactory();
16    
17     return instance;
18     }
19    
20 tim 1429 bool LatticeFactory::registerCreator( BaseLatticeCreator* latCreator ){
21     string latticeType = latCreator->getType();
22 tim 1423 map<string, BaseLatticeCreator*>::iterator mapIter;
23    
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 tim 1429 BaseLattice* LatticeFactory::createLattice( const string& latticeType ){
38     map<string, BaseLatticeCreator*>::iterator mapIter;
39 tim 1423
40     mapIter = creatorMap.find(latticeType);
41    
42     if (mapIter != creatorMap.end()) {
43 tim 1429 return (mapIter->second)->createLattice();
44 tim 1423 }
45     else
46     return NULL;
47     }
48    
49     bool LatticeFactory::hasLatticeCreator( const string& latticeType ){
50     map<string, BaseLatticeCreator*>::iterator mapIter;
51    
52     mapIter = creatorMap.find(latticeType);
53    
54     if (mapIter != creatorMap.end())
55     return true;
56     else
57     return false;
58     }
59    
60     const string LatticeFactory::toString(){
61     string result;
62     map<string, BaseLatticeCreator*>::iterator mapIter;
63    
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