23#ifndef VCL_ALGORITHMS_MESH_CHECK_POINTERS_H
24#define VCL_ALGORITHMS_MESH_CHECK_POINTERS_H
26#include <vclib/mesh.h>
34template<u
int ELEM_ID, MeshConcept MeshType>
35bool checkParentMeshPointers(
const MeshType& mesh)
37 for (
const auto& el : mesh.template elements<ELEM_ID>()) {
38 if (el.parentMesh() != &mesh) {
39 throw InconsistentMeshException(
40 "The " + elementEnumString<ELEM_ID>() +
" n. " +
41 toString(el.index()) +
" has a wrong Parent Mesh.\n" +
42 "Expected: " + toString(&mesh) +
"; " +
43 "Found: " + toString(el.parentMesh()));
50template<MeshConcept MeshType,
typename... Containers>
51bool checkParentMeshPointers(
const MeshType& mesh, TypeWrapper<Containers...>)
54 checkParentMeshPointers<Containers::ElementType::ELEMENT_ID>(mesh) &&
60template<u
int ELEM_ID,
typename Comp, MeshConcept MeshType,
typename ElemType>
61bool checkElementPointersInElementContainerOnComponent(
63 const ElemType* first,
72 if constexpr (comp::HasPointersOfType<Comp, ElemType>) {
76 auto pointersLoop = [&]() {
78 for (
const auto& el : mesh.template elements<ELEM_ID>()) {
81 const Comp& comp =
static_cast<const Comp&
>(el);
84 for (
const ElemType* ptr : comp.template pointers<ElemType>()) {
86 if (ptr < first || ptr >= last) {
87 throw InconsistentMeshException(
88 "The " + elementEnumString<ELEM_ID>() +
" n. " +
89 toString(el.index()) +
90 " has a wrong pointer in " +
91 componentEnumString<Comp::COMPONENT_ID>() +
92 " component.\n" +
"The pointer " +
93 toString(ptr) +
" is out of range [" +
94 toString(first) +
", " + toString(last) +
")");
104 if constexpr (comp::HasOptionalPointersOfType<Comp, ElemType>) {
105 if (mesh.template isPerElementComponentEnabled<
107 Comp::COMPONENT_ID>()) {
108 return pointersLoop();
113 return pointersLoop();
118 if constexpr (comp::HasIndicesOfType<Comp, ElemType>) {
122 auto indicesLoop = [&]() {
124 for (
const auto& el : mesh.template elements<ELEM_ID>()) {
127 const Comp& comp =
static_cast<const Comp&
>(el);
130 for (uint i : comp.template indices<ElemType>()) {
132 if (i >= last - first) {
133 throw InconsistentMeshException(
134 "The " + elementEnumString<ELEM_ID>() +
" n. " +
135 toString(el.index()) +
136 " has a wrong index in " +
137 componentEnumString<Comp::COMPONENT_ID>() +
138 " component.\n" +
"The index " + toString(i) +
139 " is out of range [ 0, " +
140 toString(last - first) +
")");
150 if constexpr (comp::HasOptionalIndicesOfType<Comp, ElemType>) {
151 if (mesh.template isPerElementComponentEnabled<
153 Comp::COMPONENT_ID>()) {
154 return indicesLoop();
159 return indicesLoop();
168 MeshConcept MeshType,
171bool checkElementPointersInElementContainerOnComponents(
172 const MeshType& mesh,
173 const ElemType* first,
174 const ElemType* last,
175 TypeWrapper<Comps...>)
180 checkElementPointersInElementContainerOnComponent<ELEM_ID, Comps>(
181 mesh, first, last) &&
185template<u
int ELEM_ID, MeshConcept MeshType,
typename ElemType>
186bool checkElementPointersInElementContainer(
187 const MeshType& mesh,
188 const ElemType* first,
189 const ElemType* last)
191 using ThisElemType = MeshType::template ElementType<ELEM_ID>;
192 using ThisElemComponents = ThisElemType::Components;
198 return checkElementPointersInElementContainerOnComponents<ELEM_ID>(
199 mesh, first, last, ThisElemComponents());
202template<uint ELEM_ID, MeshConcept MeshType,
typename... Containers>
203bool checkElementPointers(
const MeshType& mesh, TypeWrapper<Containers...>)
205 using ElemType = MeshType::template ElementType<ELEM_ID>;
207 const ElemType* first = &mesh.template element<ELEM_ID>(0);
208 uint size = mesh.template containerSize<ELEM_ID>();
209 const ElemType* last = first + size;
214 checkElementPointersInElementContainer<
215 Containers::ElementType::ELEMENT_ID>(mesh, first, last) &&
219template<MeshConcept MeshType,
typename... Containers>
220bool checkMeshPointers(
const MeshType& mesh, TypeWrapper<Containers...>)
223 checkElementPointers<Containers::ElementType::ELEMENT_ID>(
224 mesh, TypeWrapper<Containers...>()) &&
230template<MeshConcept MeshType>
231bool checkMeshPointers(
const MeshType& mesh)
234 detail::checkParentMeshPointers(mesh,
typename MeshType::Containers());
237 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