Skip to content

Commit

Permalink
Revert "Switch up relocate interface."
Browse files Browse the repository at this point in the history
This reverts commit 518c654.
  • Loading branch information
tmadden committed Dec 17, 2020
1 parent 518c654 commit 62b1d81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/alia/flow/object_trees.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ check_for_movement(tree_traversal<Object>& traversal, tree_node<Object>& node)
if (expected_node != &node)
{
node.remove_from_list();
traversal.active_parent->object.relocate(
node.object,
node.object.relocate(
traversal.active_parent->object,
traversal.last_sibling ? &traversal.last_sibling->object : nullptr,
expected_node ? &expected_node->object : nullptr);
node.insert_into_list(traversal.next_ptr, expected_node);
Expand Down Expand Up @@ -356,8 +356,8 @@ struct scoped_tree_cacher
tree_node<Object>** next_ptr = nullptr;
while (next_ptr != data.subtree_tail)
{
traversal.active_parent->object.relocate(
current_node->object,
current_node->object.relocate(
traversal.active_parent->object,
last_sibling ? &last_sibling->object : nullptr,
node_after);
last_sibling = current_node;
Expand Down
19 changes: 9 additions & 10 deletions unit_tests/flow/testing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,34 +134,33 @@ struct test_object
}

void
relocate(test_object& new_child, test_object* after, test_object* before)
relocate(test_object& new_parent, test_object* after, test_object* before)
{
the_log << "relocating " << new_child.name << " into " << this->name;
the_log << "relocating " << name << " into " << new_parent.name;
if (after)
the_log << " after " << after->name;
the_log << "; ";

if (new_child.parent)
if (this->parent)
{
auto& siblings = new_child.parent->children;
auto& siblings = this->parent->children;
siblings.erase(
std::remove(siblings.begin(), siblings.end(), &new_child),
std::remove(siblings.begin(), siblings.end(), this),
siblings.end());
}

new_child.parent = this;
this->parent = &new_parent;

auto& siblings = this->children;
auto& siblings = new_parent.children;
std::vector<test_object*>::iterator insertion_point;
if (after)
{
insertion_point = siblings.insert(
std::find(siblings.begin(), siblings.end(), after) + 1,
&new_child);
std::find(siblings.begin(), siblings.end(), after) + 1, this);
}
else
{
insertion_point = siblings.insert(siblings.begin(), &new_child);
insertion_point = siblings.insert(siblings.begin(), this);
}

++insertion_point;
Expand Down

0 comments on commit 62b1d81

Please sign in to comment.