VTK  9.6.20260315
vtkConstantArray.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// Funded by CEA, DAM, DIF, F-91297 Arpajon, France
14
15#ifndef vtkConstantArray_h
16#define vtkConstantArray_h
17
18#include "vtkCommonCoreModule.h" // for export macro
19#include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
20#include "vtkConstantImplicitBackend.h" // for the array backend
21#include "vtkImplicitArray.h"
22
23VTK_ABI_NAMESPACE_BEGIN
24template <class ValueTypeT>
25class VTKCOMMONCORE_EXPORT vtkConstantArray
26#ifndef __VTK_WRAP__
27 : public vtkImplicitArray<vtkConstantImplicitBackend<ValueTypeT>,
28 vtkArrayTypes::VTK_CONSTANT_ARRAY>
29{
30 using ImplicitArrayType =
32#else // Fake the superclass for the wrappers.
33 : public vtkDataArray
34{
35 using ImplicitArrayType = vtkDataArray;
36#endif
37public:
40#ifndef __VTK_WRAP__
41 using typename Superclass::ArrayTypeTag;
42 using typename Superclass::DataTypeTag;
43 using typename Superclass::ValueType;
44#else
45 using ValueType = ValueTypeT;
46#endif
47
49
50 // This macro expands to the set of method declarations that
51 // make up the interface of vtkImplicitArray, which is ignored
52 // by the wrappers.
53#if defined(__VTK_WRAP__) || defined(__WRAP_GCCXML__)
55#endif
56
61 {
62 return static_cast<vtkConstantArray<ValueType>*>(Superclass::FastDownCast(source));
63 }
64
69
74 {
75 return const_cast<vtkConstantArray<ValueType>*>(this)->GetBackend()->Value;
76 }
77
78protected:
79 vtkConstantArray() = default;
80 ~vtkConstantArray() override = default;
81
82private:
83 vtkConstantArray(const vtkConstantArray&) = delete;
84 void operator=(const vtkConstantArray&) = delete;
85};
86
87// Declare vtkArrayDownCast implementations for Constant arrays:
89
90VTK_ABI_NAMESPACE_END
91
92// This macro is used by the subclasses to create dummy
93// declarations for these functions such that the wrapper
94// can see them. The wrappers ignore vtkConstantArray.
95#define vtkCreateConstantWrappedArrayInterface(T) \
96 vtkCreateImplicitWrappedArrayInterface(T); \
97 void ConstructBackend(T value); \
98 T GetConstantValue() const;
99
100#endif // vtkConstantArray_h
101
102// This portion must be OUTSIDE the include blockers. This is used to tell
103// libraries other than vtkCommonCore that instantiations of
104// vtkConstantArray can be found externally. This prevents each library
105// from instantiating these on their own.
106#ifdef VTK_CONSTANT_ARRAY_INSTANTIATING
107#define VTK_CONSTANT_ARRAY_INSTANTIATE(T) \
108 namespace vtkDataArrayPrivate \
109 { \
110 VTK_ABI_NAMESPACE_BEGIN \
111 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkConstantArray<T>, double); \
112 VTK_ABI_NAMESPACE_END \
113 } \
114 VTK_ABI_NAMESPACE_BEGIN \
115 template class VTKCOMMONCORE_EXPORT vtkConstantArray<T>; \
116 VTK_ABI_NAMESPACE_END
117// We only provide these specializations for the 64-bit integer types, since
118// other types can reuse the double-precision mechanism in
119// vtkDataArray::GetRange without losing precision.
120#define VTK_CONSTANT_ARRAY_INSTANTIATE_VALUERANGE(T) \
121 namespace vtkDataArrayPrivate \
122 { \
123 VTK_ABI_NAMESPACE_BEGIN \
124 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkConstantArray<T>, T); \
125 VTK_ABI_NAMESPACE_END \
126 }
127#elif defined(VTK_USE_EXTERN_TEMPLATE)
128#ifndef VTK_CONSTANT_ARRAY_EXTERN
129#define VTK_CONSTANT_ARRAY_EXTERN
130#ifdef _MSC_VER
131#pragma warning(push)
132// The following is needed when the vtkConstantArray is declared
133// dllexport and is used from another class in vtkCommonCore
134#pragma warning(disable : 4910) // extern and dllexport incompatible
135#endif
136VTK_ABI_NAMESPACE_BEGIN
137vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkConstantArray);
138VTK_ABI_NAMESPACE_END
139
140namespace vtkDataArrayPrivate
141{
142VTK_ABI_NAMESPACE_BEGIN
143
144// These are instantiated in vtkGenericDataArrayValueRange${i}.cxx
149// These are instantiated by vtkConstantArrayInstantiate_double.cxx.inc, e.t.c.
163
164VTK_ABI_NAMESPACE_END
165} // namespace vtkDataArrayPrivate
166
167#ifdef _MSC_VER
168#pragma warning(pop)
169#endif
170#endif // VTK_CONSTANT_ARRAY_EXTERN
171
172// The following clause is only for MSVC
173#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
174#pragma warning(push)
175
176// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
177#pragma warning(disable : 4091)
178
179// Compiler-specific extension warning.
180#pragma warning(disable : 4231)
181
182// We need to disable warning 4910 and do an extern dllexport
183// anyway. When deriving new arrays from an
184// instantiation of this template the compiler does an explicit
185// instantiation of the base class. From outside the vtkCommon
186// library we block this using an extern dllimport instantiation.
187// For classes inside vtkCommon we should be able to just do an
188// extern instantiation, but VS 2008 complains about missing
189// definitions. We cannot do an extern dllimport inside vtkCommon
190// since the symbols are local to the dll. An extern dllexport
191// seems to be the only way to convince VS 2008 to do the right
192// thing, so we just disable the warning.
193#pragma warning(disable : 4910) // extern and dllexport incompatible
194
195// Use an "extern explicit instantiation" to give the class a DLL
196// interface. This is a compiler-specific extension.
197VTK_ABI_NAMESPACE_BEGIN
198vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkConstantArray);
199VTK_ABI_NAMESPACE_END
200
201#pragma warning(pop)
202
203#endif
204
205// VTK-HeaderTest-Exclude: vtkConstantArray.h
Abstract superclass for all arrays.
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
A utility array for wrapping constant functions in implicit arrays.
vtkConstantArray()=default
static vtkConstantArray< ValueType > * FastDownCast(vtkAbstractArray *source)
A faster alternative to SafeDownCast for downcasting vtkAbstractArrays.
ValueType GetConstantValue() const
Get the constant value stored in this array.
static vtkConstantArray * New()
void ConstructBackend(ValueType value)
Set the constant value for this array.
~vtkConstantArray() override=default
vtkConstantArray< ValueTypeT > SelfType
vtkImplicitArrayTypeMacro(SelfType, ImplicitArrayType)
#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
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition vtkType.h:411
@ VTK_CONSTANT_ARRAY
Definition vtkType.h:93