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:
Paul Beckingham
2016-02-03 21:54:37 -05:00
parent ec4e6af00d
commit 820cc4b2e5
7 changed files with 14 additions and 21 deletions

View File

@@ -71,7 +71,6 @@ Context::Context ()
, data_dir ("~/.task") , data_dir ("~/.task")
, config () , config ()
, tdb2 () , tdb2 ()
, dom ()
, determine_color_use (true) , determine_color_use (true)
, use_color (true) , use_color (true)
, run_gc (true) , run_gc (true)

View File

@@ -33,7 +33,6 @@
#include <Task.h> #include <Task.h>
#include <TDB2.h> #include <TDB2.h>
#include <Hooks.h> #include <Hooks.h>
#include <DOM.h>
#include <FS.h> #include <FS.h>
#include <CLI2.h> #include <CLI2.h>
#include <Timer.h> #include <Timer.h>
@@ -85,7 +84,6 @@ public:
TDB2 tdb2; TDB2 tdb2;
Hooks hooks; Hooks hooks;
DOM dom;
bool determine_color_use; bool determine_color_use;
bool use_color; bool use_color;

View File

@@ -52,7 +52,7 @@ extern Context context;
// system.version // system.version
// system.os // 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. // Special case, blank refs cause problems.
if (name == "") 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 // This code emphasizes speed, hence 'id' and 'urgecny' being evaluated first
// as special cases. // 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. // Special case, blank refs cause problems.
if (name == "") if (name == "")
@@ -331,7 +331,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
int count = 0; int count = 0;
// Count off the 'a'th annotation. // Count off the 'a'th annotation.
for (auto& i : annos) for (const auto& i : annos)
{ {
if (++count == a) if (++count == a)
{ {
@@ -360,7 +360,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
int count = 0; int count = 0;
// Count off the 'a'th annotation. // Count off the 'a'th annotation.
for (auto& i : annos) for (const auto& i : annos)
{ {
if (++count == a) 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. // Delegate to the context-free version of DOM::get.
return this->get (name, value); return getDOM (name, value);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -30,16 +30,8 @@
#include <string> #include <string>
#include <Variant.h> #include <Variant.h>
#include <Task.h> #include <Task.h>
#include <time.h>
class DOM bool getDOM (const std::string&, Variant&);
{ bool getDOM (const std::string&, const Task&, Variant&);
public:
bool get (const std::string&, Variant&);
bool get (const std::string&, const Task&, Variant&);
private:
};
#endif #endif
////////////////////////////////////////////////////////////////////////////////

View File

@@ -28,6 +28,7 @@
#include <Filter.h> #include <Filter.h>
#include <algorithm> #include <algorithm>
#include <Context.h> #include <Context.h>
#include <DOM.h>
#include <Eval.h> #include <Eval.h>
#include <Variant.h> #include <Variant.h>
#include <Dates.h> #include <Dates.h>
@@ -45,7 +46,7 @@ Task& contextTask = dummy;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool domSource (const std::string& identifier, Variant& value) bool domSource (const std::string& identifier, Variant& value)
{ {
if (context.dom.get (identifier, contextTask, value)) if (getDOM (identifier, contextTask, value))
{ {
value.source (identifier); value.source (identifier);
return true; return true;

View File

@@ -37,6 +37,8 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/types.h> #include <sys/types.h>
#include <Context.h> #include <Context.h>
#include <Variant.h>
#include <DOM.h>
#include <JSON.h> #include <JSON.h>
#include <Timer.h> #include <Timer.h>
#include <text.h> #include <text.h>
@@ -501,7 +503,7 @@ std::vector <std::string>& Hooks::buildHookScriptArgs (std::vector <std::string>
args.push_back ("api:2"); args.push_back ("api:2");
// Command line Taskwarrior was called with. // Command line Taskwarrior was called with.
context.dom.get ("context.args", v); getDOM ("context.args", v);
args.push_back ("args:" + std::string (v)); args.push_back ("args:" + std::string (v));
// Command to be executed. // Command to be executed.

View File

@@ -28,6 +28,7 @@
#include <CmdGet.h> #include <CmdGet.h>
#include <Variant.h> #include <Variant.h>
#include <Context.h> #include <Context.h>
#include <DOM.h>
#include <main.h> #include <main.h>
#include <text.h> #include <text.h>
#include <i18n.h> #include <i18n.h>
@@ -67,7 +68,7 @@ int CmdGet::execute (std::string& output)
{ {
Task t; Task t;
Variant result; Variant result;
if (context.dom.get (arg.attribute ("raw"), t, result)) if (getDOM (arg.attribute ("raw"), t, result))
results.push_back ((std::string) result); results.push_back ((std::string) result);
else else
results.push_back (""); results.push_back ("");