diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 61cfccffc..ed097a919 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -45,13 +45,6 @@ extern Context context; -//////////////////////////////////////////////////////////////////////////////// -Hooks::Hooks () -: _enabled (true) -, _debug (0) -{ -} - //////////////////////////////////////////////////////////////////////////////// void Hooks::initialize () { @@ -111,7 +104,7 @@ bool Hooks::enable (bool value) // - all emitted non-JSON lines are considered feedback or error messages // depending on the status code. // -void Hooks::onLaunch () +void Hooks::onLaunch () const { if (! _enabled) return; @@ -164,7 +157,7 @@ void Hooks::onLaunch () // - all emitted non-JSON lines are considered feedback or error messages // depending on the status code. // -void Hooks::onExit () +void Hooks::onExit () const { if (! _enabled) return; @@ -226,7 +219,7 @@ void Hooks::onExit () // - all emitted non-JSON lines are considered feedback or error messages // depending on the status code. // -void Hooks::onAdd (Task& task) +void Hooks::onAdd (Task& task) const { if (! _enabled) return; @@ -292,7 +285,7 @@ void Hooks::onAdd (Task& task) // - all emitted non-JSON lines are considered feedback or error messages // depending on the status code. // -void Hooks::onModify (const Task& before, Task& after) +void Hooks::onModify (const Task& before, Task& after) const { if (! _enabled) return; @@ -346,16 +339,16 @@ void Hooks::onModify (const Task& before, Task& after) } //////////////////////////////////////////////////////////////////////////////// -std::vector Hooks::list () +std::vector Hooks::list () const { return _scripts; } //////////////////////////////////////////////////////////////////////////////// -std::vector Hooks::scripts (const std::string& event) +std::vector Hooks::scripts (const std::string& event) const { std::vector matching; - for (auto& i : _scripts) + for (const auto& i : _scripts) { if (i.find ("/" + event) != std::string::npos) { @@ -500,7 +493,7 @@ void Hooks::assertFeedback (const std::vector & input) const } //////////////////////////////////////////////////////////////////////////////// -std::vector & Hooks::buildHookScriptArgs (std::vector & args) +std::vector & Hooks::buildHookScriptArgs (std::vector & args) const { Variant v; @@ -530,7 +523,7 @@ std::vector & Hooks::buildHookScriptArgs (std::vector int Hooks::callHookScript ( const std::string& script, const std::vector & input, - std::vector & output) + std::vector & output) const { if (_debug >= 1) context.debug ("Hook: Calling " + script); @@ -538,12 +531,12 @@ int Hooks::callHookScript ( if (_debug >= 2) { context.debug ("Hook: input"); - for (auto& i : input) + for (const auto& i : input) context.debug (" " + i); } std::string inputStr; - for (auto& i : input) + for (const auto& i : input) inputStr += i + "\n"; std::vector args; @@ -551,7 +544,7 @@ int Hooks::callHookScript ( if (_debug >= 2) { context.debug ("Hooks: args"); - for (auto& arg: args) + for (const auto& arg: args) context.debug (" " + arg); } @@ -573,7 +566,7 @@ int Hooks::callHookScript ( if (_debug >= 2) { context.debug ("Hook: output"); - for (auto& i : output) + for (const auto& i : output) if (i != "") context.debug (" " + i); diff --git a/src/Hooks.h b/src/Hooks.h index 969e89272..2c76e292e 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -34,36 +34,30 @@ class Hooks { public: - Hooks (); - Hooks (const Hooks&) = delete; - Hooks& operator= (const Hooks&) = delete; - + Hooks () = default; void initialize (); bool enable (bool); - - void onLaunch (); - void onExit (); - void onAdd (Task&); - void onModify (const Task&, Task&); - - std::vector list (); + void onLaunch () const; + void onExit () const; + void onAdd (Task&) const; + void onModify (const Task&, Task&) const; + std::vector list () const; private: - std::vector scripts (const std::string&); + std::vector scripts (const std::string&) const; void separateOutput (const std::vector &, std::vector &, std::vector &) const; bool isJSON (const std::string&) const; void assertValidJSON (const std::vector &) const; void assertNTasks (const std::vector &, unsigned int) const; void assertSameTask (const std::vector &, const Task&) const; void assertFeedback (const std::vector &) const; - std::vector & buildHookScriptArgs (std::vector &); - int callHookScript (const std::string&, const std::vector &, std::vector &); + std::vector & buildHookScriptArgs (std::vector &) const; + int callHookScript (const std::string&, const std::vector &, std::vector &) const; private: - bool _enabled; - int _debug; - std::vector _scripts; + bool _enabled {true}; + int _debug {0}; + std::vector _scripts {}; }; #endif -////////////////////////////////////////////////////////////////////////////////