Skip to content
Snippets Groups Projects
Commit 4920a07d authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Add MeshSubsets meshes uniqueness precondition in ctor.

parent e3c29cb1
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <stdexcept>
#include "MeshLib/MeshSubset.h" #include "MeshLib/MeshSubset.h"
...@@ -35,10 +36,15 @@ public: ...@@ -35,10 +36,15 @@ public:
/// Construct MeshSubsets from a range of MeshSubset. InputIterator must /// Construct MeshSubsets from a range of MeshSubset. InputIterator must
/// dereference to MeshSubset*. /// dereference to MeshSubset*.
/// \pre All meshes of each of the MeshSubset objects must unique,
/// an exception is thrown otherwise.
template <typename InputIterator> template <typename InputIterator>
MeshSubsets(InputIterator const& first, InputIterator const& last) MeshSubsets(InputIterator const& first, InputIterator const& last)
: _mesh_subsets(first, last) : _mesh_subsets(first, last)
{ {
if (!areMeshSubsetMeshesUnique())
throw std::logic_error("Mesh ids of input mesh subsets are not unique.");
_n_total_items = std::accumulate(first, last, 0u, _n_total_items = std::accumulate(first, last, 0u,
[](std::size_t const& sum, MeshSubset const* const mesh_subset) [](std::size_t const& sum, MeshSubset const* const mesh_subset)
{ {
...@@ -64,6 +70,20 @@ public: ...@@ -64,6 +70,20 @@ public:
return *_mesh_subsets[mesh_index]; return *_mesh_subsets[mesh_index];
} }
private:
/// returns true if all mesh ids of _mesh_subsets elements are different.
bool areMeshSubsetMeshesUnique() const
{
std::vector<std::size_t> mesh_ids;
std::transform(_mesh_subsets.cbegin(), _mesh_subsets.cend(),
std::back_inserter(mesh_ids), std::mem_fun(&MeshSubset::getMeshID));
std::sort(mesh_ids.begin(), mesh_ids.end());
auto const it = std::adjacent_find(mesh_ids.cbegin(), mesh_ids.cend());
return mesh_ids.cend() == it;
}
private: private:
std::vector<const MeshSubset*> _mesh_subsets; std::vector<const MeshSubset*> _mesh_subsets;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment