diff --git a/src/lib/hierarchy-orientation-indicator.hpp b/src/lib/hierarchy-orientation-indicator.hpp index 826204b61..d02ee997e 100644 --- a/src/lib/hierarchy-orientation-indicator.hpp +++ b/src/lib/hierarchy-orientation-indicator.hpp @@ -43,6 +43,8 @@ #define HIERARCHY_ORIENTATION_INDICATOR_H +#include +#include #include 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::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; } diff --git a/tests/library/hierarchy-orientation-indicator-test.cpp b/tests/library/hierarchy-orientation-indicator-test.cpp index a20f03c85..bdad1fa49 100644 --- a/tests/library/hierarchy-orientation-indicator-test.cpp +++ b/tests/library/hierarchy-orientation-indicator-test.cpp @@ -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");