29 #include "vtkCommonCoreModule.h"
32 #include "vtkSMPThreadLocal.h"
33 #include "vtkSMPToolsInternal.h"
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 class vtkSMPTools_Has_Initialize
47 typedef char (&no_type)[1];
48 typedef char (&yes_type)[2];
49 template <
typename U,
void (U::*)()>
struct V {};
50 template <
typename U>
static yes_type check(V<U, &U::Initialize>*);
51 template <
typename U>
static no_type check(...);
53 static bool const value =
sizeof(check<T>(
nullptr)) ==
sizeof(yes_type);
57 class vtkSMPTools_Has_Initialize_const
59 typedef char (&no_type)[1];
60 typedef char (&yes_type)[2];
61 template <
typename U,
void (U::*)() const>
struct V {};
62 template <
typename U>
static yes_type check(V<U, &U::Initialize>*);
63 template <
typename U>
static no_type check(...);
65 static bool const value =
sizeof(check<T>(0)) ==
sizeof(yes_type);
68 template <
typename Functor,
bool Init>
69 struct vtkSMPTools_FunctorInternal;
71 template <
typename Functor>
72 struct vtkSMPTools_FunctorInternal<Functor, false>
75 vtkSMPTools_FunctorInternal(Functor& f): F(f) {}
82 vtk::detail::smp::vtkSMPTools_Impl_For(first, last, grain, *
this);
84 vtkSMPTools_FunctorInternal<Functor, false>& operator=(
85 const vtkSMPTools_FunctorInternal<Functor, false>&);
86 vtkSMPTools_FunctorInternal<Functor, false>(
87 const vtkSMPTools_FunctorInternal<Functor, false>&);
90 template <
typename Functor>
91 struct vtkSMPTools_FunctorInternal<Functor, true>
94 vtkSMPThreadLocal<unsigned char> Initialized;
95 vtkSMPTools_FunctorInternal(Functor& f): F(f), Initialized(0) {}
98 unsigned char& inited = this->Initialized.Local();
101 this->F.Initialize();
104 this->F(first, last);
108 vtk::detail::smp::vtkSMPTools_Impl_For(first, last, grain, *
this);
111 vtkSMPTools_FunctorInternal<Functor, true>& operator=(
112 const vtkSMPTools_FunctorInternal<Functor, true>&);
113 vtkSMPTools_FunctorInternal<Functor, true>(
114 const vtkSMPTools_FunctorInternal<Functor, true>&);
117 template <
typename Functor>
118 class vtkSMPTools_Lookup_For
122 typedef vtkSMPTools_FunctorInternal<Functor, init>
type;
125 template <
typename Functor>
126 class vtkSMPTools_Lookup_For<Functor const>
130 typedef vtkSMPTools_FunctorInternal<Functor const, init>
type;
135 #endif // __VTK_WRAP__
136 #endif // DOXYGEN_SHOULD_SKIP_THIS
152 template <
typename Functor>
156 fi.For(first, last, grain);
170 template <
typename Functor>
174 fi.For(first, last, grain);
187 template <
typename Functor>
202 template <
typename Functor>
218 static void Initialize(
int numThreads=0);
226 static int GetEstimatedNumberOfThreads();
233 template<
typename RandomAccessIterator>
234 static void Sort(RandomAccessIterator begin, RandomAccessIterator end)
236 vtk::detail::smp::vtkSMPTools_Impl_Sort(begin,end);
245 template<
typename RandomAccessIterator,
typename Compare>
246 static void Sort(RandomAccessIterator begin, RandomAccessIterator end,
249 vtk::detail::smp::vtkSMPTools_Impl_Sort(begin,end,comp);