Skip to content

Commit

Permalink
Node Swap now correctly swaps schema parents
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinPrivitera authored Oct 31, 2023
2 parents 80178d9 + 65125fa commit e17a944
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
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");
}

0 comments on commit e17a944

Please sign in to comment.