Commit d74b96ba authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Support FieldSelection initialization with vtkm::Pair initializer list

It already supported initializer lists of std::pair. It seems weird we
would not also support our own version of pair.
parent 8e312f81
......@@ -22,6 +22,7 @@
#include <initializer_list>
#include <set>
#include <vtkm/Pair.h>
#include <vtkm/cont/Field.h>
namespace vtkm
......@@ -66,9 +67,10 @@ public:
/// Use this constructor create a field selection given the field names and
/// associations e.g.
/// @code{cpp}
/// using pair_type = std::pair<std::string, vtkm::cont::Field::AssociationEnum>;
/// FieldSelection({
/// std::pair{"field_one", vtkm::cont::Field::ASSOC_POINTS},
/// std::pair{"field_two", vtkm::cont::Field::ASSOC_CELL_SET} });
/// pair_type{"field_one", vtkm::cont::Field::ASSOC_POINTS},
/// pair_type{"field_two", vtkm::cont::Field::ASSOC_CELL_SET} });
/// @endcode
VTKM_CONT
FieldSelection(
......@@ -82,6 +84,26 @@ public:
}
}
/// Use this constructor create a field selection given the field names and
/// associations e.g.
/// @code{cpp}
/// using pair_type = vtkm::Pair<std::string, vtkm::cont::Field::AssociationEnum>;
/// FieldSelection({
/// pair_type{"field_one", vtkm::cont::Field::ASSOC_POINTS},
/// pair_type{"field_two", vtkm::cont::Field::ASSOC_CELL_SET} });
/// @endcode
VTKM_CONT
FieldSelection(
std::initializer_list<vtkm::Pair<std::string, vtkm::cont::Field::AssociationEnum>> fields,
ModeEnum mode = MODE_SELECT)
: Mode(mode)
{
for (const auto& item : fields)
{
this->AddField(item.first, item.second);
}
}
VTKM_CONT
~FieldSelection() {}
......
......@@ -50,7 +50,7 @@ void TestFieldSelection()
}
{
std::cout << "field selection with specific fields selected." << std::endl;
std::cout << "field selection with specific fields selected (AddField)." << std::endl;
vtkm::filter::FieldSelection selection;
selection.AddField("foo");
selection.AddField("bar", vtkm::cont::Field::ASSOC_CELL_SET);
......@@ -65,7 +65,7 @@ void TestFieldSelection()
}
{
std::cout << "field selection with specific fields selected." << std::endl;
std::cout << "field selection with specific fields selected (initializer list)." << std::endl;
vtkm::filter::FieldSelection selection{ "foo", "bar" };
VTKM_TEST_ASSERT(selection.IsFieldSelected("foo") == true, "field selection failed.");
VTKM_TEST_ASSERT(selection.IsFieldSelected("foo", vtkm::cont::Field::ASSOC_POINTS) == true,
......@@ -78,7 +78,8 @@ void TestFieldSelection()
}
{
std::cout << "field selection with specific fields selected." << std::endl;
std::cout << "field selection with specific fields selected (std::pair initializer list)."
<< std::endl;
using pair_type = std::pair<std::string, vtkm::cont::Field::AssociationEnum>;
vtkm::filter::FieldSelection selection{ pair_type{ "foo", vtkm::cont::Field::ASSOC_ANY },
pair_type{ "bar", vtkm::cont::Field::ASSOC_CELL_SET } };
......@@ -92,6 +93,22 @@ void TestFieldSelection()
VTKM_TEST_ASSERT(selection.IsFieldSelected("bar") == true, "field selection failed.");
}
{
std::cout << "field selection with specific fields selected (vtkm::Pair initializer list)."
<< std::endl;
using pair_type = vtkm::Pair<std::string, vtkm::cont::Field::AssociationEnum>;
vtkm::filter::FieldSelection selection{ pair_type{ "foo", vtkm::cont::Field::ASSOC_ANY },
pair_type{ "bar", vtkm::cont::Field::ASSOC_CELL_SET } };
VTKM_TEST_ASSERT(selection.IsFieldSelected("foo") == true, "field selection failed.");
VTKM_TEST_ASSERT(selection.IsFieldSelected("foo", vtkm::cont::Field::ASSOC_POINTS) == true,
"field selection failed.");
VTKM_TEST_ASSERT(selection.IsFieldSelected("bar", vtkm::cont::Field::ASSOC_POINTS) == false,
"field selection failed.");
VTKM_TEST_ASSERT(selection.IsFieldSelected("bar", vtkm::cont::Field::ASSOC_CELL_SET) == true,
"field selection failed.");
VTKM_TEST_ASSERT(selection.IsFieldSelected("bar") == true, "field selection failed.");
}
{
std::cout << "field selection with specific fields excluded." << std::endl;
using pair_type = std::pair<std::string, vtkm::cont::Field::AssociationEnum>;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment