From b8dd6e9ae73eb348fe786871cedfdb55610de156 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 30 Jul 2019 13:38:21 +0200 Subject: [PATCH] [libcalamaresui] Introduce a module-instance-key class - This replaces rather ad-hoc use of a QString as key. --- .../modulesystem/ModuleManager.h | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/libcalamaresui/modulesystem/ModuleManager.h b/src/libcalamaresui/modulesystem/ModuleManager.h index 8412e51d5..3a7535de4 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.h +++ b/src/libcalamaresui/modulesystem/ModuleManager.h @@ -32,6 +32,41 @@ namespace Calamares class Module; struct RequirementEntry; // from Requirement.h +/** @brief A module instance's key (`module@id`) + * + * A module instance is identified by both the module's name + * (a Calamares module, e.g. `users`) and an instance id. + * Usually, the instance id is the same as the module name + * and the whole module instance key is `users@users`, but + * it is possible to use the same module more than once + * and then you distinguish those module instances by their + * secondary id (e.g. `users@one`). + * + * This is supported by the *instances* configuration entry + * in `settings.conf`. + */ +class ModuleInstanceKey : protected QPair< QString, QString > +{ +public: + /// @brief Create an instance key from explicit module and id. + ModuleInstanceKey( const QString& module, const QString& id ) + : QPair( module, id ) + { + } + + /// @brief Create "usual" instances keys `module@module` + ModuleInstanceKey( const QString& module ) + : QPair( module, module ) + { + } + + QString module() const { return first; } + QString id() const { return second; } + + explicit operator QString() const { return module() + '@' + id(); } +}; + + /** * @brief The ModuleManager class is a singleton which manages Calamares modules. *