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")
, config ()
, tdb2 ()
, dom ()
, determine_color_use (true)
, use_color (true)
, run_gc (true)

View file

@ -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;

View file

@ -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);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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
////////////////////////////////////////////////////////////////////////////////

View file

@ -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;

View file

@ -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.

View file

@ -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 ("");