vtk-m/vtkm/internal/FunctionInterfaceDetailPost.h.in
Kenneth Moreland b78688f4f4 Add ability to zip function interface objects.
The zip capability allows you to parameter-wise combine two
FunctionInterface objects. The result is another FunctionInterface with
each parameter a Pair containing the respective values of the two
inputs.

Being able to zip allows you to do transforms and invokes on data that
is divided among multiple function interface objects.
2014-10-16 16:31:55 -06:00

190 lines
6.5 KiB
C

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014. Los Alamos National Security
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
$# This file uses the pyexpander macro processing utility to build the
$# FunctionInterface facilities that use a variable number of arguments.
$# Information, documentation, and downloads for pyexpander can be found at:
$#
$# http://pyexpander.sourceforge.net/
$#
$# To build the source code, execute the following (after installing
$# pyexpander, of course):
$#
$# expander.py FunctionInterfaceDetailPost.h.in > FunctionInterfaceDetailPost.h
$#
$# Ignore the following comment. It is meant for the generated file.
// **** DO NOT EDIT THIS FILE!!! ****
// This file is automatically generated by FunctionInterfaceDetailPost.h.in
#ifndef vtk_m_internal_FunctionInterfaceDetailPost_h
#define vtk_m_internal_FunctionInterfaceDetailPost_h
#if !defined(vtk_m_internal_FunctionInterface_h) && !defined(VTKM_TEST_HEADER_BUILD)
#error FunctionInterfaceDetailPre.h must be included from FunctionInterface.h
#endif
#include <vtkm/internal/FunctionInterface.h>
$# This needs to match the max_parameters in FunctionInterfaceDetailPre.h.in
$py(max_parameters=10)\
#if VTKM_MAX_FUNCTION_PARAMETERS != $(max_parameters)
#error Mismatch of maximum parameters between FunctionInterfaceDatailPre.h.in and FunctionInterfaceDetailPost.h.in
#endif
$# Python commands used in template expansion.
$py(
def comma_if(flag):
if flag:
return ','
else:
return '';
def ptype(num, name=""):
if num == 0:
return '%sR' % name
else:
return '%sP%d' % (name, num)
def template_params(num_params, start=0, name=''):
if num_params < start:
return ''
result = 'typename %s' % ptype(start, name)
for param in xrange(start+1, num_params+1):
result += ',\n typename %s' % ptype(param, name)
return result
def signature(num_params, name=''):
result = '%s(' % ptype(0, name)
if num_params > 0:
result += ptype(1, name)
for param in xrange(2, num_params+1):
result += ',%s' % ptype(param, name)
result += ')'
return result
)\
$#
$extend(comma_if, ptype, template_params, signature)\
namespace vtkm {
namespace internal {
namespace detail {
//============================================================================
$for(num_params in xrange(0, max_parameters+1))\
template<typename Transform,
$template_params(num_params)>
struct FunctionInterfaceStaticTransformType<$signature(num_params), Transform> {
typedef $ptype(0)(type)(
$for(param_index in xrange(1, num_params+1))\
typename Transform::template ReturnType<$ptype(param_index)>::type$comma_if(param_index<num_params)
$endfor\
);
};
$endfor\
} // namespace detail
//============================================================================
$for(num_params in xrange(0, max_parameters+1))\
/// \brief Create a \c FunctionInterface
///
/// \c make_FunctionInterface is a function that takes a variable number of
/// arguments and returns a \c FunctionInterface object containing these
/// objects. Since the return type for the function signature is not specified,
/// you must always specify it as a template parameter
///
/// \code{.cpp}
/// vtkm::internal::FunctionInterface<void(int,double,char)> functionInterface =
/// vtkm::internal::make_FunctionInterface<void>(1, 2.5, 'a');
/// \endcode
///
template<$template_params(num_params)>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<$signature(num_params)>
make_FunctionInterface(
$for(param_index in xrange(1,num_params+1))\
$ptype(param_index) p$(param_index)$comma_if(param_index<num_params)
$endfor\
)
{
FunctionInterface<$signature(num_params)> fi;
$for(param_index in xrange(1,num_params+1))\
fi.template SetParameter<$(param_index)>(p$(param_index));
$endfor\
return fi;
}
$endfor\
$for(num_params in xrange(0, max_parameters+1))\
template<$template_params(num_params, name='T'),
$template_params(num_params, name='U')>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<$signature(num_params, name='T')>,
vtkm::internal::FunctionInterface<$signature(num_params, name='U')> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<$ptype(0,name='T'),$ptype(0,name='U')>::type (
$for(param_index in xrange(1, num_params+1))\
vtkm::Pair<$ptype(param_index,name='T'), $ptype(param_index,name='U')>$comma_if(num_params-param_index)
$endfor\
)> type;
};
$endfor\
/// Creates a "zipped" version of two \c FunctionInterface objects. Each
/// parameter in the returned object is a \c vtkm::Pair that is a combination
/// of the corresponding pair of the input objects.
///
$for(num_params in xrange(1, max_parameters+1))\
template<$template_params(num_params, name='T'),
$template_params(num_params, name='U')>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<$signature(num_params, name='T')>,
vtkm::internal::FunctionInterface<$signature(num_params, name='U')> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<$signature(num_params, name='T')> &first,
const vtkm::internal::FunctionInterface<$signature(num_params, name='U')> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<$signature(num_params, name='T')>,
vtkm::internal::FunctionInterface<$signature(num_params, name='U')> >::type result;
$for(param_index in xrange(1, num_params+1))\
result.template SetParameter<$(param_index)>(
vtkm::make_Pair(first.template GetParameter<$(param_index)>(),
second.template GetParameter<$(param_index)>()));
$endfor\
return result;
}
$endfor\
}
} // namespace vtkm::internal
#endif //vtk_m_internal_FunctionInterfaceDetailPost_h