VTK  9.3.1
vtkSMPToolsInternal.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 
4 #ifndef vtkSMPToolsInternal_h
5 #define vtkSMPToolsInternal_h
6 
7 #include <iterator> // For std::advance
8 
9 #ifndef DOXYGEN_SHOULD_SKIP_THIS
10 namespace vtk
11 {
12 namespace detail
13 {
14 namespace smp
15 {
16 VTK_ABI_NAMESPACE_BEGIN
17 
18 template <typename InputIt, typename OutputIt, typename Functor>
19 class UnaryTransformCall
20 {
21 protected:
22  InputIt In;
23  OutputIt Out;
24  Functor& Transform;
25 
26 public:
27  UnaryTransformCall(InputIt _in, OutputIt _out, Functor& _transform)
28  : In(_in)
29  , Out(_out)
30  , Transform(_transform)
31  {
32  }
33 
34  void Execute(vtkIdType begin, vtkIdType end)
35  {
36  InputIt itIn(In);
37  OutputIt itOut(Out);
38  std::advance(itIn, begin);
39  std::advance(itOut, begin);
40  for (vtkIdType it = begin; it < end; it++)
41  {
42  *itOut = Transform(*itIn);
43  ++itIn;
44  ++itOut;
45  }
46  }
47 };
48 
49 template <typename InputIt1, typename InputIt2, typename OutputIt, typename Functor>
50 class BinaryTransformCall : public UnaryTransformCall<InputIt1, OutputIt, Functor>
51 {
52  InputIt2 In2;
53 
54 public:
55  BinaryTransformCall(InputIt1 _in1, InputIt2 _in2, OutputIt _out, Functor& _transform)
56  : UnaryTransformCall<InputIt1, OutputIt, Functor>(_in1, _out, _transform)
57  , In2(_in2)
58  {
59  }
60 
61  void Execute(vtkIdType begin, vtkIdType end)
62  {
63  InputIt1 itIn1(this->In);
64  InputIt2 itIn2(In2);
65  OutputIt itOut(this->Out);
66  std::advance(itIn1, begin);
67  std::advance(itIn2, begin);
68  std::advance(itOut, begin);
69  for (vtkIdType it = begin; it < end; it++)
70  {
71  *itOut = this->Transform(*itIn1, *itIn2);
72  ++itIn1;
73  ++itIn2;
74  ++itOut;
75  }
76  }
77 };
78 
79 template <typename T>
80 struct FillFunctor
81 {
82  const T& Value;
83 
84 public:
85  FillFunctor(const T& _value)
86  : Value(_value)
87  {
88  }
89 
90  T operator()(T vtkNotUsed(inValue)) { return Value; }
91 };
92 
93 VTK_ABI_NAMESPACE_END
94 
95 } // namespace smp
96 } // namespace detail
97 } // namespace vtk
98 #endif // DOXYGEN_SHOULD_SKIP_THIS
99 
100 #endif
101 /* VTK-HeaderTest-Exclude: vtkSMPToolsInternal.h */
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
int vtkIdType
Definition: vtkType.h:315