AMDiS  0.3
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 
8 namespace 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
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
void error_exit(std::string const &str, Args &&... args)
print a message and exit
Definition: Output.hpp:142
void test_exit_dbg(bool condition, Args &&... args)
call assert_msg, in debug mode only
Definition: Output.hpp:205
Interface for creators with name.
Definition: CreatorInterface.hpp:42
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
CreatorInterfaceName< BaseClass > * named(CreatorInterface< BaseClass > *ptr)
cast a ptr of CreatorInterface to CreatorInterfaceName
Definition: CreatorInterface.hpp:64
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...
Interface for the implementation of the factory method pattern. The creation of an object of a sub cl...
Definition: CreatorInterface.hpp:23