1 |
tim |
1758 |
/* |
2 |
|
|
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
|
|
* |
4 |
|
|
* Contact: oopse@oopse.org |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public License |
8 |
|
|
* as published by the Free Software Foundation; either version 2.1 |
9 |
|
|
* of the License, or (at your option) any later version. |
10 |
|
|
* All we ask is that proper credit is given for our work, which includes |
11 |
|
|
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
|
|
* of your source code files, and to any copyright notice that you may distribute |
13 |
|
|
* with programs based on this work. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU Lesser General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
21 |
|
|
* along with this program; if not, write to the Free Software |
22 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
|
|
* |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* @file IntegratorFactory.hpp |
28 |
|
|
* @author Teng Lin |
29 |
|
|
* @date 10/24/2004 |
30 |
|
|
* @version 1.0 |
31 |
|
|
*/ |
32 |
|
|
#ifndef INTEGRATORS_INTEGRATORFACTORY_HPP |
33 |
|
|
#define INTEGRATORS_INTEGRATORFACTORY_HPP |
34 |
|
|
#include <cassert> |
35 |
tim |
1819 |
#include <iostream> |
36 |
tim |
1758 |
#include <map> |
37 |
|
|
#include <string> |
38 |
|
|
#include <vector> |
39 |
|
|
|
40 |
|
|
namespace oopse { |
41 |
|
|
|
42 |
|
|
//forward declaration |
43 |
|
|
class Integrator; |
44 |
|
|
class SimInfo; |
45 |
|
|
/** |
46 |
|
|
* @class IntegratorFactory IntegratorFactory.hpp "integrators/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 |
49 |
|
|
*/ |
50 |
|
|
class IntegratorFactory { |
51 |
|
|
public: |
52 |
|
|
|
53 |
|
|
/** 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; |
57 |
|
|
typedef std::vector<std::string> IdentVectorType; |
58 |
|
|
typedef std::vector<std::string>::iterator IdentVectorIterator; |
59 |
|
|
|
60 |
|
|
/** |
61 |
|
|
* Returns an instance of Integrator factory |
62 |
|
|
* @return an instance of Integrator factory |
63 |
|
|
*/ |
64 |
tim |
1824 |
static IntegratorFactory* getInstance() { |
65 |
|
|
if (instance_ == NULL) { |
66 |
|
|
instance_ = new IntegratorFactory(); |
67 |
|
|
} |
68 |
|
|
return instance_; |
69 |
|
|
} |
70 |
tim |
1758 |
|
71 |
|
|
/** |
72 |
|
|
* Registers a creator with a type identifier |
73 |
|
|
* @return true if registration is succeed, otherwise return false |
74 |
|
|
* @id the identification of the concrete object |
75 |
|
|
* @creator the object responsible to create the concrete object |
76 |
|
|
*/ |
77 |
|
|
bool registerIntegrator(const std::string& id, IntegratorCreatorType creator); |
78 |
|
|
|
79 |
|
|
/** |
80 |
|
|
* Unregisters the creator for the given type identifier. If the type identifier |
81 |
|
|
* was previously registered, the function returns true. |
82 |
|
|
* @return truethe type identifier was previously registered and the creator is removed, |
83 |
|
|
* otherwise return false |
84 |
|
|
* @id the identification of the concrete object |
85 |
|
|
*/ |
86 |
|
|
bool unregisterIntegrator(const std::string& id); |
87 |
|
|
/** |
88 |
|
|
* Looks up the type identifier in the internal map. If it is found, it invokes the |
89 |
|
|
* corresponding creator for the type identifier and returns its result. |
90 |
|
|
* @return a pointer of the concrete object, return NULL if no creator is registed for |
91 |
|
|
* creating this concrete object |
92 |
|
|
* @param id the identification of the concrete object |
93 |
|
|
*/ |
94 |
tim |
1819 |
Integrator* createIntegrator(const std::string& id, SimInfo* info); |
95 |
tim |
1758 |
|
96 |
|
|
/** |
97 |
|
|
* Returns all of the registed type identifiers |
98 |
|
|
* @return all of the registed type identifiers |
99 |
|
|
*/ |
100 |
|
|
IdentVectorType getIdents(); |
101 |
|
|
|
102 |
|
|
private: |
103 |
|
|
static IntegratorFactory* instance_; |
104 |
|
|
CreatorMapType creatorMap_; |
105 |
|
|
}; |
106 |
|
|
|
107 |
|
|
/** write out all of the type identifiers to an output stream */ |
108 |
|
|
std::ostream& operator <<(std::ostream& o, IntegratorFactory& factory); |
109 |
|
|
|
110 |
|
|
}//namespace oopse |
111 |
|
|
#endif //INTEGRATORS_INTEGRATORFACTORY_HPP |