6#include <phosphorlayoutapi_export.h>
19#include <unordered_map>
94 bool set(std::type_identity_t<T*> service)
109 static_assert(std::is_class_v<T>,
"FactoryContext::set<T>: T must be a class type");
110 static_assert(!std::is_pointer_v<T>,
111 "FactoryContext::set<T>: pass the interface type, not a pointer type "
112 "(write set<IFoo>(p), not set<IFoo*>(p))");
113 const auto key = std::type_index(
typeid(T));
114 const bool duplicate = m_services.find(key) != m_services.end();
115 Q_ASSERT_X(!duplicate,
"FactoryContext::set",
116 "service key already registered; duplicate set<T>() is a programmer error");
118 qWarning(
"FactoryContext::set: ignoring duplicate registration for type '%s' (first registration kept)",
122 m_services[key] =
static_cast<void*
>(service);
133 static_assert(std::is_class_v<T>,
"FactoryContext::get<T>: T must be a class type");
134 static_assert(!std::is_pointer_v<T>,
135 "FactoryContext::get<T>: pass the interface type, not a pointer type "
136 "(write get<IFoo>(), not get<IFoo*>())");
137 const auto it = m_services.find(std::type_index(
typeid(T)));
138 return it == m_services.end() ? nullptr :
static_cast<T*
>(it->second);
142 std::unordered_map<std::type_index, void*> m_services;
233 std::function<std::unique_ptr<ILayoutSourceFactory>(
const FactoryContext&)> builder);
249template<
typename Registry,
typename Factory>
252 auto* registry = ctx.
get<Registry>();
256 return std::make_unique<Factory>(registry);
Service registry passed to a layout-source-provider builder so it can pull whatever registries / depe...
Definition LayoutSourceProviderRegistry.h:66
bool set(std::type_identity_t< T * > service)
Register a service of type T.
Definition LayoutSourceProviderRegistry.h:94
T * get() const
Look up a previously-registered service.
Definition LayoutSourceProviderRegistry.h:131
Static-init self-registration helper for provider libraries.
Definition LayoutSourceProviderRegistry.h:230
LayoutSourceProviderRegistrar(QString name, int priority, std::function< std::unique_ptr< ILayoutSourceFactory >(const FactoryContext &)> builder)
Definition AlgorithmMetadata.h:10
std::unique_ptr< ILayoutSourceFactory > makeProviderFactory(const FactoryContext &ctx)
Standard provider builder: pull Registry from ctx, return a new Factory bound to it,...
Definition LayoutSourceProviderRegistry.h:250
PHOSPHORLAYOUTAPI_EXPORT QMutex & pendingLayoutSourceProvidersMutex()
Mutex protecting pendingLayoutSourceProviders().
PHOSPHORLAYOUTAPI_EXPORT QList< PendingLayoutSourceProvider > & pendingLayoutSourceProviders()
Process-global list of pending provider registrations.
One pending layout-source-provider registration.
Definition LayoutSourceProviderRegistry.h:153
std::function< std::unique_ptr< ILayoutSourceFactory >(const FactoryContext &)> builder
Definition LayoutSourceProviderRegistry.h:156
QString name
Definition LayoutSourceProviderRegistry.h:154