UI-Coordinates: implement a partial "sub path" order

This commit is contained in:
Fischlurch 2017-10-02 23:06:23 +02:00
parent 3d8d383ca8
commit d9555701ac
5 changed files with 41 additions and 5 deletions

View file

@ -187,6 +187,38 @@ namespace interact {
}
/**
* Check if this coordinate spec can be seen as an extension
* of the given parent coordinates and thus reaches further down
* towards specific UI elements in comparison to the parent path
* This constitutes a _partial order_, since some paths might
* just be totally unrelated to each other not comparable.
* @note we tolerate (but not demand) expansion/interpolation
* of the given parent, i.e. parent may be incomplete
* or contain `'*'` placeholders.
* @todo 10/2017 have to verify suitability of this definition
*/
bool
isExtendedBelow (UICoord const& parent) const
{
size_t subSiz = this->size(),
parSiz = parent.size(),
idx = 0;
if (parSiz >= subSiz)
return false;
while (idx < parSiz
and ( (*this)[idx]== parent[idx]
or Symbol::ANY == parent[idx]
or isnil (parent[idx])))
++idx;
ENSURE (idx < subSiz);
return idx == parSiz;
} // meaning: this goes further down
/* === String representation === */
@ -366,12 +398,12 @@ namespace interact {
friend bool
operator== (UICoord const& l, UICoord const& r)
{
return false;//static_cast<PathAry const&> (l) == static_cast<PathAry const&> (r);
return static_cast<PathAry const&> (l) == static_cast<PathAry const&> (r);
}
friend bool
operator< (UICoord const& l, UICoord const& r)
{
UNIMPLEMENTED ("equality of UI coordinates");
return l.isExtendedBelow (r);
}
friend bool operator> (UICoord const& l, UICoord const& r) { return (r < l); }

View file

@ -488,7 +488,6 @@ namespace lib {
normalise()
{
if (size() == 0) return;
static Symbol ANY("*");
const char* fill = Symbol::EMPTY;
Literal* end = elms_.end();
@ -498,7 +497,7 @@ namespace lib {
setContent (pos, fill);
else
if (fill==Symbol::EMPTY)
fill = ANY;
fill = Symbol::ANY;
if (tail_)
{
@ -510,7 +509,7 @@ namespace lib {
setContent (pos, fill);
else
if (fill==Symbol::EMPTY)
fill = ANY;
fill = Symbol::ANY;
}
size_t idx = size();

View file

@ -82,6 +82,7 @@ namespace lib {
/* == predefined marker Symbols == */
Symbol Symbol::ANY = "*";
Symbol Symbol::EMPTY = "";
Symbol Symbol::BOTTOM = "";
Symbol Symbol::FAILURE = "";

View file

@ -116,6 +116,7 @@ namespace lib {
: public Literal
{
public:
static Symbol ANY;
static Symbol EMPTY;
static Symbol BOTTOM;
static Symbol FAILURE;

View file

@ -380,6 +380,9 @@ namespace test {
CHECK (not (u1 < u1 ));
CHECK (not (u1 < u2 ));
CHECK (not (u11 < u2 ));
// expansion of jokers from parent path is tolerated
CHECK (u11 < u1.view("*").window(NULL));
}