From e610384376a926e6147d6f0b4dd4f514cbccf61c Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 8 Apr 2013 02:37:14 +0200 Subject: [PATCH] WIP: further reworking the test fixture While this isn't immediately relevant to the problem at hand, it looks like a sensible idea to be able to explore an existing data structure by iterators exposing pointers (instead of reference wrappers). Generally speaking, reference wrappers would be preferrable, but, especially when the data structure relies on STL containers, the default constructed values for resizing rule out the standard reference wrapper, which can't be default constructed. Using a custom variant would be equivalent to using just a plain pointer (since both can be NULL and can be rebound) --- .../hierarchy-orientation-indicator-test.cpp | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/tests/library/hierarchy-orientation-indicator-test.cpp b/tests/library/hierarchy-orientation-indicator-test.cpp index 3b4d4f76a..570938653 100644 --- a/tests/library/hierarchy-orientation-indicator-test.cpp +++ b/tests/library/hierarchy-orientation-indicator-test.cpp @@ -155,29 +155,18 @@ namespace test { } - class NodeRef - { - Node* n_; - - public: - NodeRef() : n_(0) { } - NodeRef(Node& n) : n_(&n) { } - - operator Node& () const { return *n_; } - }; - - typedef lib::IterQueue NodeSeq; + typedef lib::IterQueue NodeSeq; /** * Function to generate a depth-first tree visitation */ NodeSeq - exploreChildren (NodeRef ref) + exploreChildren (Node* ref) { - Node& node(ref); + Node& node(*ref); NodeSeq children_to_visit; - build(children_to_visit).usingSequence (node.childSequence()); + build(children_to_visit).usingSequence (AddressExposingIter(node.childSequence())); return children_to_visit; } @@ -205,7 +194,7 @@ namespace test { */ class NodeVisitor { - typedef std::deque NodePath; + typedef std::deque NodePath; typedef NodePath::reverse_iterator PathIter; NodePath path_; @@ -214,10 +203,10 @@ namespace test { // using default ctor and copy operations VisitationData - operator() (Node& node) + operator() (Node* node) { int direction = establishRelation (node); - return VisitationData(node.id_, direction); + return VisitationData(node->id_, direction); } private: @@ -226,15 +215,16 @@ namespace test { * this relation on-the-fly, when visiting the tree, instead of * determining it after the fact. */ int - establishRelation (Node& nextNode) + establishRelation (Node* nextNode) { + REQUIRE (nextNode); uint level = path_.size(); uint refLevel = level; for (PathIter p = path_.rbegin(); 0 < level ; --level, ++p ) { - Node& parent = *p; - if (parent.hasChild (nextNode)) + Node* parent = *p; + if (parent->hasChild (*nextNode)) { // visitation continues with children below this level path_.resize(level); @@ -263,7 +253,7 @@ namespace test { : Node(0) { populate (transformIterator (treeTraversal, - function(NodeVisitor()))); + function(NodeVisitor()))); } private: @@ -371,9 +361,13 @@ namespace test { testWood.push_back(Node()); using iter_stl::eachElm; + using lib::AddressExposingIter; - TreeRebuilder reconstructed (depthFirst (eachElm (testWood)) >>= exploreChildren); + TreeRebuilder reconstructed (depthFirst (AddressExposingIter(eachElm (testWood))) >>= exploreChildren); + + //////////////////TODO: problem is in WrappedSequence. The operator*() returns a ref, but AddressExposingIter returns a value + //////////////////TODO: solution idea: use a specialisation for AddressexposingIter in "depthFirst" cout << reconstructed.children_.size() << "=?=" << testWood.size(); CHECK (reconstructed.children_ == testWood);