ComponentFactory.hpp
1 #pragma once
2 #include <score/plugins/Interface.hpp>
3 #include <score/plugins/InterfaceList.hpp>
4 
5 #define SCORE_CONCRETE_COMPONENT_FACTORY(AbstractFactory, ConcreteFactory)
6 
7 #define SCORE_ABSTRACT_COMPONENT_FACTORY(Type) \
8 public: \
9  static Q_DECL_RELAXED_CONSTEXPR score::InterfaceKey static_interfaceKey() noexcept \
10  { \
11  return static_cast<score::InterfaceKey>(Type::static_key().impl()); \
12  } \
13  \
14  score::InterfaceKey interfaceKey() const noexcept final override \
15  { \
16  return static_interfaceKey(); \
17  } \
18  \
19 private:
20 
21 namespace score
22 {
23 struct DocumentContext;
24 template <
25  typename Model_T, // e.g. ProcessModel - maybe ProcessEntity ?
26  typename System_T, // e.g. LocalTree::DocumentPlugin
27  typename ComponentFactory_T> // e.g. ProcessComponent
29 {
30 public:
31  using base_model_type = Model_T;
32  using system_type = System_T;
33  using factory_type = ComponentFactory_T;
34 
36 
38  virtual ConcreteKey concreteKey() const noexcept = 0;
39 
40  virtual bool matches(const base_model_type&) const = 0;
41 };
42 
43 template <
44  typename Model_T, // e.g. ProcessModel - maybe ProcessEntity ?
45  typename System_T, // e.g. LocalTree::DocumentPlugin
46  typename Factory_T> // e.g. ProcessComponentFactory
48 {
49 public:
50  template <typename... Args>
51  Factory_T* factory(Args&&... args) const
52  {
53  for(auto& factory : *this)
54  {
55  if(factory.matches(std::forward<Args>(args)...))
56  {
57  return &factory;
58  }
59  }
60 
61  return nullptr;
62  }
63 };
64 
65 template <
66  typename Model_T, // e.g. ProcessModel - maybe ProcessEntity ?
67  typename System_T, // e.g. LocalTree::DocumentPlugin
68  typename Factory_T, // e.g. ProcessComponentFactory
69  typename DefaultFactory_T>
71 {
72 public:
73  template <typename... Args>
74  Factory_T& factory(Args&&... args) const
75  {
76  for(auto& factory : *this)
77  {
78  if(factory.matches(std::forward<Args>(args)...))
79  {
80  return factory;
81  }
82  }
83 
84  return m_default;
85  }
86 
87 private:
88  mutable DefaultFactory_T m_default;
89 };
90 }
Definition: UuidKey.hpp:343
Definition: ComponentFactory.hpp:71
Definition: ComponentFactory.hpp:29
virtual ConcreteKey concreteKey() const noexcept=0
Identifies an implementation of an interface uniquely.
Definition: ComponentFactory.hpp:48
Base class for plug-in interfaces.
Definition: Interface.hpp:52
InterfaceList Default implementation of InterfaceListBase.
Definition: InterfaceList.hpp:80
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: ObjectMatches.hpp:6