VTK  9.7.1
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
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 
23 VTK_ABI_NAMESPACE_BEGIN
24 template <class ValueTypeT>
25 class 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
37 public:
39  vtkImplicitArrayTypeMacro(SelfType, ImplicitArrayType);
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 
48  static vtkConstantArray* New();
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 
68  void ConstructBackend(ValueType value);
69 
74  {
75  return const_cast<vtkConstantArray<ValueType>*>(this)->GetBackend()->Value;
76  }
77 
81  bool IsBackendConstructed() const
82  {
83  return const_cast<vtkConstantArray<ValueType>*>(this)->GetBackend() != nullptr;
84  }
85 
86 protected:
87  vtkConstantArray() = default;
88  ~vtkConstantArray() override = default;
89 
90 private:
91  vtkConstantArray(const vtkConstantArray&) = delete;
92  void operator=(const vtkConstantArray&) = delete;
93 };
94 
95 // Declare vtkArrayDownCast implementations for Constant arrays:
97 
98 VTK_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
145 VTK_ABI_NAMESPACE_BEGIN
146 vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkConstantArray);
147 VTK_ABI_NAMESPACE_END
148 
149 namespace vtkDataArrayPrivate
150 {
151 VTK_ABI_NAMESPACE_BEGIN
152 
153 // These are instantiated in vtkGenericDataArrayValueRange${i}.cxx
155 VTK_DECLARE_VALUERANGE_ARRAYTYPE(vtkConstantArray<unsigned long>, unsigned long)
157 VTK_DECLARE_VALUERANGE_ARRAYTYPE(vtkConstantArray<unsigned long long>, unsigned long long)
158 // These are instantiated by vtkConstantArrayInstantiate_double.cxx.inc, e.t.c.
165 VTK_DECLARE_VALUERANGE_ARRAYTYPE(vtkConstantArray<unsigned short>, double)
171 VTK_DECLARE_VALUERANGE_ARRAYTYPE(vtkConstantArray<unsigned long long>, double)
172 
173 VTK_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.
206 VTK_ABI_NAMESPACE_BEGIN
207 vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkConstantArray);
208 VTK_ABI_NAMESPACE_END
209 
210 #pragma warning(pop)
211 
212 #endif
213 
214 // VTK-HeaderTest-Exclude: vtkConstantArray.h
static vtkConstantArray< ValueType > * FastDownCast(vtkAbstractArray *source)
A faster alternative to SafeDownCast for downcasting vtkAbstractArrays.
vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkConstantArray)
Abstract superclass for all arrays.
vtkImplicitArrayTypeMacro(SelfType, GenericDataArrayType)
A utility array for wrapping constant functions in implicit arrays.
#define VTK_DECLARE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType)
bool IsBackendConstructed() const
Check whether the backend has been constructed.
std::shared_ptr< BackendT > GetBackend()
Setter/Getter for Backend.
vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkArrayIteratorTemplate)
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
A read only array class that wraps an implicit function from integers to any value type supported by ...
ValueType GetConstantValue() const
Get the constant value stored in this array.
vtkArrayDownCast_TemplateFastCastMacro(vtkConstantArray)
#define vtkCreateImplicitWrappedArrayInterface(T)
static vtkImplicitArray * New()
void ConstructBackend(Params &&...params)
Utility method for setting backend parameterization directly.