20 #ifndef GAIA_LAYOUTAWAREFACTORY_H 21 #define GAIA_LAYOUTAWAREFACTORY_H 25 #include "pointlayout.h" 35 template <
typename IdentifierType,
36 typename AbstractProduct,
38 typename ArgumentType >
42 typedef AbstractProduct* (*ProductCreator)(
const LayoutType&,
const ArgumentType&);
43 typedef QMap<IdentifierType, ProductCreator> CreatorMap;
54 static AbstractProduct* create(
const IdentifierType&
id,
55 const LayoutType& layout,
56 const ArgumentType& arg = ArgumentType()) {
58 AbstractProduct* result;
60 result = instance().create_i(
id, layout, arg);
62 catch (FixedLengthException& e) {
64 e.msg() = e.msg().arg(
id);
71 if (result->validParams.size() == 1 && result->validParams[0] ==
"NO_PARAMS_CHECK") {
76 foreach (
const QString& p, arg.keys()) {
77 if (!result->validParams.contains(p)) {
79 msg <<
"Could not create algorithm " <<
id <<
" because parameter " << p
80 <<
" is not a valid parameter.\n" 81 <<
"Valid parameters are: " << result->validParams.join(
", ");
90 AbstractProduct* create_i(
const IdentifierType&
id,
91 const LayoutType& layout,
92 const ArgumentType& arg)
const {
94 IdentifierType lid =
id.toLower();
95 typename CreatorMap::const_iterator it = _map.constBegin();
96 while (it != _map.constEnd() && it.key().toLower() != lid) {
99 if (it == _map.end()) {
101 msg <<
"Identifier '" <<
id <<
"' not found in registry...\n";
102 msg <<
"Available keys: " << keys().join(
" ");
106 return (*it)(layout, arg);
109 static QStringList keys() {
return instance()._map.keys(); }
111 template <
typename ConcreteProduct>
115 LayoutAwareFactory::instance()._map.insert(
id, &create);
118 static AbstractProduct* create(
const LayoutType& layout,
const ArgumentType& arg) {
119 return new ConcreteProduct(layout, arg);
127 #endif // GAIA_LAYOUTAWAREFACTORY_H Definition: layoutawarefactory.h:112
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
A tuned implementation of a factory.
Definition: layoutawarefactory.h:39
Exception class that can take up to 3 arguments of any type, which will be serialized into a QString ...
Definition: gaiaexception.h:46