VTK  9.6.20260407
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
82 {
83 return const_cast<vtkConstantArray<ValueType>*>(this)->GetBackend() != nullptr;
84 }
85
86protected:
87 vtkConstantArray() = default;
88 ~vtkConstantArray() override = default;
89
90private:
91 vtkConstantArray(const vtkConstantArray&) = delete;
92 void operator=(const vtkConstantArray&) = delete;
93};
94
95// Declare vtkArrayDownCast implementations for Constant arrays:
97
98VTK_ABI_NAMESPACE_END
99
100// This macro is used by the subclasses to create dummy
101// declarations for these functions such that the wrapper
102// can see them. The wrappers ignore vtkConstantArray.
103#define vtkCreateConstantWrappedArrayInterface(T) \
104 vtkCreateImplicitWrappedArrayInterface(T); \
105 void ConstructBackend(T value); \
106 T GetConstantValue() const; \
107 bool IsBackendConstructed() const;
108
109#endif // vtkConstantArray_h
110
111// This portion must be OUTSIDE the include blockers. This is used to tell
112// libraries other than vtkCommonCore that instantiations of
113// vtkConstantArray can be found externally. This prevents each library
114// from instantiating these on their own.
115#ifdef VTK_CONSTANT_ARRAY_INSTANTIATING
116#define VTK_CONSTANT_ARRAY_INSTANTIATE(T) \
117 namespace vtkDataArrayPrivate \
118 { \
119 VTK_ABI_NAMESPACE_BEGIN \
120 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkConstantArray<T>, double); \
121 VTK_ABI_NAMESPACE_END \
122 } \
123 VTK_ABI_NAMESPACE_BEGIN \
124 template class VTKCOMMONCORE_EXPORT vtkConstantArray<T>; \
125 VTK_ABI_NAMESPACE_END
126// We only provide these specializations for the 64-bit integer types, since
127// other types can reuse the double-precision mechanism in
128// vtkDataArray::GetRange without losing precision.
129#define VTK_CONSTANT_ARRAY_INSTANTIATE_VALUERANGE(T) \
130 namespace vtkDataArrayPrivate \
131 { \
132 VTK_ABI_NAMESPACE_BEGIN \
133 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkConstantArray<T>, T); \
134 VTK_ABI_NAMESPACE_END \
135 }
136#elif defined(VTK_USE_EXTERN_TEMPLATE)
137#ifndef VTK_CONSTANT_ARRAY_EXTERN
138#define VTK_CONSTANT_ARRAY_EXTERN
139#ifdef _MSC_VER
140#pragma warning(push)
141// The following is needed when the vtkConstantArray is declared
142// dllexport and is used from another class in vtkCommonCore
143#pragma warning(disable : 4910) // extern and dllexport incompatible
144#endif
145VTK_ABI_NAMESPACE_BEGIN
146vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkConstantArray);
147VTK_ABI_NAMESPACE_END
148
149namespace vtkDataArrayPrivate
150{
151VTK_ABI_NAMESPACE_BEGIN
152
153// These are instantiated in vtkGenericDataArrayValueRange${i}.cxx
158// These are instantiated by vtkConstantArrayInstantiate_double.cxx.inc, e.t.c.
172
173VTK_ABI_NAMESPACE_END
174} // namespace vtkDataArrayPrivate
175
176#ifdef _MSC_VER
177#pragma warning(pop)
178#endif
179#endif // VTK_CONSTANT_ARRAY_EXTERN
180
181// The following clause is only for MSVC
182#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
183#pragma warning(push)
184
185// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
186#pragma warning(disable : 4091)
187
188// Compiler-specific extension warning.
189#pragma warning(disable : 4231)
190
191// We need to disable warning 4910 and do an extern dllexport
192// anyway. When deriving new arrays from an
193// instantiation of this template the compiler does an explicit
194// instantiation of the base class. From outside the vtkCommon
195// library we block this using an extern dllimport instantiation.
196// For classes inside vtkCommon we should be able to just do an
197// extern instantiation, but VS 2008 complains about missing
198// definitions. We cannot do an extern dllimport inside vtkCommon
199// since the symbols are local to the dll. An extern dllexport
200// seems to be the only way to convince VS 2008 to do the right
201// thing, so we just disable the warning.
202#pragma warning(disable : 4910) // extern and dllexport incompatible
203
204// Use an "extern explicit instantiation" to give the class a DLL
205// interface. This is a compiler-specific extension.
206VTK_ABI_NAMESPACE_BEGIN
207vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkConstantArray);
208VTK_ABI_NAMESPACE_END
209
210#pragma warning(pop)
211
212#endif
213
214// 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
bool IsBackendConstructed() const
Check whether the backend has been constructed.
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