DOM: Stubbed DOM tree

This commit is contained in:
Paul Beckingham 2017-04-28 12:42:19 -04:00
parent 4afe912f84
commit ee3e8c46dc
2 changed files with 86 additions and 0 deletions

View file

@ -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 <std::string> DOM::decomposeReference (const std::string& reference) const
{
return split (reference, '.');
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -28,10 +28,27 @@
#define INCLUDED_DOM
#include <string>
#include <Tree.h>
#include <Variant.h>
#include <Task.h>
// 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 <std::string> decomposeReference (const std::string&) const;
};
#endif