23#ifndef VCL_ALGORITHMS_MESH_CHECK_POINTERS_H
24#define VCL_ALGORITHMS_MESH_CHECK_POINTERS_H
26#include <vclib/concepts/mesh.h>
27#include <vclib/exceptions/mesh.h>
28#include <vclib/misc/string.h>
36template<u
int ELEM_ID, MeshConcept MeshType>
37bool checkParentMeshPointers(
const MeshType& mesh)
39 for (
const auto& el : mesh.template elements<ELEM_ID>()) {
40 if (el.parentMesh() != &mesh) {
41 throw InconsistentMeshException(
42 "The " + elementEnumString<ELEM_ID>() +
" n. " +
43 toString(el.index()) +
" has a wrong Parent Mesh.\n" +
44 "Expected: " + toString(&mesh) +
"; " +
45 "Found: " + toString(el.parentMesh()));
52template<MeshConcept MeshType,
typename... Containers>
53bool checkParentMeshPointers(
const MeshType& mesh, TypeWrapper<Containers...>)
56 checkParentMeshPointers<Containers::ElementType::ELEMENT_ID>(mesh) &&
62template<u
int ELEM_ID,
typename Comp, MeshConcept MeshType,
typename ElemType>
63bool checkElementPointersInElementContainerOnComponent(
65 const ElemType* first,
74 if constexpr (comp::HasPointersOfType<Comp, ElemType>) {
78 auto pointersLoop = [&]() {
80 for (
const auto& el : mesh.template elements<ELEM_ID>()) {
83 const Comp& comp =
static_cast<const Comp&
>(el);
86 for (
const ElemType* ptr : comp.template pointers<ElemType>()) {
88 if (ptr < first || ptr >= last) {
89 throw InconsistentMeshException(
90 "The " + elementEnumString<ELEM_ID>() +
" n. " +
91 toString(el.index()) +
92 " has a wrong pointer in " +
93 componentEnumString<Comp::COMPONENT_ID>() +
94 " component.\n" +
"The pointer " +
95 toString(ptr) +
" is out of range [" +
96 toString(first) +
", " + toString(last) +
")");
106 if constexpr (comp::HasOptionalPointersOfType<Comp, ElemType>) {
107 if (mesh.template isPerElementComponentEnabled<
109 Comp::COMPONENT_ID>()) {
110 return pointersLoop();
115 return pointersLoop();
120 if constexpr (comp::HasIndicesOfType<Comp, ElemType>) {
124 auto indicesLoop = [&]() {
126 for (
const auto& el : mesh.template elements<ELEM_ID>()) {
129 const Comp& comp =
static_cast<const Comp&
>(el);
132 for (uint i : comp.template indices<ElemType>()) {
134 if (i >= last - first) {
135 throw InconsistentMeshException(
136 "The " + elementEnumString<ELEM_ID>() +
" n. " +
137 toString(el.index()) +
138 " has a wrong index in " +
139 componentEnumString<Comp::COMPONENT_ID>() +
140 " component.\n" +
"The index " + toString(i) +
141 " is out of range [ 0, " +
142 toString(last - first) +
")");
152 if constexpr (comp::HasOptionalIndicesOfType<Comp, ElemType>) {
153 if (mesh.template isPerElementComponentEnabled<
155 Comp::COMPONENT_ID>()) {
156 return indicesLoop();
161 return indicesLoop();
170 MeshConcept MeshType,
173bool checkElementPointersInElementContainerOnComponents(
174 const MeshType& mesh,
175 const ElemType* first,
176 const ElemType* last,
177 TypeWrapper<Comps...>)
182 checkElementPointersInElementContainerOnComponent<ELEM_ID, Comps>(
183 mesh, first, last) &&
187template<u
int ELEM_ID, MeshConcept MeshType,
typename ElemType>
188bool checkElementPointersInElementContainer(
189 const MeshType& mesh,
190 const ElemType* first,
191 const ElemType* last)
193 using ThisElemType = MeshType::template ElementType<ELEM_ID>;
194 using ThisElemComponents = ThisElemType::Components;
200 return checkElementPointersInElementContainerOnComponents<ELEM_ID>(
201 mesh, first, last, ThisElemComponents());
204template<uint ELEM_ID, MeshConcept MeshType,
typename... Containers>
205bool checkElementPointers(
const MeshType& mesh, TypeWrapper<Containers...>)
207 using ElemType = MeshType::template ElementType<ELEM_ID>;
209 const ElemType* first = &mesh.template element<ELEM_ID>(0);
210 uint size = mesh.template containerSize<ELEM_ID>();
211 const ElemType* last = first + size;
216 checkElementPointersInElementContainer<
217 Containers::ElementType::ELEMENT_ID>(mesh, first, last) &&
221template<MeshConcept MeshType,
typename... Containers>
222bool checkMeshPointers(
const MeshType& mesh, TypeWrapper<Containers...>)
225 checkElementPointers<Containers::ElementType::ELEMENT_ID>(
226 mesh, TypeWrapper<Containers...>()) &&
232template<MeshConcept MeshType>
233bool checkMeshPointers(
const MeshType& mesh)
236 detail::checkParentMeshPointers(mesh,
typename MeshType::Containers());
239 res && detail::checkMeshPointers(mesh,
typename MeshType::Containers());
constexpr uint UINT_NULL
The UINT_NULL value represent a null value of uint that is the maximum value that can be represented ...
Definition base.h:48