Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node Swap now correctly swaps schema parents #1179

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
#### Blueprint
- The `conduit::blueprint::mesh::partition()` function no longer issues an error when it receives a "maxshare" adjset.
- The partitioner is better about outputting a "material_map" node for matsets. The "material_map" node is optional for some varieties of matset but they can also help the `conduit::blueprint::mesh::matset::to_silo()` function generate the right material numbers when a domain does not contain all materials.
- The `conduit::Node::swap()` and `conduit::Node::move()` functions no longer cause node names to disappear.

## [0.8.8] - Released 2023-05-18

Expand Down
2 changes: 2 additions & 0 deletions src/libs/conduit/conduit_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8774,6 +8774,7 @@ Node::swap(Node &n_b)

// things we need to swap
// schema pointer
// schema parent pointer
// data pointer and data size
// if data is allocated or not
// if data is memory mapped or not
Expand All @@ -8782,6 +8783,7 @@ Node::swap(Node &n_b)
// any children
std::swap(m_data,n_b.m_data);
std::swap(m_data_size,n_b.m_data_size);
std::swap(m_schema->m_parent,n_b.m_schema->m_parent);
std::swap(m_schema,n_b.m_schema);
std::swap(m_alloced,n_b.m_alloced);
std::swap(m_mmaped,n_b.m_mmaped);
Expand Down
67 changes: 67 additions & 0 deletions src/tests/conduit/t_conduit_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,9 +1315,76 @@ TEST(conduit_node, avoid_crazy_town)
EXPECT_EQ(res,"\ncrazy_town: \"not here\"\n");
}

//-----------------------------------------------------------------------------
TEST(conduit_node, swap_schema_parent)
{
Node root, subtree;
subtree["to/data"] = 5;
root["path"]["to"]["data"] = 6;

std::string path_name = root["path"].name();
std::string path_schema_parent_existence;
if (root["path"].schema().parent() != NULL)
{
path_schema_parent_existence = "path schema parent exists";
}
else
{
path_schema_parent_existence = "path schema parent does not exist";
}
EXPECT_EQ(path_name, "path");
EXPECT_EQ(path_schema_parent_existence, "path schema parent exists");

// swap should preserve the schema parent, allowing name() to work
root["path"].swap(subtree);

path_name = root["path"].name();
path_schema_parent_existence;
if (root["path"].schema().parent() != NULL)
{
path_schema_parent_existence = "path schema parent exists";
}
else
{
path_schema_parent_existence = "path schema parent does not exist";
}
EXPECT_EQ(path_name, "path");
EXPECT_EQ(path_schema_parent_existence, "path schema parent exists");
}

//-----------------------------------------------------------------------------
TEST(conduit_node, move_schema_parent)
{
Node root, subtree;
subtree["to/data"] = 5;
root["path"]["to"]["data"] = 6;

std::string path_name = root["path"].name();
std::string path_schema_parent_existence;
if (root["path"].schema().parent() != NULL)
{
path_schema_parent_existence = "path schema parent exists";
}
else
{
path_schema_parent_existence = "path schema parent does not exist";
}
EXPECT_EQ(path_name, "path");
EXPECT_EQ(path_schema_parent_existence, "path schema parent exists");

// move should preserve the schema parent, allowing name() to work
root["path"].move(subtree);

path_name = root["path"].name();
path_schema_parent_existence;
if (root["path"].schema().parent() != NULL)
{
path_schema_parent_existence = "path schema parent exists";
}
else
{
path_schema_parent_existence = "path schema parent does not exist";
}
EXPECT_EQ(path_name, "path");
EXPECT_EQ(path_schema_parent_existence, "path schema parent exists");
}
Loading