add Context::withCurrentTask
This commit is contained in:
committed by
Tomas Babej
parent
2ea6dd627e
commit
53127bf844
@@ -1328,6 +1328,12 @@ void Context::debugTiming (const std::string& details, const Timer& timer)
|
|||||||
debug (out.str ());
|
debug (out.str ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CurrentTask Context::withCurrentTask (const Task *task)
|
||||||
|
{
|
||||||
|
return CurrentTask(this, task);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// This capability is to answer the question of 'what did I just do to generate
|
// This capability is to answer the question of 'what did I just do to generate
|
||||||
// this output?'.
|
// this output?'.
|
||||||
@@ -1429,6 +1435,19 @@ void Context::debug (const std::string& input)
|
|||||||
debugMessages.push_back (input);
|
debugMessages.push_back (input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CurrentTask::CurrentTask (Context *context, const Task *task)
|
||||||
|
: context {context}, previous {context->currentTask}
|
||||||
|
{
|
||||||
|
context->currentTask = task;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CurrentTask::~CurrentTask ()
|
||||||
|
{
|
||||||
|
context->currentTask = previous;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// vim ts=2:sw=2
|
// vim ts=2:sw=2
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
#include <Timer.h>
|
#include <Timer.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
class CurrentTask;
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -73,6 +75,9 @@ public:
|
|||||||
void decomposeSortField (const std::string&, std::string&, bool&, bool&);
|
void decomposeSortField (const std::string&, std::string&, bool&, bool&);
|
||||||
void debugTiming (const std::string&, const Timer&);
|
void debugTiming (const std::string&, const Timer&);
|
||||||
|
|
||||||
|
CurrentTask withCurrentTask (const Task *);
|
||||||
|
friend class CurrentTask;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void staticInitialization ();
|
void staticInitialization ();
|
||||||
void createDefaultConfig ();
|
void createDefaultConfig ();
|
||||||
@@ -115,6 +120,24 @@ public:
|
|||||||
long time_sort_us {0};
|
long time_sort_us {0};
|
||||||
long time_render_us {0};
|
long time_render_us {0};
|
||||||
long time_hooks_us {0};
|
long time_hooks_us {0};
|
||||||
|
|
||||||
|
// the current task for DOM references, or NULL if there is no task
|
||||||
|
const Task * currentTask {NULL};
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CurrentTask resets Context::currentTask to NULL on destruction; this ensures
|
||||||
|
// that this context value is not a dangling pointer.
|
||||||
|
class CurrentTask {
|
||||||
|
~CurrentTask();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CurrentTask(Context *context, const Task *previous);
|
||||||
|
|
||||||
|
Context *context;
|
||||||
|
const Task *previous;
|
||||||
|
|
||||||
|
friend class Context;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user