Albert
Loading...
Searching...
No Matches
extensionregistry.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 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
32
37
41 const std::map<QString,Extension*> &extensions() const;
42
46 template<typename T> std::map<QString, T*> extensions() const
47 {
48 std::map<QString, T*> results;
49 for (auto &[id, extension] : extensions_)
50 if (T *t = dynamic_cast<T*>(extension))
51 results.emplace(id, t);
52 return results;
53 }
54
58 template<typename T> T* extension(const QString &id) const
59 {
60 try {
61 return dynamic_cast<T*>(extensions_.at(id));
62 } catch (const std::out_of_range &) {
63 return nullptr;
64 }
65 }
66
67signals:
68
73
78
79private:
80
81 std::map<QString,Extension*> extensions_;
82};
83
84}
The common extension pool.
Definition extensionregistry.h:23
std::map< QString, T * > extensions() const
Get map of all extensions of type T.
Definition extensionregistry.h:46
bool registerExtension(Extension *)
Add extension to the registry.
T * extension(const QString &id) const
Get extension by id implicitly dynamic_cast'ed to type T.
Definition extensionregistry.h:58
void deregisterExtension(Extension *)
Remove extension from the registry.
const std::map< QString, Extension * > & extensions() const
Get map of all registered extensions.
void added(albert::Extension *)
Emitted when an extension has been registered.
void removed(albert::Extension *)
Emitted when an extension has been deregistered.
Abstract extension class.
Definition extension.h:19
Definition app.h:56