1#ifndef SCORE_INTERFACELIST_2018_10_22
2#define SCORE_INTERFACELIST_2018_10_22
4#include <score/plugins/Interface.hpp>
5#include <score/tools/Debug.hpp>
6#include <score/tools/std/IndirectContainer.hpp>
7#include <score/tools/std/Pointer.hpp>
9#include <ossia/detail/hash_map.hpp>
11#include <nano_signal_slot.hpp>
12#include <score_lib_base_export.h>
32 static constexpr bool factory_list_tag =
true;
55 virtual
void optimize() noexcept = 0;
58SCORE_LIB_BASE_EXPORT
void
66 void insert_base(std::unique_ptr<score::InterfaceBase> e,
score::uuid_t k);
70 auto reserve(std::size_t v) {
return map.reserve(v); }
71 auto size()
const noexcept {
return map.size(); }
72 auto empty()
const noexcept {
return map.empty(); }
74 void optimize()
noexcept final override;
75 ossia::hash_map<score::uuid_t, std::unique_ptr<score::InterfaceBase>> map;
95template <
typename FactoryType>
99 using factory_type = FactoryType;
100 using key_type =
typename FactoryType::ConcreteKey;
107 return FactoryType::static_interfaceKey();
112 return FactoryType::static_interfaceKey();
115 void insert(std::unique_ptr<score::InterfaceBase> e)
final override
117 if(
auto result =
dynamic_cast<factory_type*
>(e.get()))
119 return insert_base(std::move(e), result->concreteKey().impl());
123 SCORE_SOFT_ASSERT(
"Invalid interface detected");
128 FactoryType*
get(
const key_type& k)
const noexcept
130 auto it = this->map.find(k.impl());
131 return (it != this->map.end()) ?
static_cast<FactoryType*
>(it->second.get())
135 auto begin() noexcept
137 return make_indirect_cast_map_iterator<factory_type>(map.begin());
141 return make_indirect_cast_map_iterator<factory_type>(map.end());
143 auto begin() const noexcept
145 return make_indirect_cast_map_iterator<factory_type>(map.begin());
147 auto end() const noexcept
149 return make_indirect_cast_map_iterator<factory_type>(map.end());
152 auto cbegin() const noexcept
154 return make_indirect_cast_map_iterator<factory_type>(map.cbegin());
156 auto cend() const noexcept
158 return make_indirect_cast_map_iterator<factory_type>(map.cend());
162 InterfaceList(
const InterfaceList&) =
delete;
163 InterfaceList(InterfaceList&&) =
delete;
164 InterfaceList& operator=(
const InterfaceList&) =
delete;
165 InterfaceList& operator=(InterfaceList&&) =
delete;
186 template <
typename Fun,
typename... Args>
187 requires std::is_invocable_v<
188 Fun,
typename score::InterfaceList<T>::factory_type&, Args...>
189 auto make(Fun f, Args&&... args)
const noexcept
191 using val_t =
decltype(*this->begin());
192 for(
const val_t& elt : *
this)
194 if(elt.matches(std::forward<Args>(args)...))
196 return (elt.*f)(std::forward<Args>(args)...);
199 return decltype((std::declval<val_t>().*f)(std::forward<Args>(args)...)){};
Definition UuidKey.hpp:345
Definition IndirectContainer.hpp:169
Base class for plug-in interfaces.
Definition Interface.hpp:52
InterfaceListBase Interface to access factories.
Definition InterfaceList.hpp:30
virtual score::InterfaceKey interfaceKey() const noexcept=0
A key that uniquely identifies this family of factories.
InterfaceList Default implementation of InterfaceListBase.
Definition InterfaceList.hpp:97
void insert(std::unique_ptr< score::InterfaceBase > e) final override
insert Register a new factory.
Definition InterfaceList.hpp:115
constexpr score::InterfaceKey interfaceKey() const noexcept final override
A key that uniquely identifies this family of factories.
Definition InterfaceList.hpp:110
FactoryType * get(const key_type &k) const noexcept
Get a particular factory from its ConcreteKey.
Definition InterfaceList.hpp:128
Definition InterfaceList.hpp:62
Utility class for making a factory interface list.
Definition InterfaceList.hpp:173
auto make(Fun f, Args &&... args) const noexcept
Apply a function on the correct factory according to a set of parameter.
Definition InterfaceList.hpp:189
Base toolkit upon which the software is built.
Definition Application.cpp:97
Definition UuidKey.hpp:24