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