AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
CreatorInterface.hpp
1#pragma once
2
3#include <memory>
4#include <string>
5
6#include <amdis/Output.hpp>
7
8namespace AMDiS
9{
22 template <class BaseClass>
24 {
25 public:
26 virtual ~CreatorInterface() = default;
27
32 virtual std::unique_ptr<BaseClass> create() = 0;
33 };
34
41 template <class BaseClass>
43 : public CreatorInterface<BaseClass>
44 {
45 public:
46
47 std::unique_ptr<BaseClass> create() final
48 {
49 error_exit("Should not be called. Call create(string) instead!");
50 return {};
51 };
52
58 virtual std::unique_ptr<BaseClass> createWithString(std::string) = 0;
59 };
60
61
63 template <class BaseClass>
65 {
66 auto result = dynamic_cast<CreatorInterfaceName<BaseClass>*>(ptr);
67 test_exit_dbg(result, "Can not cast CreatorInterface to CreatorInterfaceName!");
68 return result;
69 }
70
71} // end namespace AMDiS
Interface for creators with name.
Definition: CreatorInterface.hpp:44
virtual std::unique_ptr< BaseClass > createWithString(std::string)=0
Must be implemented by sub classes of CreatorInterfaceName. Creates a new instance of the sub class o...
std::unique_ptr< BaseClass > create() final
Must be implemented by sub classes of CreatorInterface. Creates a new instance of the sub class of Ba...
Definition: CreatorInterface.hpp:47
Interface for the implementation of the factory method pattern. The creation of an object of a sub cl...
Definition: CreatorInterface.hpp:24
virtual std::unique_ptr< BaseClass > create()=0
Must be implemented by sub classes of CreatorInterface. Creates a new instance of the sub class of Ba...