23#ifndef VCL_MESH_COMPONENTS_BASE_REFERENCE_CONTAINER_COMPONENT_H
24#define VCL_MESH_COMPONENTS_BASE_REFERENCE_CONTAINER_COMPONENT_H
26#include "index_container_component.h"
27#include "pointer_container_component.h"
72 typename DerivedComponent,
76 typename ParentElemType,
80class ReferenceContainerComponent :
81 public std::conditional_t<
83 IndexContainerComponent<
92 PointerContainerComponent<
103 using Base = std::conditional_t<
105 IndexContainerComponent<
114 PointerContainerComponent<
124 uint size()
const {
return Base::container().
size(); }
126 Elem* element(uint i)
128 if constexpr (STORE_INDICES)
129 return elemFromParent(elementIndex(i));
131 return Base::container().at(i);
134 const Elem* element(uint i)
const
136 if constexpr (STORE_INDICES)
137 return elemFromParent(elementIndex(i));
139 return Base::container().at(i);
142 uint elementIndex(uint i)
const
144 if constexpr (STORE_INDICES)
145 return Base::container().at(i);
147 return indexFromPointer(Base::container().at(i));
150 Elem* elementMod(
int i)
152 if constexpr (STORE_INDICES)
153 return elemFromParent(elementIndexMod(i));
155 return Base::container().atMod(i);
158 const Elem* elementMod(
int i)
const
160 if constexpr (STORE_INDICES)
161 return elemFromParent(elementIndexMod(i));
163 return Base::container().atMod(i);
166 uint elementIndexMod(
int i)
const
168 if constexpr (STORE_INDICES)
169 return Base::container().atMod(i);
171 return indexFromPointer(elementMod(i));
174 void setElement(uint i, Elem* e)
176 if constexpr (STORE_INDICES)
177 Base::container().set(i, indexFromPointer(e));
179 Base::container().set(i, e);
182 void setElement(uint i, uint ei)
184 if constexpr (STORE_INDICES)
185 Base::container().set(i, ei);
187 Base::container().set(i, elemFromParent(ei));
190 void setElement(Base::ConstIterator it, Elem* v)
192 setElement(it - elementBegin(), v);
195 void setElement(Base::ConstIterator it, uint vi)
197 setElement(it - elementBegin(), vi);
200 void setElement(Base::ConstIndexIterator it, Elem* v)
202 setElement(it - elementBegin(), v);
205 void setElement(Base::ConstIndexIterator it, uint vi)
207 setElement(it - elementBegin(), vi);
210 void setElementMod(
int i, Elem* e)
212 if constexpr (STORE_INDICES)
213 Base::container().atMod(i) = indexFromPointer(e);
215 Base::container().atMod(i) = e;
218 void setElementMod(
int i, uint ei)
220 if constexpr (STORE_INDICES)
221 Base::container().atMod(i) = ei;
223 Base::container().atMod(i) = elemFromParent(ei);
227 void setElements(Rng&& r)
requires InputRange<Rng, Elem*>
229 if constexpr (STORE_INDICES) {
230 auto conv = [&](
auto v) {
231 return indexFromPointer(v);
234 Base::container().set(r | std::views::transform(conv));
237 Base::container().set(r);
242 void setElements(Rng&& r)
requires InputRange<Rng, uint>
244 if constexpr (STORE_INDICES) {
245 Base::container().set(r);
248 auto conv = [&](
auto i) {
249 return elemFromParent(i);
252 Base::container().set(r | std::views::transform(conv));
256 bool containsElement(
const Elem* e)
const
258 if constexpr (STORE_INDICES)
259 return Base::container().contains(indexFromPointer(e));
261 return Base::container().contains(e);
264 bool containsElement(uint ei)
const
266 if constexpr (STORE_INDICES)
267 return Base::container().contains(ei);
269 return Base::container().contains(elemFromParent(ei));
272 uint indexOfElement(
const Elem* e)
const
274 if constexpr (STORE_INDICES)
275 return Base::container().indexOf(indexFromPointer(e));
277 return Base::container().indexOf(e);
280 uint indexOfElement(uint ei)
const
282 if constexpr (STORE_INDICES)
283 return Base::container().indexOf(ei);
285 return Base::container().indexOf(elemFromParent(ei));
288 Base::Iterator elementBegin()
290 if constexpr (STORE_INDICES)
291 return typename Base::Iterator(
292 Base::container().begin(), Base::parentElement());
294 return Base::container().begin();
297 Base::Iterator elementEnd()
299 if constexpr (STORE_INDICES)
300 return typename Base::Iterator(Base::container().end());
302 return Base::container().end();
305 Base::ConstIterator elementBegin()
const
307 if constexpr (STORE_INDICES)
308 return typename Base::ConstIterator(
309 Base::container().begin(), Base::parentElement());
311 return Base::container().begin();
314 Base::ConstIterator elementEnd()
const
316 if constexpr (STORE_INDICES)
317 return typename Base::ConstIterator(Base::container().end());
319 return Base::container().end();
322 Base::ConstIndexIterator elementIndexBegin()
const
324 if constexpr (STORE_INDICES)
325 return Base::container().begin();
327 return typename Base::ConstIndexIterator(elementBegin());
330 Base::ConstIndexIterator elementIndexEnd()
const
332 if constexpr (STORE_INDICES)
333 return Base::container().end();
335 return typename Base::ConstIndexIterator(elementEnd());
338 View<typename Base::Iterator> elements()
340 return View(elementBegin(), elementEnd());
343 View<typename Base::ConstIterator> elements()
const
345 return View(elementBegin(), elementEnd());
348 View<typename Base::ConstIndexIterator> elementIndices()
const
350 return View(elementIndexBegin(), elementIndexEnd());
355 void resize(uint n)
requires (N < 0)
357 if constexpr (STORE_INDICES)
358 Base::container().resize(n, UINT_NULL);
360 Base::container().resize(n);
363 void pushBack(Elem* e =
nullptr)
requires (N < 0)
365 if constexpr (STORE_INDICES)
366 Base::container().pushBack(indexFromPointer(e));
368 Base::container().pushBack(e);
371 void pushBack(uint ei)
requires (N < 0)
373 if constexpr (STORE_INDICES)
374 Base::container().pushBack(ei);
376 Base::container().pushBack(elemFromParent(ei));
379 void insert(uint i, Elem* e =
nullptr)
requires (N < 0)
381 if constexpr (STORE_INDICES)
382 Base::container().insert(i, indexFromPointer(e));
384 Base::container().insert(i, e);
387 void insert(uint i, uint ei)
requires (N < 0)
389 if constexpr (STORE_INDICES)
390 Base::container().insert(i, ei);
392 Base::container().insert(i, elemFromParent(ei));
395 void erase(uint i)
requires (N < 0) { Base::container().erase(i); }
397 void clear()
requires (N < 0) { Base::container().clear(); }
401 uint indexFromPointer(
const Elem* v)
const
403 if (v ==
nullptr) [[unlikely]]
409 Elem* elemFromParent(uint vi)
411 if (vi == UINT_NULL) [[unlikely]]
414 return &Base::parentElement()
416 ->template element<Elem::ELEMENT_ID>(vi);
419 const Elem* elemFromParent(uint vi)
const
421 if (vi == UINT_NULL) [[unlikely]]
424 return &Base::parentElement()
426 ->template element<Elem::ELEMENT_ID>(vi);
PointT size() const
Computes the size of the box.
Definition box.h:267
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