1 |
tim |
1758 |
|
2 |
|
|
#include "integrators/IntegratorFactory" |
3 |
|
|
namespace oopse { |
4 |
|
|
|
5 |
|
|
//initialize instance of IntegratorFactory |
6 |
|
|
IntegratorFactory::instance_ = NULL; |
7 |
|
|
|
8 |
|
|
bool IntegratorFactory::registerIntegrator(const std::string& id, IntegratorCreatorType creator) { |
9 |
|
|
return creatorMap_.insert( |
10 |
|
|
CreatorMapType::value_type(id, creator)).second; |
11 |
|
|
} |
12 |
|
|
|
13 |
|
|
bool IntegratorFactory::unregisterIntegrator(const std::string& id) { |
14 |
|
|
return creatorMap_.erase(id) == 1; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
Integrator* IntegratorFactory::createIntegrator(const std::string& id, SimInfo* info) { |
18 |
|
|
typename CreatorMapType::iterator i = creatorMap_.find(id); |
19 |
|
|
if (i != creatorMap_.end()) { |
20 |
|
|
//invoke functor to create object |
21 |
|
|
return (i->second)(info); |
22 |
|
|
} else { |
23 |
|
|
return NULL; |
24 |
|
|
} |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
std::vector<std::string> IntegratorFactory::getIdents() { |
28 |
|
|
IdentVectorType idents; |
29 |
|
|
typename CreatorMapType::iterator i; |
30 |
|
|
|
31 |
|
|
for (i = creatorMap_.begin(); i != creatorMap_.end(); ++i) { |
32 |
|
|
idents.push_back(i->first); |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
return idents; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
std::ostream& operator <<(std::ostream& o, IntegratorFactory& factory) { |
39 |
|
|
typename IntegratorFactory::IdentVectorType idents; |
40 |
|
|
typename IntegratorFactory::IdentVectorIterator i; |
41 |
|
|
|
42 |
|
|
idents = factory.getIdents(); |
43 |
|
|
|
44 |
|
|
o << "Avaliable type identifiers in this factory: " << std::endl; |
45 |
|
|
for (i = idents.begin(); i != idents.end(); ++i) { |
46 |
|
|
o << *i << std::endl; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
return o; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
} |
53 |
|
|
|