Albert
Loading...
Searching...
No Matches
extensionregistry.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Manuel Schneider
2// SPDX-License-Identifier: MIT
3
4#pragma once
5#include <QObject>
6#include <albert/export.h>
7#include <albert/extension.h>
8#include <map>
9
10namespace albert
11{
12
22class ALBERT_EXPORT ExtensionRegistry : public QObject
23{
24 Q_OBJECT
25
26public:
27
30
33
35 const std::map<QString,Extension*> &extensions();
36
38 template<typename T> std::map<QString, T*> extensions()
39 {
40 std::map<QString, T*> results;
41 for (auto &[id, extension] : extensions_)
42 if (T *t = dynamic_cast<T*>(extension))
43 results.emplace(id, t);
44 return results;
45 }
46
48 template<typename T> T* extension(const QString &id)
49 {
50 try {
51 return dynamic_cast<T*>(extensions_.at(id));
52 } catch (const std::out_of_range &) {
53 return nullptr;
54 }
55 }
56
57signals:
58
61
64
65private:
66
67 std::map<QString,Extension*> extensions_;
68};
69
70}
The common extension pool.
Definition extensionregistry.h:23
void removed(Extension *)
Emitted when an extension has been deregistered.
bool registerExtension(Extension *)
Add extension to the registry.
void deregisterExtension(Extension *)
Remove extension from the registry.
void added(Extension *)
Emitted when an extension has been registered.
T * extension(const QString &id)
Get extension by id implicitly dynamic_cast'ed to type T.
Definition extensionregistry.h:48
const std::map< QString, Extension * > & extensions()
Get map of all registered extensions.
std::map< QString, T * > extensions()
Get map of all extensions of type T.
Definition extensionregistry.h:38
Abstract extension class.
Definition extension.h:19
Definition action.h:10