Commit b56cde38 authored by T.J. Corona's avatar T.J. Corona

smtk::mesh::Collection: visit()

parent 3a3aa930
......@@ -120,8 +120,27 @@ std::function<bool(const resource::ComponentPtr&)> Collection::queryOperation(
// visit all components in the resource.
void Collection::visit(smtk::resource::Component::Visitor& visitor) const
{
// TODO
(void)visitor;
class Visit : public smtk::mesh::MeshForEach
{
public:
Visit(smtk::resource::Component::Visitor& visitor)
: smtk::mesh::MeshForEach()
, m_visitor(visitor)
{
}
void forMesh(smtk::mesh::MeshSet& mesh) override
{
m_visitor(smtk::mesh::Component::create(mesh));
}
private:
smtk::resource::Component::Visitor& m_visitor;
};
Visit visit_(visitor);
smtk::mesh::for_each(this->meshes(), visit_);
}
const smtk::mesh::InterfacePtr& Collection::interface() const
......
......@@ -10,6 +10,7 @@
#include "smtk/io/ImportMesh.h"
#include "smtk/mesh/core/Collection.h"
#include "smtk/mesh/core/Component.h"
#include "smtk/mesh/testing/cxx/helpers.h"
......@@ -399,6 +400,20 @@ void verify_meshset_for_each(const smtk::mesh::CollectionPtr& c)
test(static_cast<std::size_t>(functor.numberOfMeshesVisited()) == volMeshes.size());
test(functor.cells() == volMeshes.cells());
}
void verify_meshset_visit(const smtk::mesh::CollectionPtr& c)
{
std::size_t numMeshesIteratedOver = 0;
smtk::resource::Component::Visitor countMeshesAndCells = [&](
const smtk::resource::ComponentPtr& component) {
auto meshComponent = std::dynamic_pointer_cast<smtk::mesh::Component>(component);
numMeshesIteratedOver++;
};
c->visit(countMeshesAndCells);
test(numMeshesIteratedOver == c->meshes().size());
}
}
int UnitTestMeshSet(int, char** const)
......@@ -420,6 +435,7 @@ int UnitTestMeshSet(int, char** const)
verify_meshset_subtract(c);
verify_meshset_for_each(c);
verify_meshset_visit(c);
return 0;
}
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