Skip to content
Snippets Groups Projects
Commit 8e70c875 authored by Carsten Gräser's avatar Carsten Gräser
Browse files

Reintroduce function syntax

Now that Type is the actual return type, it cannot be abstract
such that we can use the function signature notation again which
also allows to have a default value for the Key type.
parent f449b735
No related branches found
No related tags found
2 merge requests!212Fix link to build system doc,!3Feature/parameterizedobjectfactory
......@@ -30,10 +30,14 @@ namespace Dune {
* @tparam Signature Signature of the "virtual" constructor call in the form for Interface(Args...). For default constructors onecan omit the ()-brackets.
* @tparam KeyT The type of the objects that are used as keys in the lookup [DEFAULT: std::string].
*/
template<typename Signature,
typename KeyT = std::string>
class ParameterizedObjectFactory;
template<typename TypeT,
typename KeyT,
typename... Args>
class ParameterizedObjectFactory
class ParameterizedObjectFactory<TypeT(Args...), KeyT>
{
public:
......
......@@ -57,7 +57,7 @@ struct AImp : public InterfaceA
int main()
{
// int as parameter
Dune::ParameterizedObjectFactory<std::unique_ptr<InterfaceA>, std::string, int> FactoryA;
Dune::ParameterizedObjectFactory<std::unique_ptr<InterfaceA>(int)> FactoryA;
FactoryA.define<Ai>("Ai");
FactoryA.define<Bi>("Bi");
FactoryA.define<Ax>("Ax", [](int i) { return Dune::Std::make_unique<Ax>(); });
......@@ -66,7 +66,7 @@ int main()
CheckInstance(FactoryA, Ax, 1);
// default constructor
Dune::ParameterizedObjectFactory<std::shared_ptr<InterfaceA>, std::string> FactoryAd;
Dune::ParameterizedObjectFactory<std::shared_ptr<InterfaceA>()> FactoryAd;
FactoryAd.define<Ax>("Ax");
FactoryAd.define<Bx>("Bx");
FactoryAd.define<Ai>("Ai", []() { return std::make_shared<Ai>(0); });
......@@ -83,14 +83,14 @@ int main()
std::cout << FactoryAd.create("AImp3")->info() << std::endl;
// explicitly request the default constructor
Dune::ParameterizedObjectFactory<std::unique_ptr<InterfaceA>, std::string> FactoryAx;
Dune::ParameterizedObjectFactory<std::unique_ptr<InterfaceA>()> FactoryAx;
FactoryAx.define<Ax>("Ax");
FactoryAx.define<Bx>("Bx");
CheckInstance(FactoryAx, Ax);
CheckInstance(FactoryAx, Bx);
// multiple parameters
Dune::ParameterizedObjectFactory<std::unique_ptr<InterfaceB>, std::string, int, std::string> FactoryB;
Dune::ParameterizedObjectFactory<std::unique_ptr<InterfaceB>(int, std::string)> FactoryB;
FactoryB.define<Ais>("Ais");
FactoryB.define<Bis>("Bis");
CheckInstance(FactoryB, Ais, 0, std::to_string(2));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment