3 #include <Patterns/NotCopyable.hpp>
17 template <
typename T,
template <
typename>
class Ptr>
21 typedef std::function<Ptr<T>()> CreateFunc;
24 ~ShowcaseFactoryT() {}
26 Ptr<T> create()
const;
28 void setSchema(
const Schema& schema);
38 struct hasSchemaInitialization
44 template <
typename C>
static one test(decltype(&C::setSchema));
45 template <
typename C>
static two test(...);
48 static const bool value =
sizeof(test<T>(0)) ==
sizeof(char);
51 template <
typename T,
template <
typename>
class Ptr,
bool = hasSchemaInitialization<T>::value>
52 struct ComponentInitializer
54 inline static Ptr<T> create(std::function<Ptr<T>()> createFunc,
62 template <
typename T,
template <
typename>
class Ptr>
63 struct ComponentInitializer<T, Ptr, true>
65 inline static Ptr<T> create(std::function<Ptr<T>()> createFunc,
68 auto c = createFunc();
76 template <
typename T,
template <
typename>
class Ptr>
84 template <
typename T,
template <
typename>
class Ptr>
90 template <
typename T,
template <
typename>
class Ptr>
91 Ptr<T> ShowcaseFactoryT<T, Ptr>::create()
const
94 return ComponentInitializer<T,Ptr>::create(m_create, m_schema);
100 using ShowcaseFactory = ShowcaseFactoryT<T, std::shared_ptr>;
101 template <
typename T>
102 using ShowcaseFactoryPtr = std::shared_ptr<ShowcaseFactory<T>>;
104 template <
typename T>
105 using FactoryMap = std::map<QString, ShowcaseFactoryPtr<T>>;
107 template <
typename T>
108 using FactoryKey =
typename FactoryMap<T>::iterator;