VTK  9.6.20260403
vtkStridedArray.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
54
55#ifndef vtkStridedArray_h
56#define vtkStridedArray_h
57
58#include "vtkCommonCoreModule.h" // for export macro
59#include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
60#include "vtkImplicitArray.h"
61#include "vtkSmartPointer.h" // for vtkSmartPointer
62#include "vtkStridedImplicitBackend.h" // for the array backend
63
64VTK_ABI_NAMESPACE_BEGIN
66VTK_ABI_NAMESPACE_END
67
68VTK_ABI_NAMESPACE_BEGIN
69template <class ValueTypeT>
70class VTKCOMMONCORE_EXPORT vtkStridedArray
71#ifndef __VTK_WRAP__
72 : public vtkImplicitArray<vtkStridedImplicitBackend<ValueTypeT>, vtkArrayTypes::VTK_STRIDED_ARRAY>
73{
74 using ImplicitArrayType =
76#else // Fake the superclass for the wrappers.
77 : public vtkDataArray
78{
79 using ImplicitArrayType = vtkDataArray;
80#endif
81public:
84#ifndef __VTK_WRAP__
85 using typename Superclass::ArrayTypeTag;
86 using typename Superclass::DataTypeTag;
87 using typename Superclass::ValueType;
88#else
89 using ValueType = ValueTypeT;
90#endif
91
93
94 // This macro expands to the set of method declarations that
95 // make up the interface of vtkImplicitArray, which is ignored
96 // by the wrappers.
97#if defined(__VTK_WRAP__) || defined(__WRAP_GCCXML__)
99#endif
100
105 {
106 return static_cast<vtkStridedArray<ValueType>*>(Superclass::FastDownCast(source));
107 }
108
110
117 vtkAbstractBuffer* buffer, vtkIdType stride, int components, vtkIdType offset);
118 void ConstructBackend(vtkAbstractBuffer* buffer, vtkIdType stride, int components);
121
123
129 const ValueType* buffer, vtkIdType stride, int components, vtkIdType offset);
130 void ConstructBackend(const ValueType* buffer, vtkIdType stride, int components);
131 void ConstructBackend(const ValueType* buffer, vtkIdType stride);
133
139 vtkAbstractBuffer* GetBufferSource() const { return this->BufferSource; }
140
144 const ValueType* GetBuffer() const
145 {
146 return const_cast<vtkStridedArray<ValueType>*>(this)->GetBackend()->GetBuffer();
147 }
148
153 {
154 return const_cast<vtkStridedArray<ValueType>*>(this)->GetBackend()->GetStride();
155 }
156
161 {
162 return const_cast<vtkStridedArray<ValueType>*>(this)->GetBackend()->GetOffset();
163 }
164
165protected:
166 vtkStridedArray() = default;
167 ~vtkStridedArray() override = default;
168
169private:
170 vtkStridedArray(const vtkStridedArray&) = delete;
171 void operator=(const vtkStridedArray&) = delete;
172
178};
179
180// Declare vtkArrayDownCast implementations for STRIDED arrays:
182
183VTK_ABI_NAMESPACE_END
184
185// This macro is used by the subclasses to create dummy
186// declarations for these functions such that the wrapper
187// can see them. The wrappers ignore vtkStridedArray.
188#define vtkCreateStridedWrappedArrayInterface(T) \
189 vtkCreateImplicitWrappedArrayInterface(T); \
190 void ConstructBackend( \
191 vtkAbstractBuffer* buffer, vtkIdType stride, int components, vtkIdType offset); \
192 void ConstructBackend(vtkAbstractBuffer* buffer, vtkIdType stride, int components); \
193 void ConstructBackend(vtkAbstractBuffer* buffer, vtkIdType stride); \
194 void ConstructBackend(const T* buffer, vtkIdType stride, int components, vtkIdType offset); \
195 void ConstructBackend(const T* buffer, vtkIdType stride, int components); \
196 void ConstructBackend(const T* buffer, vtkIdType stride); \
197 const T* GetBuffer() const; \
198 vtkAbstractBuffer* GetBufferSource() const; \
199 vtkIdType GetStride() const; \
200 vtkIdType GetOffset() const;
201
202#endif // vtkStridedArray_h
203
204// This portion must be OUTSIDE the include blockers. This is used to tell
205// libraries other than vtkCommonCore that instantiations of
206// vtkStridedArray can be found externally. This prevents each library
207// from instantiating these on their own.
208#ifdef VTK_STRIDED_ARRAY_INSTANTIATING
209#define VTK_STRIDED_ARRAY_INSTANTIATE(T) \
210 namespace vtkDataArrayPrivate \
211 { \
212 VTK_ABI_NAMESPACE_BEGIN \
213 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkStridedArray<T>, double); \
214 VTK_ABI_NAMESPACE_END \
215 } \
216 VTK_ABI_NAMESPACE_BEGIN \
217 template class VTKCOMMONCORE_EXPORT vtkStridedArray<T>; \
218 VTK_ABI_NAMESPACE_END
219// We only provide these specializations for the 64-bit integer types, since
220// other types can reuse the double-precision mechanism in
221// vtkDataArray::GetRange without losing precision.
222#define VTK_STRIDED_ARRAY_INSTANTIATE_VALUERANGE(T) \
223 namespace vtkDataArrayPrivate \
224 { \
225 VTK_ABI_NAMESPACE_BEGIN \
226 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkStridedArray<T>, T); \
227 VTK_ABI_NAMESPACE_END \
228 }
229#elif defined(VTK_USE_EXTERN_TEMPLATE)
230#ifndef VTK_STRIDED_ARRAY_EXTERN
231#define VTK_STRIDED_ARRAY_EXTERN
232#ifdef _MSC_VER
233#pragma warning(push)
234// The following is needed when the vtkStridedArray is declared
235// dllexport and is used from another class in vtkCommonCore
236#pragma warning(disable : 4910) // extern and dllexport incompatible
237#endif
238VTK_ABI_NAMESPACE_BEGIN
239vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkStridedArray);
240VTK_ABI_NAMESPACE_END
241
242namespace vtkDataArrayPrivate
243{
244VTK_ABI_NAMESPACE_BEGIN
245
246// These are instantiated in vtkGenericDataArrayValueRange${i}.cxx
251// These are instantiated by vtkStridedArrayInstantiate_double.cxx.inc, e.t.c.
265
266VTK_ABI_NAMESPACE_END
267} // namespace vtkDataArrayPrivate
268
269#ifdef _MSC_VER
270#pragma warning(pop)
271#endif
272#endif // VTK_STRIDED_ARRAY_EXTERN
273
274// The following clause is only for MSVC
275#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
276#pragma warning(push)
277
278// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
279#pragma warning(disable : 4091)
280
281// Compiler-specific extension warning.
282#pragma warning(disable : 4231)
283
284// We need to disable warning 4910 and do an extern dllexport
285// anyway. When deriving new arrays from an
286// instantiation of this template the compiler does an explicit
287// instantiation of the base class. From outside the vtkCommon
288// library we block this using an extern dllimport instantiation.
289// For classes inside vtkCommon we should be able to just do an
290// extern instantiation, but VS 2008 complains about missing
291// definitions. We cannot do an extern dllimport inside vtkCommon
292// since the symbols are local to the dll. An extern dllexport
293// seems to be the only way to convince VS 2008 to do the right
294// thing, so we just disable the warning.
295#pragma warning(disable : 4910) // extern and dllexport incompatible
296
297// Use an "extern explicit instantiation" to give the class a DLL
298// interface. This is a compiler-specific extension.
299VTK_ABI_NAMESPACE_BEGIN
300vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkStridedArray);
301VTK_ABI_NAMESPACE_END
302
303#pragma warning(pop)
304
305#endif
306
307// VTK-HeaderTest-Exclude: vtkStridedArray.h
Abstract superclass for all arrays.
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
Abstract base class for vtkBuffer providing buffer protocol support.
Hold a reference to a vtkObjectBase instance.
A utility array for wrapping a strided buffer in implicit arrays.
void ConstructBackend(vtkAbstractBuffer *buffer, vtkIdType stride)
Set the parameters for the strided backend using a vtkBuffer (via vtkAbstractBuffer) as the buffer so...
vtkAbstractBuffer * GetBufferSource() const
Get the buffer source object, if one was provided via the vtkAbstractBuffer overload of ConstructBack...
const ValueType * GetBuffer() const
Get the buffer of the strided backend.
void ConstructBackend(const ValueType *buffer, vtkIdType stride, int components, vtkIdType offset)
Set the parameters for the strided backend from a raw pointer.
vtkIdType GetStride() const
Get the stride of the strided backend.
~vtkStridedArray() override=default
static vtkStridedArray< ValueType > * FastDownCast(vtkAbstractArray *source)
A faster alternative to SafeDownCast for downcasting vtkAbstractArrays.
void ConstructBackend(vtkAbstractBuffer *buffer, vtkIdType stride, int components, vtkIdType offset)
Set the parameters for the strided backend using a vtkBuffer (via vtkAbstractBuffer) as the buffer so...
vtkStridedArray()=default
static vtkStridedArray * New()
void ConstructBackend(const ValueType *buffer, vtkIdType stride, int components)
Set the parameters for the strided backend from a raw pointer.
void ConstructBackend(const ValueType *buffer, vtkIdType stride)
Set the parameters for the strided backend from a raw pointer.
vtkIdType GetOffset() const
Get the offset of the strided backend.
vtkImplicitArrayTypeMacro(SelfType, ImplicitArrayType)
vtkStridedArray< ValueTypeT > SelfType
void ConstructBackend(vtkAbstractBuffer *buffer, vtkIdType stride, int components)
Set the parameters for the strided backend using a vtkBuffer (via vtkAbstractBuffer) as the buffer so...
#define vtkArrayDownCast_TemplateFastCastMacro(ArrayT)
Same as vtkArrayDownCast_FastCastMacro, but treats ArrayT as a single-parameter template (the paramet...
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_DECLARE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType)
#define vtkCreateImplicitWrappedArrayInterface(T)
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition vtkType.h:458
int vtkIdType
Definition vtkType.h:363
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition vtkType.h:411
@ VTK_STRIDED_ARRAY
Definition vtkType.h:96