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