navigation orientation indicator done (closes #918)
This commit is contained in:
parent
e0c5b18740
commit
d512267575
2 changed files with 27 additions and 16 deletions
|
|
@ -43,6 +43,8 @@
|
|||
#define HIERARCHY_ORIENTATION_INDICATOR_H
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
namespace lib {
|
||||
|
|
@ -52,39 +54,44 @@ namespace lib {
|
|||
|
||||
class OrientationIndicator
|
||||
{
|
||||
string nothing_;
|
||||
|
||||
size_t refLevel_;
|
||||
ptrdiff_t offset_;
|
||||
|
||||
public:
|
||||
OrientationIndicator()
|
||||
: nothing_ ()
|
||||
{
|
||||
}
|
||||
: refLevel_(0)
|
||||
, offset_(0)
|
||||
{ }
|
||||
|
||||
// using default copy/assignment
|
||||
|
||||
operator int() const
|
||||
operator ptrdiff_t() const
|
||||
{
|
||||
UNIMPLEMENTED ("tbw");
|
||||
return offset_;
|
||||
}
|
||||
|
||||
/* == X interface for == */
|
||||
|
||||
|
||||
|
||||
void
|
||||
markRefLevel (size_t newRefLevel)
|
||||
{
|
||||
UNIMPLEMENTED ("tbw");
|
||||
REQUIRE (newRefLevel < size_t(std::numeric_limits<ptrdiff_t>::max()) );
|
||||
|
||||
offset_ = newRefLevel - refLevel_;
|
||||
refLevel_ = newRefLevel;
|
||||
}
|
||||
|
||||
OrientationIndicator&
|
||||
operator+= (int adj)
|
||||
{
|
||||
UNIMPLEMENTED ("tbw");
|
||||
offset_ += adj;
|
||||
return *this;
|
||||
}
|
||||
|
||||
OrientationIndicator&
|
||||
operator-= (int adj)
|
||||
{
|
||||
this->operator +=(-adj);
|
||||
offset_ -= adj;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -326,6 +326,9 @@ namespace test {
|
|||
/***************************************************************************
|
||||
* @test describing and rebuilding a tree structure
|
||||
* while visiting the tree in depth first order.
|
||||
* To keep track of the level changes during that navigation,
|
||||
* we use an indicator to represent the relative level difference
|
||||
* compared to the previously visited node in the tree.
|
||||
*
|
||||
* @see HierarchyOrientationIndicator
|
||||
* @see DispatcherInterface_test
|
||||
|
|
@ -375,7 +378,7 @@ namespace test {
|
|||
CHECK (-1 == orient);
|
||||
|
||||
orient.markRefLevel (2);
|
||||
CHECK (+3 == orient);
|
||||
CHECK (+2 == orient);
|
||||
|
||||
orient.markRefLevel (2);
|
||||
CHECK ( 0 == orient);
|
||||
|
|
@ -392,15 +395,16 @@ namespace test {
|
|||
|
||||
orient += 200;
|
||||
orient -= 190;
|
||||
CHECK (+13 == orient);
|
||||
CHECK (+7 == orient);
|
||||
|
||||
OrientationIndicator o2(orient);
|
||||
o2.markRefLevel(0);
|
||||
CHECK (+3 == o2);
|
||||
CHECK (+13 == orient);
|
||||
CHECK (-2 == o2);
|
||||
CHECK (+7 == orient);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Register this test class... */
|
||||
LAUNCHER(HierarchyOrientationIndicator_test, "unit common");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue