Expand usability of vtk::Range(compDS) references.
Rather than return just vtkDataObject*
from the range iterators, return a new vtk::CompositeDataSetNodeReference
object that does everything the older vtkCompositeDataIterator
s did (except iterate in reverse).
From the new NodeReference
documentation:
A reference proxy into a vtkCompositeDataSet, obtained by dereferencing an
iterator from the vtk::Range(vtkCompositeDataSet*) overloads.
This proxy may be used as a pointer, in which case it will forward the
currently pointed-to vtkDataObject*. This means that the following code is still
legal:
for (auto node : vtk::Range(cds))
{ // decltype(node) == CompositeDataSetNodeReference
if (node) // same as: if (node.GetDataObject() != nullptr)
{
assert(node->IsA("vtkDataObject")); // node.GetDataObject()->IsA(...)
node = nullptr; // node.SetDataObject(nullptr)
}
}
for (vtkDataObject *dObj : vtk::Range(cds))
{
// Work with dObj
}
This allows for simple access to the objects in the composite dataset. If
more advanced operations are required, the CompositeDataSetNodeReference can:
- Access the current vtkDataObject*:
vtkDataObject* NodeReference::GetDataObject() const
-
NodeReference::operator vtkDataObject* () const
(implicit conversion) -
vtkDataObject* NodeReference::operator->() const
(arrow operator)
- Replace the current vtkDataObject* in the composite dataset:
void NodeReference::SetDataObject(vtkDataObject*)
-
NodeReference& NodeReference::operator=(vtkDataObject*)
(assignment)
- SetGet the vtkDataObject at the same position in another composite dataset
void NodeReference::SetDataObject(vtkCompositeDataSet*, vtkDataObject*)
vtkDataObject* NodeReference::GetDataObject(vtkCompositeDataSet*) const
- Check and access node metadata (if any):
bool NodeReference::HasMetaData() const
vtkInformation* NodeReference::GetMetaData() const
- Get the current flat index within the parent range:
- unsigned int NodeReference::GetFlatIndex() const`
The NodeReference shares state with the OwnerType iterator that
generates. Incrementing or destroying the parent iterator will invalidate
the reference. In debugging builds, these misuses will be caught via runtime
assertions.