diff --git a/src/proc/mobject/session/scope-path.cpp b/src/proc/mobject/session/scope-path.cpp index 49ec87b0c..c713e2fc0 100644 --- a/src/proc/mobject/session/scope-path.cpp +++ b/src/proc/mobject/session/scope-path.cpp @@ -39,6 +39,7 @@ namespace session { using std::reverse; using lib::append_all; using util::isSameObject; + using util::isnil; using namespace lumiera; @@ -141,6 +142,26 @@ namespace session { const ScopePath ScopePath::INVALID = ScopePath(Scope()); + /** ScopePath diagnostic self display. + * Implemented similar to a filesystem path, where the + * path elements are based on the self-display of the MObject + * attached through the respective scope top placement. */ + ScopePath::operator string() const + { + if (isnil (path_)) return "!"; + if (1 == length()) return "/"; + + string res; + vector::const_iterator node (path_.begin()); + while (++node != path_.end()) + { + res += "/"; + res += string (*node); + } + return res; + } + + /** a \em valid path consists of more than just the root element. * @note contrary to this, an \em empty path doesn't even contain a root element */ diff --git a/src/proc/mobject/session/scope-path.hpp b/src/proc/mobject/session/scope-path.hpp index d23d286cf..61799d95d 100644 --- a/src/proc/mobject/session/scope-path.hpp +++ b/src/proc/mobject/session/scope-path.hpp @@ -93,6 +93,7 @@ #include "lib/error.hpp" #include +#include namespace lib { @@ -163,7 +164,7 @@ namespace session { size_t size() const; size_t length() const; size_t ref_count()const; - ////////////////////////////////////////TICKET #429 : diagnostic output to be added later + operator string() const; /// Iteration is always ascending from leaf to root typedef _IterType iterator; diff --git a/tests/43session.tests b/tests/43session.tests index 32c12d434..5f6f8994b 100644 --- a/tests/43session.tests +++ b/tests/43session.tests @@ -190,6 +190,12 @@ END TEST "Path of nested scopes" ScopePath_test < +#include namespace mobject { namespace session { namespace test { + using std::cout; + using std::endl; + using std::string; using util::isnil; using util::isSameObject; @@ -75,7 +80,6 @@ namespace test { check_RefcountProtection (startPlacement); navigate (testPath, index); clear (testPath, index); - ////////////////////////////////////////TICKET #429 : verify diagnostic output (to be added later) } @@ -183,6 +187,7 @@ namespace test { ASSERT (refPath); ASSERT (!ScopePath::INVALID); ASSERT (isnil (ScopePath::INVALID)); + ASSERT ("!" == string(ScopePath::INVALID)); ScopePath invalidP (ScopePath::INVALID); ASSERT (isnil (invalidP)); @@ -304,11 +309,13 @@ namespace test { void navigate (const ScopePath refPath, PPIdx index) { - ScopePath path (refPath); + #define __SHOWPATH(N) cout << "Step("<find( // place newNode as sibling of "leaf" index->insert (newNode, parentRefPoint)); - path.navigate (newLocation); + path.navigate (newLocation); __SHOWPATH(5) Scope sibling = path.getLeaf(); ASSERT (sibling == newLocation); ASSERT (parent == sibling.getParent()); @@ -350,7 +357,7 @@ namespace test { ASSERT (prefix.endsAt (parent)); ASSERT (!prefix.contains (leaf)); ASSERT (!prefix.contains (sibling)); - path.navigate (prefix.getLeaf()); + path.navigate (prefix.getLeaf()); __SHOWPATH(6) ASSERT (path == prefix); // try to navigate to an unconnected location...