10#ifndef PROVIDER_MANAGER_H
11#define PROVIDER_MANAGER_H
20template <
typename TProv
iderType>
21class ProviderManager {
24 ProviderManager(ProviderManager
const &) =
delete;
26 ProviderManager &operator=(ProviderManager
const &) =
delete;
28 static void Register(
const TProviderType &instance)
32 auto it = std::ranges::lower_bound(providers, &instance,
typename TProviderType::ProviderSorter());
33 providers.insert(it, &instance);
36 static void Unregister(
const TProviderType &instance)
39 providers.erase(std::find(std::begin(providers), std::end(providers), &instance));
48 static std::vector<const TProviderType *> providers{};
69 inline std::string_view
GetName()
const {
return this->
name; }
84 bool operator()(
const T *a,
const T *b)
const
86 if (a->GetName() == b->GetName())
return a < b;
87 return a->GetName() < b->GetName();
92 const std::string_view
name;
120 bool operator()(
const T *a,
const T *b)
const
122 if (a->GetPriority() == b->GetPriority())
return a < b;
123 return a->GetPriority() < b->GetPriority();
virtual ~BaseProvider()=default
Ensure the destructor of the sub classes are called as well.
std::string_view GetName() const
Get the name of this provider.
constexpr BaseProvider(std::string_view name, std::string_view description)
Create the provider.
const std::string_view name
The name of the provider.
std::string_view GetDescription() const
Get a description of this provider.
const std::string_view description
A description of the provider.
const int priority
The priority of this provider.
constexpr PriorityBaseProvider(std::string_view name, std::string_view description, int priority)
Create the provider.
int GetPriority() const
Get the priority of this provider.
static std::vector< const TProviderType * > & GetProviders()
Get the currently known providers.
#define T
Climate temperate.
Sorter for PriorityBaseProvider.