From ee3e8c46dcf226705f1b8c3eb5df49c405337d66 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 28 Apr 2017 12:42:19 -0400 Subject: [PATCH] DOM: Stubbed DOM tree --- src/DOM.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DOM.h | 17 +++++++++++++ 2 files changed, 86 insertions(+) diff --git a/src/DOM.cpp b/src/DOM.cpp index 8fd8c7274..06f770e53 100644 --- a/src/DOM.cpp +++ b/src/DOM.cpp @@ -435,3 +435,72 @@ bool getDOM (const std::string& name, const Task& task, Variant& value) } //////////////////////////////////////////////////////////////////////////////// +// DOM Class +// +// References are paths into a tree structure. For example: +// +// 1.due.month.number +// 1.due.day.number +// +// Are represented internally as: +// +// 1 +// +- due +// +- day +// | +- number +// +- month +// +- number +// +// The tree is augmented by other elements: +// +// 1 +// +- due +// | +- day +// | | +- number +// | +- month +// | +- number +// +- system +// +- os +// +// Each node in the tree has a name ("due", "system", "day"), and each node may +// have a data source attached to it. +// +// The DOM class is independent of the project, in that it knows nothing about +// the internal data or program structure. It knows only that certain DOM path +// elements have handlers which will provide the data. +// +// The DOM class is therefore responsible for maintaining a tree of named nodes +// with associated proividers. When a reference value is requested, the DOM +// class will decompose the reference path, and navigate the tree to the lowest +// level provider, and call it. +// +// This makes the DOM class a reusible object. + +//////////////////////////////////////////////////////////////////////////////// +bool DOM::valid (const std::string& reference) const +{ + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +Variant DOM::get (const std::string& reference) const +{ + Variant v (""); + + // Find the provider. + // TODO Start at the root of the tree. + for (const auto& element : decomposeReference (reference)) + { + // TODO If tree contains a named node 'element', capture the provider, if any. + } + + return v; +} + +//////////////////////////////////////////////////////////////////////////////// +std::vector DOM::decomposeReference (const std::string& reference) const +{ + return split (reference, '.'); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/DOM.h b/src/DOM.h index f1cdef7a6..2f6d0704e 100644 --- a/src/DOM.h +++ b/src/DOM.h @@ -28,10 +28,27 @@ #define INCLUDED_DOM #include +#include #include #include +// 2017-04-22 Deprecated. bool getDOM (const std::string&, Variant&); bool getDOM (const std::string&, const Task&, Variant&); +// DOM Tree +class DOM; + +class DOM +{ +public: + void addSource (const std::string&, bool (*)(const std::string&, Variant&)); + bool valid (const std::string&) const; + Variant get (const Task&, const std::string&) const; + Variant get (const std::string&) const; + +private: + std::vector decomposeReference (const std::string&) const; +}; + #endif