1 |
tim |
1740 |
|
2 |
tim |
1758 |
#include "UseTheForce/ForceFieldFactory.hpp" |
3 |
tim |
1837 |
#include "UseTheForce/ForceFieldCreator.hpp" |
4 |
|
|
|
5 |
tim |
1740 |
namespace oopse { |
6 |
|
|
|
7 |
|
|
//initialize instance of ForceFieldFactory |
8 |
tim |
1783 |
ForceFieldFactory* ForceFieldFactory::instance_ = NULL; |
9 |
tim |
1740 |
|
10 |
tim |
1837 |
bool ForceFieldFactory::registerForceField(ForceFieldCreator* creator) { |
11 |
tim |
1840 |
std::cout << "register " << creator->getIdent() << std::endl; |
12 |
tim |
1740 |
return creatorMap_.insert( |
13 |
tim |
1837 |
CreatorMapType::value_type(creator->getIdent(), creator)).second; |
14 |
tim |
1740 |
} |
15 |
|
|
|
16 |
|
|
bool ForceFieldFactory::unregisterForceField(const std::string& id) { |
17 |
|
|
return creatorMap_.erase(id) == 1; |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
ForceField* ForceFieldFactory::createForceField(const std::string& id) { |
21 |
tim |
1783 |
CreatorMapType::iterator i = creatorMap_.find(id); |
22 |
tim |
1740 |
if (i != creatorMap_.end()) { |
23 |
|
|
//invoke functor to create object |
24 |
tim |
1837 |
return (i->second)->create(); |
25 |
tim |
1740 |
} else { |
26 |
|
|
return NULL; |
27 |
|
|
} |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
std::vector<std::string> ForceFieldFactory::getIdents() { |
31 |
|
|
IdentVectorType idents; |
32 |
tim |
1783 |
CreatorMapType::iterator i; |
33 |
tim |
1740 |
|
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, ForceFieldFactory& factory) { |
42 |
tim |
1783 |
ForceFieldFactory::IdentVectorType idents; |
43 |
|
|
ForceFieldFactory::IdentVectorIterator i; |
44 |
tim |
1740 |
|
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 |
|
|
} |