Hooks: C++11

This commit is contained in:
Paul Beckingham 2016-02-03 21:06:49 -05:00
parent c25f312477
commit cdd1c4681d
2 changed files with 25 additions and 38 deletions

View file

@ -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 <std::string> Hooks::list ()
std::vector <std::string> Hooks::list () const
{
return _scripts;
}
////////////////////////////////////////////////////////////////////////////////
std::vector <std::string> Hooks::scripts (const std::string& event)
std::vector <std::string> Hooks::scripts (const std::string& event) const
{
std::vector <std::string> 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 <std::string>& input) const
}
////////////////////////////////////////////////////////////////////////////////
std::vector <std::string>& Hooks::buildHookScriptArgs (std::vector <std::string>& args)
std::vector <std::string>& Hooks::buildHookScriptArgs (std::vector <std::string>& args) const
{
Variant v;
@ -530,7 +523,7 @@ std::vector <std::string>& Hooks::buildHookScriptArgs (std::vector <std::string>
int Hooks::callHookScript (
const std::string& script,
const std::vector <std::string>& input,
std::vector <std::string>& output)
std::vector <std::string>& 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 <std::string> 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);

View file

@ -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 <std::string> list ();
void onLaunch () const;
void onExit () const;
void onAdd (Task&) const;
void onModify (const Task&, Task&) const;
std::vector <std::string> list () const;
private:
std::vector <std::string> scripts (const std::string&);
std::vector <std::string> scripts (const std::string&) const;
void separateOutput (const std::vector <std::string>&, std::vector <std::string>&, std::vector <std::string>&) const;
bool isJSON (const std::string&) const;
void assertValidJSON (const std::vector <std::string>&) const;
void assertNTasks (const std::vector <std::string>&, unsigned int) const;
void assertSameTask (const std::vector <std::string>&, const Task&) const;
void assertFeedback (const std::vector <std::string>&) const;
std::vector <std::string>& buildHookScriptArgs (std::vector <std::string>&);
int callHookScript (const std::string&, const std::vector <std::string>&, std::vector <std::string>&);
std::vector <std::string>& buildHookScriptArgs (std::vector <std::string>&) const;
int callHookScript (const std::string&, const std::vector <std::string>&, std::vector <std::string>&) const;
private:
bool _enabled;
int _debug;
std::vector <std::string> _scripts;
bool _enabled {true};
int _debug {0};
std::vector <std::string> _scripts {};
};
#endif
////////////////////////////////////////////////////////////////////////////////