ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/minimizers/MinimizerFactory.cpp
Revision: 1913
Committed: Mon Jan 10 22:04:20 2005 UTC (21 years, 4 months ago) by tim
File size: 1623 byte(s)
Log Message:
create a register module to register force fields, integrators and minimizers

File Contents

# User Rev Content
1 tim 1902
2     #include "minimizers/MinimizerFactory.hpp"
3     #include "minimizers/MinimizerCreator.hpp"
4    
5     namespace oopse {
6    
7     //initialize instance of MinimizerFactory
8     MinimizerFactory* MinimizerFactory::instance_ = NULL;
9    
10 tim 1913 MinimizerFactory::~MinimizerFactory() {
11     CreatorMapType::iterator i;
12     for (i = creatorMap_.begin(); i != creatorMap_.end(); ++i) {
13     delete i->second;
14     }
15     creatorMap_.clear();
16     }
17    
18 tim 1902 bool MinimizerFactory::registerMinimizer(MinimizerCreator* creator) {
19     return creatorMap_.insert(
20     CreatorMapType::value_type(creator->getIdent(), creator)).second;
21     }
22    
23     bool MinimizerFactory::unregisterMinimizer(const std::string& id) {
24     return creatorMap_.erase(id) == 1;
25     }
26    
27     Minimizer* MinimizerFactory::createMinimizer(const std::string& id, SimInfo* info) {
28     CreatorMapType::iterator i = creatorMap_.find(id);
29     if (i != creatorMap_.end()) {
30     //invoke functor to create object
31     return (i->second)->create(info);
32     } else {
33     return NULL;
34     }
35     }
36    
37     std::vector<std::string> MinimizerFactory::getIdents() {
38     IdentVectorType idents;
39     CreatorMapType::iterator i;
40    
41     for (i = creatorMap_.begin(); i != creatorMap_.end(); ++i) {
42     idents.push_back(i->first);
43     }
44    
45     return idents;
46     }
47    
48     std::ostream& operator <<(std::ostream& o, MinimizerFactory& factory) {
49     MinimizerFactory::IdentVectorType idents;
50     MinimizerFactory::IdentVectorIterator i;
51    
52     idents = factory.getIdents();
53    
54     o << "Avaliable type identifiers in this factory: " << std::endl;
55     for (i = idents.begin(); i != idents.end(); ++i) {
56     o << *i << std::endl;
57     }
58    
59     return o;
60     }
61    
62     }
63    

Properties

Name Value
svn:executable *