VTK  9.3.0
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>
124{
125private:
126 // Allow this to work with vtkNew, vtkSmartPointer, etc.
127 using ArrayType = typename detail::StripPointers<ArrayTypePtr>::type;
128
129 static_assert(detail::IsValidTupleSize<TupleSize>::value, "Invalid tuple size.");
130 static_assert(detail::IsVtkDataArray<ArrayType>::value, "Invalid array type.");
131
132public:
133 using type =
134 typename std::remove_reference<decltype(vtk::detail::DeclareValueRangeSpecialization<ArrayType,
135 TupleSize>(std::declval<ArrayType*>()))>::type;
136};
137
138VTK_ABI_NAMESPACE_END
139} // end namespace detail
140
245VTK_ABI_NAMESPACE_BEGIN
246template <ComponentIdType TupleSize = detail::DynamicTupleSize,
247 typename ArrayTypePtr = vtkDataArray*>
248VTK_ITER_INLINE auto DataArrayTupleRange(const ArrayTypePtr& array, TupleIdType start = -1,
250{
251 // Lookup specializations:
253
254 assert(array);
255
256 return RangeType(array, start < 0 ? 0 : start, end < 0 ? array->GetNumberOfTuples() : end);
257}
258
356template <ComponentIdType TupleSize = detail::DynamicTupleSize,
357 typename ArrayTypePtr = vtkDataArray*>
358VTK_ITER_INLINE auto DataArrayValueRange(const ArrayTypePtr& array, ValueIdType start = -1,
360{
362
363 assert(array);
364
365 return RangeType(array, start < 0 ? 0 : start, end < 0 ? array->GetNumberOfValues() : end);
366}
367
368VTK_ABI_NAMESPACE_END
369} // end namespace vtk
370
372
373#endif // vtkDataArrayRange_h
374
375// VTK-HeaderTest-Exclude: vtkDataArrayRange.h
abstract superclass for arrays of numeric data
static constexpr ComponentIdType DynamicTupleSize
ValueRange< AOSArrayType, TupleSize > DeclareValueRangeSpecialization(ArrayType *)
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 >::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 >(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.