add diagnostic self display to QueryFocus

This commit is contained in:
Fischlurch 2010-10-15 05:05:05 +02:00
parent c772359440
commit d8c06fac1e
6 changed files with 44 additions and 8 deletions

View file

@ -24,6 +24,11 @@
#include "proc/mobject/session/query-focus.hpp"
#include "proc/mobject/mobject.hpp"
#include <boost/format.hpp>
using boost::format;
using boost::str;
namespace mobject {
namespace session {
@ -155,4 +160,14 @@ namespace session {
/** diagnostic self-display based on the ScopePath */
QueryFocus::operator string() const
{
static format display("Focus(%d)--->%s");
return str ( display % ScopeLocator::instance().stackSize()
% string (*focus_));
}
}} // namespace mobject::session

View file

@ -29,6 +29,7 @@
#include "proc/mobject/session/scope-locator.hpp"
#include <boost/intrusive_ptr.hpp>
#include <string>
namespace mobject {
namespace session {
@ -91,6 +92,7 @@ namespace session {
ScopePath const& currentPath() const;
operator Scope() const;
operator string() const;
QueryFocus& attach (Scope const&);
static QueryFocus push (Scope const&);

View file

@ -85,6 +85,8 @@ namespace session {
lib::IterSource<const Scope>::iterator
locate (Scope const& target);
size_t stackSize() const;
~ScopeLocator();
@ -143,7 +145,7 @@ namespace session {
{
return ScopeQuery<MObject> (scope.getTop(), PATH).resolveBy (theResolver());
}
}} // namespace mobject::session
#endif

View file

@ -121,6 +121,13 @@ namespace session {
}
size_t
ScopeLocator::stackSize() const
{
return focusStack_->size();
}
/** establishes the \em current query focus location.
* Relies on the state of the QueryFocusStack.
* If there is no current focus location, a new

View file

@ -221,6 +221,16 @@ END
TEST "Query focus management" QueryFocus_test <<END
out: Focus\(2\)--->/\[DummyMO....\]
out: Focus\(3\)--->/$
out: Focus\(3\)--->/\[DummyMO....\]$
out: Focus\(3\)--->/\[DummyMO....\]/\[DummyMO....\]$
out: Focus\(3\)--->/\[DummyMO....\]/\[DummyMO....\]/\[DummyMO....\]$
out: Focus\(3\)--->/\[DummyMO....\]/\[DummyMO....\]/\[DummyMO....\]/\[DummyMO....\]$
out: Focus\(3\)--->/\[DummyMO....\]/\[DummyMO....\]/\[DummyMO....\]/\[DummyMO....\]/\[DummyMO....\]$
out: Focus\(3\)--->/\[DummyMO....\]/\[DummyMO....\]/\[DummyMO....\]/\[DummyMO....\]/\[DummyMO....\]<<<--discovery exhausted
out: Focus\(2\)--->/\[DummyMO....\]<<<--after pop
out: Focus\(2\)--->/\[DummyMO....\]
return: 0
END

View file

@ -137,7 +137,7 @@ namespace test {
ASSERT (num_refs > 1); // because the run() function also holds a ref
QueryFocus subF = QueryFocus::push();
// cout << string(subF) << endl; /////////////////////////////////////TICKET #429 display diagnostic output
cout << string(subF) << endl;
ASSERT (subF == original);
ASSERT ( 1 == refs(subF) );
@ -147,25 +147,25 @@ namespace test {
QueryFocus subF2 = QueryFocus::push(Scope(subF).getParent());
ASSERT (subF2 != subF);
ASSERT (subF == original);
// cout << string(subF2) << endl; /////////////////////////////////////TICKET #429 display diagnostic output
cout << string(subF2) << endl;
ScopeQuery<TestSubMO21>::iterator ii = subF2.explore<TestSubMO21>();
while (ii) // drill down depth first
{
subF2.attach(*ii);
// cout << string(subF2) << endl; /////////////////////////////////////TICKET #429 display diagnostic output
cout << string(subF2) << endl;
ii = subF2.explore<TestSubMO21>();
}
// cout << string(subF2) << "<<<--discovery exhausted" << endl; /////////////////////////////////////TICKET #429 display diagnostic output
cout << string(subF2) << "<<<--discovery exhausted" << endl;
subF2.pop(); // releasing this focus and re-attaching to what's on stack top
// cout << string(subF2) << "<<<--after pop()" << endl; /////////////////////////////////////TICKET #429 display diagnostic output
cout << string(subF2) << "<<<--after pop()" << endl;
ASSERT (subF2 == subF);
ASSERT (2 == refs(subF2)); // both are now attached to the same path
ASSERT (2 == refs(subF));
}
// subF2 went out of scope, but no auto-pop happens (because subF is still there)
// cout << string(subF) << endl; /////////////////////////////////////TICKET #429 display diagnostic output
cout << string(subF) << endl;
ASSERT ( 1 == refs(subF));
ASSERT (num_refs == refs(original));