mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 09:53:08 +02:00
DOM: Demoted from class to functions
- The DOM object contains no members, and only two (effectively) const methods. Demoting DOM to function calls reduces coupling with Context.
This commit is contained in:
parent
ec4e6af00d
commit
820cc4b2e5
7 changed files with 14 additions and 21 deletions
|
@ -71,7 +71,6 @@ Context::Context ()
|
|||
, data_dir ("~/.task")
|
||||
, config ()
|
||||
, tdb2 ()
|
||||
, dom ()
|
||||
, determine_color_use (true)
|
||||
, use_color (true)
|
||||
, run_gc (true)
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <Task.h>
|
||||
#include <TDB2.h>
|
||||
#include <Hooks.h>
|
||||
#include <DOM.h>
|
||||
#include <FS.h>
|
||||
#include <CLI2.h>
|
||||
#include <Timer.h>
|
||||
|
@ -85,7 +84,6 @@ public:
|
|||
|
||||
TDB2 tdb2;
|
||||
Hooks hooks;
|
||||
DOM dom;
|
||||
|
||||
bool determine_color_use;
|
||||
bool use_color;
|
||||
|
|
10
src/DOM.cpp
10
src/DOM.cpp
|
@ -52,7 +52,7 @@ extern Context context;
|
|||
// system.version
|
||||
// system.os
|
||||
//
|
||||
bool DOM::get (const std::string& name, Variant& value)
|
||||
bool getDOM (const std::string& name, Variant& value)
|
||||
{
|
||||
// Special case, blank refs cause problems.
|
||||
if (name == "")
|
||||
|
@ -194,7 +194,7 @@ bool DOM::get (const std::string& name, Variant& value)
|
|||
//
|
||||
// This code emphasizes speed, hence 'id' and 'urgecny' being evaluated first
|
||||
// as special cases.
|
||||
bool DOM::get (const std::string& name, const Task& task, Variant& value)
|
||||
bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||
{
|
||||
// Special case, blank refs cause problems.
|
||||
if (name == "")
|
||||
|
@ -331,7 +331,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
|
|||
int count = 0;
|
||||
|
||||
// Count off the 'a'th annotation.
|
||||
for (auto& i : annos)
|
||||
for (const auto& i : annos)
|
||||
{
|
||||
if (++count == a)
|
||||
{
|
||||
|
@ -360,7 +360,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
|
|||
int count = 0;
|
||||
|
||||
// Count off the 'a'th annotation.
|
||||
for (auto& i : annos)
|
||||
for (const auto& i : annos)
|
||||
{
|
||||
if (++count == a)
|
||||
{
|
||||
|
@ -388,7 +388,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
|
|||
}
|
||||
|
||||
// Delegate to the context-free version of DOM::get.
|
||||
return this->get (name, value);
|
||||
return getDOM (name, value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
12
src/DOM.h
12
src/DOM.h
|
@ -30,16 +30,8 @@
|
|||
#include <string>
|
||||
#include <Variant.h>
|
||||
#include <Task.h>
|
||||
#include <time.h>
|
||||
|
||||
class DOM
|
||||
{
|
||||
public:
|
||||
bool get (const std::string&, Variant&);
|
||||
bool get (const std::string&, const Task&, Variant&);
|
||||
|
||||
private:
|
||||
};
|
||||
bool getDOM (const std::string&, Variant&);
|
||||
bool getDOM (const std::string&, const Task&, Variant&);
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <Filter.h>
|
||||
#include <algorithm>
|
||||
#include <Context.h>
|
||||
#include <DOM.h>
|
||||
#include <Eval.h>
|
||||
#include <Variant.h>
|
||||
#include <Dates.h>
|
||||
|
@ -45,7 +46,7 @@ Task& contextTask = dummy;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool domSource (const std::string& identifier, Variant& value)
|
||||
{
|
||||
if (context.dom.get (identifier, contextTask, value))
|
||||
if (getDOM (identifier, contextTask, value))
|
||||
{
|
||||
value.source (identifier);
|
||||
return true;
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <Context.h>
|
||||
#include <Variant.h>
|
||||
#include <DOM.h>
|
||||
#include <JSON.h>
|
||||
#include <Timer.h>
|
||||
#include <text.h>
|
||||
|
@ -501,7 +503,7 @@ std::vector <std::string>& Hooks::buildHookScriptArgs (std::vector <std::string>
|
|||
args.push_back ("api:2");
|
||||
|
||||
// Command line Taskwarrior was called with.
|
||||
context.dom.get ("context.args", v);
|
||||
getDOM ("context.args", v);
|
||||
args.push_back ("args:" + std::string (v));
|
||||
|
||||
// Command to be executed.
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <CmdGet.h>
|
||||
#include <Variant.h>
|
||||
#include <Context.h>
|
||||
#include <DOM.h>
|
||||
#include <main.h>
|
||||
#include <text.h>
|
||||
#include <i18n.h>
|
||||
|
@ -67,7 +68,7 @@ int CmdGet::execute (std::string& output)
|
|||
{
|
||||
Task t;
|
||||
Variant result;
|
||||
if (context.dom.get (arg.attribute ("raw"), t, result))
|
||||
if (getDOM (arg.attribute ("raw"), t, result))
|
||||
results.push_back ((std::string) result);
|
||||
else
|
||||
results.push_back ("");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue