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 "vtkType.h" //Required for vtkIdType
58 #include "vtkDataArray.h" //required for constructor of the vtkDataArrayFunctor
59 #include <map> //Required for the storage of template params to runtime params
60 
62 // Object that is passed to all functor that are used with this class
63 // This allows the user the ability to find info about the size
65 template<typename T>
67 {
68  typedef T ValueType;
69 
72  ValueType* RawPointer;
73 
75  NumberOfTuples(array->GetNumberOfTuples()),
76  NumberOfComponents(array->GetNumberOfComponents()),
77  RawPointer(static_cast<ValueType*>(array->GetVoidPointer(0)))
78  {}
79 };
80 
82 // class template FunctorDispatcher
84 template
85  <
86  class DefaultFunctorType,
87  typename ReturnType = void
88  >
90 {
91 public:
92 
101  vtkDataArrayDispatcher(DefaultFunctorType& f);
102 
106 
107  virtual ~vtkDataArrayDispatcher();
108 
110  ReturnType Go(vtkDataArray* lhs);
111 
112 protected:
113  DefaultFunctorType* DefaultFunctor;
115 };
116 
117 //We are making all these method non-inline to reduce compile time overhead
118 
119 //----------------------------------------------------------------------------
120 template<class DefaultFunctorType,typename ReturnType>
122  DefaultFunctor(&fun),
123  OwnsFunctor(false)
124  {
125  }
126 
127 //----------------------------------------------------------------------------
128 template<class DefaultFunctorType,typename ReturnType>
130  DefaultFunctor(new DefaultFunctorType()),
131  OwnsFunctor(true)
132  {
133  }
134 
135 //----------------------------------------------------------------------------
136 template<class DefaultFunctorType,typename ReturnType>
138  {
139  if(OwnsFunctor)
140  {
141  delete this->DefaultFunctor;
142  }
143  }
144 
145 //----------------------------------------------------------------------------
146 template <class DefaultFunctorType,typename ReturnType>
149  {
150  switch(lhs->GetDataType())
151  {
152  vtkTemplateMacro(return (*this->DefaultFunctor) (
154  }
155  return ReturnType();
156  }
157 
158 #endif // vtkDataArrayDispatcher_h
159 // VTK-HeaderTest-Exclude: vtkDataArrayDispatcher.h
ReturnType Go(vtkDataArray *lhs)
DefaultFunctorType * DefaultFunctor
virtual int GetDataType()=0
int vtkIdType
Definition: vtkType.h:275
vtkDataArrayDispatcherPointer(vtkDataArray *array)
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
Dispatch to functor vtkDataArrayType.