vtkSMPToolsInternal.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSMPToolsInternal.h.in
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include <algorithm> //for std::sort()
16 
17 namespace vtk
18 {
19 namespace detail
20 {
21 namespace smp
22 {
23 template <typename FunctorInternal>
25  vtkIdType first, vtkIdType last, vtkIdType grain,
26  FunctorInternal& fi)
27 {
28  vtkIdType n = last - first;
29  if (!n)
30  {
31  return;
32  }
33 
34  if (grain == 0 || grain >= n)
35  {
36  fi.Execute(first, last);
37  }
38  else
39  {
40  vtkIdType b = first;
41  while (b < last)
42  {
43  vtkIdType e = b + grain;
44  if (e > last)
45  {
46  e = last;
47  }
48  fi.Execute(b, e);
49  b = e;
50  }
51  }
52 }
53 
54 //--------------------------------------------------------------------------------
55 template<typename RandomAccessIterator>
56 void vtkSMPTools_Impl_Sort(RandomAccessIterator begin,
57  RandomAccessIterator end)
58 {
59  std::sort(begin, end);
60 }
61 
62 //--------------------------------------------------------------------------------
63 template<typename RandomAccessIterator, typename Compare>
64 void vtkSMPTools_Impl_Sort(RandomAccessIterator begin,
65  RandomAccessIterator end,
66  Compare comp)
67 {
68  std::sort(begin, end, comp);
69 }
70 
71 }//namespace smp
72 }//namespace detail
73 }//namespace vtk
int vtkIdType
void vtkSMPTools_Impl_For(vtkIdType first, vtkIdType last, vtkIdType grain, FunctorInternal &fi)
void vtkSMPTools_Impl_Sort(RandomAccessIterator begin, RandomAccessIterator end)