VTK  9.4.20250102
vtkDataArrayRange.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
14#ifndef vtkDataArrayRange_h
15#define vtkDataArrayRange_h
16
18#include "vtkDataArray.h"
19#include "vtkDataArrayMeta.h"
24#include "vtkMeta.h"
25#include "vtkSmartPointer.h"
26
27#include <cassert>
28#include <iterator>
29#include <type_traits>
30
85
86namespace vtk
87{
88namespace detail
89{
90VTK_ABI_NAMESPACE_BEGIN
91
92// Internal detail: This utility is not directly needed by users of
93// DataArrayRange.
94//
95// These classes are used to detect when specializations exist for a given
96// array type. They are necessary because given:
97//
98// template <typename ArrayType> class SomeTemplateClass;
99// template <typename T> class SomeTemplateClass<vtkAOSDataArrayTemplate<T>>;
100//
101// SomeTemplateClass<vtkFloatArray> will pick the generic version, as ArrayType
102// is a better match than vtkAOSDataArrayTemplate<T>. This class works around
103// that by using Declare[Tuple|Value]RangeSpecialization functions that map an
104// input ArrayTypePtr and tuple size to a specific version of the appropriate
105// Range.
106template <typename ArrayTypePtr, ComponentIdType TupleSize>
108{
109private:
110 // Allow this to work with vtkNew, vtkSmartPointer, etc.
111 using ArrayType = typename detail::StripPointers<ArrayTypePtr>::type;
112
113 static_assert(detail::IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
114 static_assert(detail::IsVtkDataArray<ArrayType>::value, "Invalid array type.");
115
116public:
117 using type =
118 typename std::decay<decltype(vtk::detail::DeclareTupleRangeSpecialization<ArrayType, TupleSize>(
119 std::declval<ArrayType*>()))>::type;
120};
121
122template <typename ArrayTypePtr, ComponentIdType TupleSize,
123 typename ForceValueTypeForVtkDataArray = double>
125{
126private:
127 // Allow this to work with vtkNew, vtkSmartPointer, etc.
128 using ArrayType = typename detail::StripPointers<ArrayTypePtr>::type;
129
130 static_assert(detail::IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
131 static_assert(detail::IsVtkDataArray<ArrayType>::value, "Invalid array type.");
132
133public:
134 using type =
135 typename std::remove_reference<decltype(vtk::detail::DeclareValueRangeSpecialization<ArrayType,
136 TupleSize, ForceValueTypeForVtkDataArray>(std::declval<ArrayType*>()))>::type;
137};
138
139VTK_ABI_NAMESPACE_END
140} // end namespace detail
141
248VTK_ABI_NAMESPACE_BEGIN
249template <ComponentIdType TupleSize = detail::DynamicTupleSize,
250 typename ArrayTypePtr = vtkDataArray*>
251VTK_ITER_INLINE auto DataArrayTupleRange(const ArrayTypePtr& array, TupleIdType start = -1,
253{
254 // Lookup specializations:
256
257 assert(array);
258
259 return RangeType(array, start < 0 ? 0 : start, end < 0 ? array->GetNumberOfTuples() : end);
260}
261
359template <ComponentIdType TupleSize = detail::DynamicTupleSize,
360 typename ForceValueTypeForVtkDataArray = double, typename ArrayTypePtr = vtkDataArray*>
362 const ArrayTypePtr& array, ValueIdType start = -1, ValueIdType end = -1) ->
364{
365 using RangeType =
367
368 assert(array);
369
370 return RangeType(array, start < 0 ? 0 : start, end < 0 ? array->GetNumberOfValues() : end);
371}
372
373VTK_ABI_NAMESPACE_END
374} // end namespace vtk
375
377
378#endif // vtkDataArrayRange_h
379
380// VTK-HeaderTest-Exclude: vtkDataArrayRange.h
abstract superclass for arrays of numeric data
ValueRange< AOSArrayType, TupleSize, ForceValueTypeForVtkDataArray > DeclareValueRangeSpecialization(ArrayType *)
static constexpr ComponentIdType DynamicTupleSize
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
VTK_ITER_INLINE auto DataArrayTupleRange(const ArrayTypePtr &array, TupleIdType start=-1, TupleIdType end=-1) -> typename detail::SelectTupleRange< ArrayTypePtr, TupleSize >::type
Generate an stl and for-range compatible range of tuple iterators from a vtkDataArray.
vtkIdType ValueIdType
vtkIdType TupleIdType
int ComponentIdType
VTK_ITER_INLINE auto DataArrayValueRange(const ArrayTypePtr &array, ValueIdType start=-1, ValueIdType end=-1) -> typename detail::SelectValueRange< ArrayTypePtr, TupleSize, ForceValueTypeForVtkDataArray >::type
Generate an stl and for-range compatible range of flat AOS iterators from a vtkDataArray.
typename std::decay< decltype(vtk::detail::DeclareTupleRangeSpecialization< ArrayType, TupleSize >(std::declval< ArrayType * >()))>::type type
typename std::remove_reference< decltype(vtk::detail::DeclareValueRangeSpecialization< ArrayType, TupleSize, ForceValueTypeForVtkDataArray >(std::declval< ArrayType * >()))>::type type
This file contains a variety of metaprogramming constructs for working with vtkDataArrays.
#define VTK_ITER_OPTIMIZE_START
#define VTK_ITER_INLINE
#define VTK_ITER_OPTIMIZE_END
This file contains a variety of metaprogramming constructs for working with vtk types.