VTK
vtkDataArrayDispatcher.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDataArrayDispatcher.h
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 
55 #ifndef vtkDataArrayDispatcher_h
56 #define vtkDataArrayDispatcher_h
57 
58 #include "vtkType.h" //Required for vtkIdType
59 #include "vtkDataArray.h" //required for constructor of the vtkDataArrayFunctor
60 #include <map> //Required for the storage of template params to runtime params
61 
63 // Object that is passed to all functor that are used with this class
64 // This allows the user the ability to find info about the size
66 template<typename T>
68 {
69  typedef T ValueType;
70 
73  ValueType* RawPointer;
74 
76  NumberOfTuples(array->GetNumberOfTuples()),
77  NumberOfComponents(array->GetNumberOfComponents()),
78  RawPointer(static_cast<ValueType*>(array->GetVoidPointer(0)))
79  {}
80 };
81 
83 // class template FunctorDispatcher
85 template
86  <
87  class DefaultFunctorType,
88  typename ReturnType = void
89  >
91 {
92 public:
93 
118  vtkDataArrayDispatcher(DefaultFunctorType& f);
119 
125 
126  virtual ~vtkDataArrayDispatcher();
127 
131  ReturnType Go(vtkDataArray* lhs);
132 
133 protected:
134  DefaultFunctorType* DefaultFunctor;
136 };
137 
138 //We are making all these method non-inline to reduce compile time overhead
139 
140 //----------------------------------------------------------------------------
141 template<class DefaultFunctorType,typename ReturnType>
143  DefaultFunctor(&fun),
144  OwnsFunctor(false)
145 {
146 }
147 
148 //----------------------------------------------------------------------------
149 template<class DefaultFunctorType,typename ReturnType>
151  DefaultFunctor(new DefaultFunctorType()),
152  OwnsFunctor(true)
153 {
154 }
155 
156 //----------------------------------------------------------------------------
157 template<class DefaultFunctorType,typename ReturnType>
159 {
160  if(OwnsFunctor)
161  {
162  delete this->DefaultFunctor;
163  }
164 }
165 
166 //----------------------------------------------------------------------------
167 template <class DefaultFunctorType,typename ReturnType>
170 {
171  switch(lhs->GetDataType())
172  {
173  vtkTemplateMacro(return (*this->DefaultFunctor) (
175  }
176  return ReturnType();
177 }
178 
179 #endif // vtkDataArrayDispatcher_h
180 // VTK-HeaderTest-Exclude: vtkDataArrayDispatcher.h
ReturnType Go(vtkDataArray *lhs)
Execute the default functor with the passed in vtkDataArray;.
DefaultFunctorType * DefaultFunctor
virtual int GetDataType()=0
Return the underlying data type.
int vtkIdType
Definition: vtkType.h:347
vtkDataArrayDispatcherPointer(vtkDataArray *array)
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
Dispatch to functor vtkDataArrayType.
vtkDataArrayDispatcher()
Default constructor which will create an instance of the DefaultFunctorType and use that single insta...