[vtk-developers] Alternatives to vtkTemplateMacro

Jeff Baumes jeff.baumes at kitware.com
Tue Sep 15 13:03:48 EDT 2009


Ok, thanks for the clarification. So having two template arguments to
Apply takes care of most of the possible cases. The only major
remaining one is to have one functor that implements some subsets of
array subclasses (i.e. dense and sparse). If we are confident that
those scenarios are few and far between, I'm comfortable with
requiring multiple functors in that case.

Jeff

On Tue, Sep 15, 2009 at 12:45 PM, Timothy M. Shead <tshead at sandia.gov> wrote:
> Jeff Baumes wrote:
>>
>> Tim,
>>
>> Can you flesh your thoughts out in code so that I can understand your
>> suggestions better? In particular, what do you mean by "typelists"?
>
> A typelist is a type that stores a collection of types.  For example, you
> can define lists of numeric and string types:
>
>  #include <boost/mpl/vector.hpp>
>
>  typedef boost::mpl::vector<vtkTypeUInt8, vtkTypeInt8, ...,
>    vtkTypeFloat32, vtkTypeFloat64> vtkNumericTypes;
>
>  typedef boost::mpl::vector<vtkStdString, vtkUnicodeString>
>    vtkStringTypes;
>
>
> Once you've defined appropriate typelists, you can use them as parameters to
> a generic algorithm.  I imagine adding the typelist as an additional
> parameter to Apply():
>
>  array1->Apply<vtkNumericTypes, vtkTypedArray>(my_numeric_functor);
>
>  array2->Apply<vtkStringTypes, vtkDenseArray>(my_string_functor);
>
> Note that this approach is explicit and compact, while allowing the caller
> to define their own typelist when needed.
>
> The Apply() implementation would be altered to perform SafeDownCast tests
> based on the contents of the typelist parameter, instead of the hard-coded
> list in the original proposal.
>
> Although this example uses Boost.MPL for simplicity, implementing typelists
> for this purpose is straightforward, I've used them on a number of occasions
> both with and without Boost.
>
> Cheers,
> Tim
>
>



-- 
Jeff Baumes, Ph.D.
R&D Engineer, Kitware Inc.
(518) 881-4932
jeff.baumes at kitware.com



More information about the vtk-developers mailing list