1 |
|
|
2 |
|
#include "UseTheForce/ForceFieldFactory.hpp" |
3 |
+ |
#include "UseTheForce/ForceFieldCreator.hpp" |
4 |
+ |
|
5 |
|
namespace oopse { |
6 |
|
|
7 |
|
//initialize instance of ForceFieldFactory |
8 |
< |
ForceFieldFactory::instance_ = NULL; |
8 |
> |
ForceFieldFactory* ForceFieldFactory::instance_ = NULL; |
9 |
|
|
10 |
< |
bool ForceFieldFactory::registerForceField(const std::string& id, ForceFieldCreatorType creator) { |
10 |
> |
bool ForceFieldFactory::registerForceField(ForceFieldCreator* creator) { |
11 |
> |
//std::cout << "register " << creator->getIdent() << std::endl; |
12 |
|
return creatorMap_.insert( |
13 |
< |
CreatorMapType::value_type(id, creator)).second; |
13 |
> |
CreatorMapType::value_type(creator->getIdent(), creator)).second; |
14 |
|
} |
15 |
|
|
16 |
|
bool ForceFieldFactory::unregisterForceField(const std::string& id) { |
18 |
|
} |
19 |
|
|
20 |
|
ForceField* ForceFieldFactory::createForceField(const std::string& id) { |
21 |
< |
typename CreatorMapType::iterator i = creatorMap_.find(id); |
21 |
> |
CreatorMapType::iterator i = creatorMap_.find(id); |
22 |
|
if (i != creatorMap_.end()) { |
23 |
|
//invoke functor to create object |
24 |
< |
return (i->second)(); |
24 |
> |
return (i->second)->create(); |
25 |
|
} else { |
26 |
|
return NULL; |
27 |
|
} |
29 |
|
|
30 |
|
std::vector<std::string> ForceFieldFactory::getIdents() { |
31 |
|
IdentVectorType idents; |
32 |
< |
typename CreatorMapType::iterator i; |
32 |
> |
CreatorMapType::iterator i; |
33 |
|
|
34 |
|
for (i = creatorMap_.begin(); i != creatorMap_.end(); ++i) { |
35 |
|
idents.push_back(i->first); |
39 |
|
} |
40 |
|
|
41 |
|
std::ostream& operator <<(std::ostream& o, ForceFieldFactory& factory) { |
42 |
< |
typename ForceFieldFactory::IdentVectorType idents; |
43 |
< |
typename ForceFieldFactory::IdentVectorIterator i; |
42 |
> |
ForceFieldFactory::IdentVectorType idents; |
43 |
> |
ForceFieldFactory::IdentVectorIterator i; |
44 |
|
|
45 |
|
idents = factory.getIdents(); |
46 |
|
|