VTK  9.7.1
vtkStdFunctionArray.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
20 #ifndef vtkStdFunctionArray_h
21 #define vtkStdFunctionArray_h
22 
23 #include "vtkCommonCoreModule.h" // for export macro
24 #include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
25 #include "vtkImplicitArray.h"
26 
27 #include <functional>
28 
29 VTK_ABI_NAMESPACE_BEGIN
30 template <class ValueTypeT>
31 class VTK_DEPRECATED_IN_9_7_0("No longer needed") VTKCOMMONCORE_EXPORT vtkStdFunctionArray
32 #ifndef __VTK_WRAP__
33  : public vtkImplicitArray<std::function<ValueTypeT(int)>,
34  /* vtkArrayTypes::VTK_STD_FUNCTION_ARRAY */ 15>
35 {
37  /* vtkArrayTypes::VTK_STD_FUNCTION_ARRAY */ 15>;
38 #else // Fake the superclass for the wrappers.
39  : public vtkDataArray
40 {
41  using ImplicitArrayType = vtkDataArray;
42 #endif
43 public:
45  vtkImplicitArrayTypeMacro(SelfType, ImplicitArrayType);
46 #ifndef __VTK_WRAP__
47  using typename Superclass::ArrayTypeTag;
48  using typename Superclass::DataTypeTag;
49  using typename Superclass::ValueType;
50 #else
51  using ValueType = ValueTypeT;
52 #endif
53 
54  static vtkStdFunctionArray* New();
55 
56  // This macro expands to the set of method declarations that
57  // make up the interface of vtkImplicitArray, which is ignored
58  // by the wrappers.
59 #if defined(__VTK_WRAP__) || defined(__WRAP_GCCXML__)
61 #endif
62 
67  {
68  return static_cast<vtkStdFunctionArray<ValueType>*>(Superclass::FastDownCast(source));
69  }
70 
74  void ConstructBackend(std::function<ValueType(int)> func);
75 
76 protected:
77  vtkStdFunctionArray() = default;
78  ~vtkStdFunctionArray() override = default;
79 
80 private:
82  void operator=(const vtkStdFunctionArray&) = delete;
83 };
84 
85 // Declare vtkArrayDownCast implementations for StdFunction arrays:
87 
88 VTK_ABI_NAMESPACE_END
89 
90 // This macro is used by the subclasses to create dummy
91 // declarations for these functions such that the wrapper
92 // can see them. The wrappers ignore vtkStdFunctionArray.
93 #define vtkCreateStdFunctionWrappedArrayInterface(T) \
94  vtkCreateImplicitWrappedArrayInterface(T); \
95  void ConstructBackend(std::function<T(int)> func);
96 
97 #endif // vtkStdFunctionArray_h
98 
99 // This portion must be OUTSIDE the include blockers. This is used to tell
100 // libraries other than vtkCommonCore that instantiations of
101 // vtkStdFunctionArray can be found externally. This prevents each library
102 // from instantiating these on their own.
103 #ifdef VTK_STD_FUNCTION_ARRAY_INSTANTIATING
104 #define VTK_STD_FUNCTION_ARRAY_INSTANTIATE(T) \
105  namespace vtkDataArrayPrivate \
106  { \
107  VTK_ABI_NAMESPACE_BEGIN \
108  VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkStdFunctionArray<T>, double); \
109  VTK_ABI_NAMESPACE_END \
110  } \
111  VTK_ABI_NAMESPACE_BEGIN \
112  template class VTKCOMMONCORE_EXPORT vtkStdFunctionArray<T>; \
113  VTK_ABI_NAMESPACE_END
114 // We only provide these specializations for the 64-bit integer types, since
115 // other types can reuse the double-precision mechanism in
116 // vtkDataArray::GetRange without losing precision.
117 #define VTK_STD_FUNCTION_ARRAY_INSTANTIATE_VALUERANGE(T) \
118  namespace vtkDataArrayPrivate \
119  { \
120  VTK_ABI_NAMESPACE_BEGIN \
121  VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkStdFunctionArray<T>, T); \
122  VTK_ABI_NAMESPACE_END \
123  }
124 #elif defined(VTK_USE_EXTERN_TEMPLATE)
125 #ifndef VTK_STD_FUNCTION_ARRAY_EXTERN
126 #define VTK_STD_FUNCTION_ARRAY_EXTERN
127 #ifdef _MSC_VER
128 #pragma warning(push)
129 // The following is needed when the vtkStdFunctionArray is declared
130 // dllexport and is used from another class in vtkCommonCore
131 #pragma warning(disable : 4910) // extern and dllexport incompatible
132 #endif
133 VTK_ABI_NAMESPACE_BEGIN
134 vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkStdFunctionArray);
135 VTK_ABI_NAMESPACE_END
136 
137 namespace vtkDataArrayPrivate
138 {
139 VTK_ABI_NAMESPACE_BEGIN
140 
141 // These are instantiated in vtkGenericDataArrayValueRange${i}.cxx
143 VTK_DECLARE_VALUERANGE_ARRAYTYPE(vtkStdFunctionArray<unsigned long>, unsigned long)
145 VTK_DECLARE_VALUERANGE_ARRAYTYPE(vtkStdFunctionArray<unsigned long long>, unsigned long long)
146 // These are instantiated by vtkStdFunctionArrayInstantiate_double.cxx.inc, e.t.c.
159 VTK_DECLARE_VALUERANGE_ARRAYTYPE(vtkStdFunctionArray<unsigned long long>, double)
160 
161 VTK_ABI_NAMESPACE_END
162 } // namespace vtkDataArrayPrivate
163 
164 #ifdef _MSC_VER
165 #pragma warning(pop)
166 #endif
167 #endif // VTK_STD_FUNCTION_ARRAY_EXTERN
168 
169 // The following clause is only for MSVC
170 #elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
171 #pragma warning(push)
172 
173 // C4091: 'extern ' : ignored on left of 'int' when no variable is declared
174 #pragma warning(disable : 4091)
175 
176 // Compiler-specific extension warning.
177 #pragma warning(disable : 4231)
178 
179 // We need to disable warning 4910 and do an extern dllexport
180 // anyway. When deriving new arrays from an
181 // instantiation of this template the compiler does an explicit
182 // instantiation of the base class. From outside the vtkCommon
183 // library we block this using an extern dllimport instantiation.
184 // For classes inside vtkCommon we should be able to just do an
185 // extern instantiation, but VS 2008 complains about missing
186 // definitions. We cannot do an extern dllimport inside vtkCommon
187 // since the symbols are local to the dll. An extern dllexport
188 // seems to be the only way to convince VS 2008 to do the right
189 // thing, so we just disable the warning.
190 #pragma warning(disable : 4910) // extern and dllexport incompatible
191 
192 // Use an "extern explicit instantiation" to give the class a DLL
193 // interface. This is a compiler-specific extension.
194 VTK_ABI_NAMESPACE_BEGIN
195 vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkStdFunctionArray);
196 VTK_ABI_NAMESPACE_END
197 
198 #pragma warning(pop)
199 
200 #endif
201 
202 // VTK-HeaderTest-Exclude: vtkStdFunctionArray.h
Abstract superclass for all arrays.
vtkImplicitArrayTypeMacro(SelfType, GenericDataArrayType)
A utility array for wrapping std::function in implicit arrays.
#define VTK_DECLARE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType)
Base interface for all typed vtkDataArray subclasses.
vtkArrayDownCast_TemplateFastCastMacro(vtkStdFunctionArray)
static vtkStdFunctionArray< ValueType > * FastDownCast(vtkAbstractArray *source)
A faster alternative to SafeDownCast for downcasting vtkAbstractArrays.
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 ...
vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkStdFunctionArray)
#define vtkCreateImplicitWrappedArrayInterface(T)
static vtkImplicitArray * New()
#define VTK_DEPRECATED_IN_9_7_0(reason)
void ConstructBackend(Params &&...params)
Utility method for setting backend parameterization directly.