From 071f4ef0122a8bfceeda9a10b41e85ad9a34a28d Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 23 Dec 2015 11:43:37 +0100 Subject: vastly simplify by getting rid of Module as a base class just a move slightly more towards functional --- akonadi2_cli/module.h | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'akonadi2_cli/module.h') diff --git a/akonadi2_cli/module.h b/akonadi2_cli/module.h index 4f426b8..d2745d0 100644 --- a/akonadi2_cli/module.h +++ b/akonadi2_cli/module.h @@ -29,33 +29,42 @@ class Module public: struct Syntax { + enum Interactivity { + NotInteractive = 0, + EventDriven + }; + Syntax(); - Syntax(const QString &keyword, std::function lambda = std::function(), const QString &helpText = QString(), bool eventDriven = false); + Syntax(const QString &keyword, + const QString &helpText = QString(), + std::function lambda = std::function(), + Interactivity interactivity = NotInteractive); + QString keyword; - std::function lambda; - QList children; QString help; - bool eventDriven; + Interactivity interactivity; + std::function lambda; + + QVector children; }; typedef std::pair Command; + typedef QVector SyntaxList; - static void addModule(const Module &module); - static QList modules(); - static Command match(const QStringList &commands); - static bool run(const QStringList &commands); - static void loadModules(); - static QVectornearestSyntax(const QStringList &words, const QString &fragment); + static Module *self(); - Module(); - Module::Syntax syntax() const; - void setSyntax(const Syntax &syntax); + SyntaxList syntax() const; + Command match(const QStringList &commands) const; + SyntaxList nearestSyntax(const QStringList &words, const QString &fragment) const; + + bool run(const QStringList &commands); private: + Module(); Command matches(const QStringList &commands) const; - Syntax m_syntax; - static QList s_modules; - static State s_state; + SyntaxList m_syntax; + State m_state; + static Module *s_module; }; -- cgit v1.2.3