20 #ifndef ESSENTIA_ALGORITHMFACTORY_CPP
21 #define ESSENTIA_ALGORITHMFACTORY_CPP
25 template <
typename BaseAlgorithm>
28 throw EssentiaException(
"You haven't initialized the factory yet... Please do it now!");
33 template <
typename BaseAlgorithm>
35 std::vector<std::string> result;
37 for (
typename CreatorMap::const_iterator it = m.begin(); it != m.end(); ++it) {
38 result.push_back(it->first);
43 template <
typename BaseAlgorithm>
45 E_DEBUG(
EFactory, BaseAlgorithm::processingMode <<
": Creating algorithm: " <<
id);
47 typename CreatorMap::const_iterator it = _map.find(
id);
48 if (it == _map.end()) {
49 std::ostringstream msg;
50 msg <<
"Identifier '" <<
id <<
"' not found in registry...\n";
51 msg <<
"Available algorithms:";
52 for (it=_map.begin(); it!=_map.end(); ++it) {
53 msg <<
' ' << it->first;
59 BaseAlgorithm* algo = it->second.create();
68 algo->declareParameters();
77 E_DEBUG(
EFactory, BaseAlgorithm::processingMode <<
": Configuring " <<
id <<
" with default parameters");
84 std::ostringstream msg;
85 msg <<
"ERROR: Algorithm " <<
id <<
" could not be configured using default values.\n"
86 <<
" If it doesn't make sense for an algorithm to be configured with\n"
87 <<
" default values, then it should still be able to be instantiated, and\n"
88 <<
" it is your responsibility to keep track of the fact that it should\n"
89 <<
" currently be impossible to call it (for example, by checking if the state\n"
90 <<
" is valid upon entering the process() method).\n\n"
95 E_DEBUG(
EFactory, BaseAlgorithm::processingMode <<
": Creating " <<
id <<
" ok!");
101 #define CREATE_I template <typename BaseAlgorithm> BaseAlgorithm* EssentiaFactory<BaseAlgorithm>::create_i(const std::string& id
102 #define P(n) , const std::string& name##n, const Parameter& value##n
103 #define AP(n) params.add(name##n, value##n);
105 #define CREATE_I_BEG ) const { \
106 E_DEBUG(EFactory, BaseAlgorithm::processingMode << ": Creating algorithm: " << id); \
107 typename CreatorMap::const_iterator it = _map.find(id); \
108 if (it == _map.end()) { \
109 std::ostringstream msg; \
110 msg << "Identifier '" << id << "' not found in registry...\n"; \
111 msg << "Available algorithms:"; \
112 for (it=_map.begin(); it!=_map.end(); ++it) { \
113 msg << ' ' << it->first; \
115 throw EssentiaException(msg); \
118 BaseAlgorithm* algo = it->second.create(); \
121 algo->declareParameters(); \
124 #define CREATE_I_END \
125 algo->setParameters(params); \
126 E_DEBUG(EFactory, BaseAlgorithm::processingMode << ": Configuring " << id << " with default parameters"); \
128 E_DEBUG(EFactory, BaseAlgorithm::processingMode << ": Creating " << id << " ok!"); \
#define CREATE_I_END
Definition: algorithmfactory_impl.h:124
#define CREATE_I
Definition: algorithmfactory_impl.h:101
#define AP(n)
Definition: algorithmfactory_impl.h:103
#define P(n)
Definition: algorithmfactory_impl.h:102
#define CREATE_I_BEG
Definition: algorithmfactory_impl.h:105
virtual const char * what() const
Definition: types.h:100
Definition: algorithmfactory.h:58
BaseAlgorithm * create_i(const std::string &id) const
Definition: algorithmfactory_impl.h:44
static EssentiaFactory & instance()
Definition: algorithmfactory_impl.h:26
static std::vector< std::string > keys()
Definition: algorithmfactory_impl.h:34
#define E_DEBUG(module, msg)
Definition: debugging.h:157
#define E_DEBUG_OUTDENT
Definition: debugging.h:149
#define E_DEBUG_INDENT
Definition: debugging.h:148
Definition: algorithm.h:28
@ EFactory
Definition: debugging.h:44