Refactor getDOM to use a pointer for the optional context

It's possible to call getDOM without a contextual task.  Previously,
this was done by referencing a "dummy" task which necessitated a way to
distinguish such dummy tasks.  This switches to using a pointer and
treating the NULL value as meaning there is no context.

Note that this cannot use `std::optional<&Task>`, as optional does not
support reference types.
This commit is contained in:
Dustin J. Mitchell
2021-11-18 02:48:14 +00:00
committed by Tomas Babej
parent 3af5ceadc1
commit 2812a8c77a
11 changed files with 76 additions and 82 deletions

View File

@@ -36,9 +36,8 @@
#include <shared.h>
////////////////////////////////////////////////////////////////////////////////
// Const iterator that can be derefenced into a Task by domSource.
static Task dummy;
Task& contextTask = dummy;
// Context for DOM evaluations
const Task* contextTask = NULL;
////////////////////////////////////////////////////////////////////////////////
bool domSource (const std::string& identifier, Variant& value)
@@ -79,7 +78,7 @@ void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output
for (auto& task : input)
{
// Set up context for any DOM references.
contextTask = task;
contextTask = &task;
Variant var;
eval.evaluateCompiledExpression (var);
@@ -131,7 +130,7 @@ void Filter::subset (std::vector <Task>& output)
for (auto& task : pending)
{
// Set up context for any DOM references.
contextTask = task;
contextTask = &task;
Variant var;
eval.evaluateCompiledExpression (var);
@@ -150,7 +149,7 @@ void Filter::subset (std::vector <Task>& output)
for (auto& task : completed)
{
// Set up context for any DOM references.
contextTask = task;
contextTask = &task;
Variant var;
eval.evaluateCompiledExpression (var);