23#ifndef VCL_MESH_COMPONENTS_BASE_POINTER_CONTAINER_COMPONENT_H
24#define VCL_MESH_COMPONENTS_BASE_POINTER_CONTAINER_COMPONENT_H
26#include "container_component.h"
28#include <vclib/mesh/iterators/components/index_from_pointer_iterator.h>
30#include <vclib/base.h>
78 typename DerivedComponent,
82 typename ParentElemType,
86class PointerContainerComponent :
87 public ContainerComponent<
99 using Base = ContainerComponent<
121 auto pointers() const requires std::is_same_v<T, Elem>
124 ConstIterator(Base::container().begin()),
125 ConstIterator(Base::container().end()));
129 using Base::container;
131 using Iterator = Base::ConstIterator;
132 using ConstIterator = ConstPointerIterator<typename Base::ConstIterator>;
133 using ConstIndexIterator = IndexFromPointerIterator<ConstIterator>;
160 void updateReferences(
const Elem* oldBase, std::size_t offset = 0)
162 const Elem* newBase = baseOfElemContainer();
164 auto& baseContainer = Base::container();
166 for (uint j = 0; j < baseContainer.size();
168 if (baseContainer.at(j) !=
nullptr) {
170 baseContainer.at(j) - oldBase;
173 baseContainer.at(j) = (Elem*) newBase + diff + offset;
190 void updateReferences(
const std::vector<uint>& newIndices)
192 const Elem* base = baseOfElemContainer();
194 auto& baseContainer = Base::container();
196 for (uint j = 0; j < baseContainer.size(); ++j) {
197 if (baseContainer.at(j) !=
nullptr) {
198 size_t diff = baseContainer.at(j) - base;
199 if (newIndices[diff] == UINT_NULL) {
200 baseContainer.at(j) =
nullptr;
203 baseContainer.at(j) = (Elem*) base + newIndices[diff];
210 const Elem* baseOfElemContainer()
const
212 return &(Base::parentElement()
214 ->template element<Elem::ELEMENT_ID>(0));