32 |
|
#ifndef INTEGRATORS_INTEGRATORFACTORY_HPP |
33 |
|
#define INTEGRATORS_INTEGRATORFACTORY_HPP |
34 |
|
#include <cassert> |
35 |
– |
#include <iostream> |
35 |
|
#include <map> |
36 |
|
#include <string> |
37 |
|
#include <vector> |
38 |
< |
|
38 |
> |
#include <iostream> |
39 |
|
namespace oopse { |
40 |
|
|
41 |
|
//forward declaration |
42 |
|
class Integrator; |
43 |
+ |
class IntegratorCreator; |
44 |
|
class SimInfo; |
45 |
|
/** |
46 |
< |
* @class IntegratorFactory IntegratorFactory.hpp "integrators/IntegratorFactory.hpp" |
46 |
> |
* @class IntegratorFactory IntegratorFactory.hpp "UseTheForce/IntegratorFactory.hpp" |
47 |
|
* Factory pattern and Singleton Pattern are used to define an interface for creating an Integrator. |
48 |
– |
* @note we can actually use GenericFactory |
48 |
|
*/ |
49 |
|
class IntegratorFactory { |
50 |
|
public: |
51 |
< |
|
52 |
< |
/** a function pointer which has not parameter and return a pointer pointer to a Integrator instance*/ |
54 |
< |
typedef Integrator* (*IntegratorCreatorType)(SimInfo*); |
55 |
< |
|
56 |
< |
typedef std::map<std::string, IntegratorCreatorType> CreatorMapType; |
51 |
> |
|
52 |
> |
typedef std::map<std::string, IntegratorCreator*> CreatorMapType; |
53 |
|
typedef std::vector<std::string> IdentVectorType; |
54 |
|
typedef std::vector<std::string>::iterator IdentVectorIterator; |
55 |
|
|
58 |
|
* @return an instance of Integrator factory |
59 |
|
*/ |
60 |
|
static IntegratorFactory* getInstance() { |
61 |
+ |
|
62 |
|
if (instance_ == NULL) { |
63 |
|
instance_ = new IntegratorFactory(); |
64 |
|
} |
65 |
|
return instance_; |
66 |
+ |
|
67 |
|
} |
68 |
|
|
69 |
|
/** |
72 |
|
* @id the identification of the concrete object |
73 |
|
* @creator the object responsible to create the concrete object |
74 |
|
*/ |
75 |
< |
bool registerIntegrator(const std::string& id, IntegratorCreatorType creator); |
75 |
> |
bool registerIntegrator(IntegratorCreator* creator); |
76 |
|
|
77 |
|
/** |
78 |
|
* Unregisters the creator for the given type identifier. If the type identifier |
107 |
|
|
108 |
|
}//namespace oopse |
109 |
|
#endif //INTEGRATORS_INTEGRATORFACTORY_HPP |
110 |
+ |
|