Merge branch 'expand-function-interface'

This commit is contained in:
Kenneth Moreland 2014-07-07 08:31:47 -06:00
commit 4c65092322
10 changed files with 4886 additions and 485 deletions

@ -0,0 +1,37 @@
##============================================================================
## 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.
##============================================================================
#
# - Finds the pyexpander macro tool.
# Use this module by invoking find_package.
#
# This module finds the expander.py command distributed with pyexpander.
# pyexpander can be downloaded from http://pyexpander.sourceforge.net.
# The following variables are defined:
#
# PYEXPANDER_FOUND - True if pyexpander is found
# PYEXPANDER_COMMAND - The pyexpander executable
#
find_program(PYEXPANDER_COMMAND expander.py)
mark_as_advanced(PYEXPANDER_COMMAND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Pyexpander DEFAULT_MSG PYEXPANDER_COMMAND)

@ -0,0 +1,71 @@
##============================================================================
## 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 script, which is run as part of a target, uses pyexpander to do
# macro substitution on an input file and checks the result with the
# version stored in the source code. If the versions are different, an
# error message is printed with further instructions.
#
# To use this script, the CMake variables PYEXPANDER_COMMAND, SOURCE_FILE,
# and GENERATED_FILE must be defined as the two files to compare. A ".in"
# is appended to SOURCE_FILE to get the pyexpander input.
if(NOT PYEXPANDER_COMMAND)
message(SEND_ERROR "Variable PYEXPANDER_COMMAND must be set.")
return()
endif()
if(NOT SOURCE_FILE)
message(SEND_ERROR "Variable SOURCE_FILE must be set.")
return()
endif()
if(NOT GENERATED_FILE)
message(SEND_ERROR "Variable GENERATED_FILE must be set.")
return()
endif()
execute_process(
COMMAND ${PYEXPANDER_COMMAND} ${SOURCE_FILE}.in
RESULT_VARIABLE pyexpander_result
OUTPUT_VARIABLE pyexpander_output
)
if(${pyexpander_result})
# If pyexpander returned non-zero, it failed.
message(SEND_ERROR "Running pyexpander failed.")
return()
endif()
file(WRITE ${GENERATED_FILE} "${pyexpander_output}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E compare_files ${SOURCE_FILE} ${GENERATED_FILE}
RESULT_VARIABLE diff_result
)
if(${diff_result})
# If diff returned non-zero, it failed and the two files are different.
file(REMOVE ${GENERATED_FILE})
get_filename_component(filename ${SOURCE_FILE} NAME)
message(SEND_ERROR
"The source file ${filename} does not match the generated file. If you have modified this file directly, then you have messed up. Modify the ${filename}.in file instead and then copy the pyexpander result to ${filename}. If you modified ${filename}.in, then you might just need to copy the pyresult back to the source directory. If you have not modifed either, then you have likely checked out an inappropriate change. Check the git logs to see what changes were made.
If the changes have resulted from modifying ${filename}.in, then you can finish by copying ${GENERATED_FILE} to ${SOURCE_FILE}.")
endif()

@ -131,6 +131,26 @@ function(vtkm_declare_worklets)
vtkm_declare_headers(${ARGN})
endfunction(vtkm_declare_worklets)
function(vtkm_pyexpander_generated_file generated_file_name)
# If pyexpander is available, add targets to build and check
if(PYEXPANDER_FOUND)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name}
COMMAND ${CMAKE_COMMAND}
-DPYEXPANDER_COMMAND=${PYEXPANDER_COMMAND}
-DSOURCE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${generated_file_name}
-DGENERATED_FILE=${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name}
-P ${CMAKE_SOURCE_DIR}/CMake/VTKmCheckPyexpander.cmake
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${generated_file_name}.in
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${generated_file_name}
)
add_custom_target(check_${generated_file_name} ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name}
COMMENT "Checking validity of ${generated_file_name}"
)
endif()
endfunction(vtkm_pyexpander_generated_file)
# Declare unit tests, which should be in the same directory as a kit
# (package, module, whatever you call it). Usage:
#

@ -122,6 +122,8 @@ vtkm_install_headers(
# * Meta programming language
find_package(BoostHeaders ${VTKm_REQUIRED_BOOST_VERSION} REQUIRED)
find_package(Pyexpander)
#-----------------------------------------------------------------------------
# Add subdirectories
add_subdirectory(vtkm)

@ -23,9 +23,14 @@ set(headers
ConfigureFor64.h
ExportMacros.h
FunctionInterface.h
FunctionInterfaceDetailPost.h
FunctionInterfaceDetailPre.h
)
vtkm_declare_headers(${headers})
vtkm_pyexpander_generated_file(FunctionInterfaceDetailPre.h)
vtkm_pyexpander_generated_file(FunctionInterfaceDetailPost.h)
add_subdirectory(testing)

@ -36,150 +36,15 @@
#include <boost/mpl/insert.hpp>
#include <boost/mpl/less.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/dec.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_shifted.hpp>
#include <boost/preprocessor/repetition/enum_shifted_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/utility/enable_if.hpp>
#define VTKM_MAX_FUNCTION_PARAMETERS 10
#include <vtkm/internal/FunctionInterfaceDetailPre.h>
namespace vtkm {
namespace internal {
/// This struct is used internally by FunctionInterface to store the return
/// value of a function. There is a special implementation for a return type of
/// void, which stores nothing.
///
template<typename T>
struct FunctionInterfaceReturnContainer {
T Value;
static const bool VALID = true;
};
template<>
struct FunctionInterfaceReturnContainer<void> {
// Nothing to store for void return.
static const bool VALID = false;
};
namespace detail {
// If you get a compiler error stating that this class is not specialized, that
// probably means that you are using FunctionInterface with an unsupported
// number of arguments.
template<typename FunctionSignature>
struct ParameterContainer;
// The following code uses the Boost preprocessor utilities to create
// definitions of ParameterContainer for all supported number of arguments.
// The created classes are conceptually defined as follows:
//
// template<typename P0, // Return type
// typename P1,
// typename P2, ...>
// struct ParameterContainer<P0(P1,P2,...)> {
// P1 Parameter1;
// P2 Parameter2;
// ...
// };
//
// These are defined for 0 to VTKM_MAX_FUNCTION_PARAMETERS parameters.
#define VTK_M_PARAMETER_DEFINITION(z, ParamIndex, data) \
BOOST_PP_IF(ParamIndex, \
BOOST_PP_CAT(P,ParamIndex) BOOST_PP_CAT(Parameter,ParamIndex);,)
#define VTK_M_PARAMETER_CONTAINER(NumParamsPlusOne) \
template<BOOST_PP_ENUM_PARAMS(NumParamsPlusOne, typename P)> \
struct ParameterContainer<P0(BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, P))> \
{ \
BOOST_PP_REPEAT(NumParamsPlusOne, VTK_M_PARAMETER_DEFINITION,) \
};
#define VTK_M_PARAMETER_CONTAINER_REPEAT(z, NumParams, data) \
VTK_M_PARAMETER_CONTAINER(BOOST_PP_INC(NumParams))
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_PARAMETER_CONTAINER_REPEAT,)
#undef VTK_M_PARAMETER_CONTAINER_REPEAT
#undef VTK_M_PARAMETER_CONTAINER
#undef VTK_M_PARAMETER_DEFINITION
template<int ParameterIndex, typename FunctionSignature>
struct ParameterContainerAccess;
// The following code uses the Boost preprocessor utilities to create
// definitions of ParameterContainerAccess for all supported number of
// arguments. The created class specalizations conceptually create the
// following interface:
//
// template<int ParameterIndex, typename R(P1,P2,...)>
// struct ParameterContainerAccess
// {
// VTKM_EXEC_CONT_EXPORT
// static ParameterType
// GetParameter(const ParameterContainer<R(P1,P2,...)> &parameters);
//
// VTKM_EXEC_CONT_EXPORT
// static void SetParameter(ParameterContainer<R(P1,P2,...)> &parameters,
// const ParameterType &value);
// };
//
// Here ParameterType is the P# type in the function signature for the given
// ParameterIndex. It is the same you would get for
// FunctionInterface::ParameterType.
#define VTK_M_PARAMETER_CONTAINER_ACCESS(ParameterIndex) \
template<typename FunctionSignature> \
struct ParameterContainerAccess<ParameterIndex, FunctionSignature> { \
typedef typename boost::mpl::at_c< \
boost::function_types::components<FunctionSignature>, \
ParameterIndex>::type ParameterType; \
VTKM_EXEC_CONT_EXPORT \
static \
ParameterType \
GetParameter(const ParameterContainer<FunctionSignature> &parameters) { \
return parameters.BOOST_PP_CAT(Parameter, ParameterIndex); \
} \
VTKM_EXEC_CONT_EXPORT \
static \
void SetParameter(ParameterContainer<FunctionSignature> &parameters, \
const ParameterType &value) { \
parameters.BOOST_PP_CAT(Parameter, ParameterIndex) = value; \
} \
};
#define VTK_M_PARAMETER_CONTAINER_ACCESS_REPEAT(z, i, data) \
VTK_M_PARAMETER_CONTAINER_ACCESS(BOOST_PP_INC(i))
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_PARAMETER_CONTAINER_ACCESS_REPEAT,)
#undef VTK_M_PARAMETER_CONTAINER_ACCESS_REPEAT
#undef VTK_M_PARAMETER_CONTAINER_ACCESS
template<int ParameterIndex, typename FunctionSignature>
VTKM_EXEC_CONT_EXPORT
typename ParameterContainerAccess<ParameterIndex,FunctionSignature>::ParameterType
GetParameter(const ParameterContainer<FunctionSignature> &parameters) {
return ParameterContainerAccess<ParameterIndex,FunctionSignature>::GetParameter(parameters);
}
template<int ParameterIndex, typename FunctionSignature>
VTKM_EXEC_CONT_EXPORT
void SetParameter(ParameterContainer<FunctionSignature> &parameters,
const typename ParameterContainerAccess<ParameterIndex,FunctionSignature>::ParameterType &value) {
return ParameterContainerAccess<ParameterIndex,FunctionSignature>::SetParameter(parameters, value);
}
struct IdentityFunctor {
template<typename T>
VTKM_EXEC_CONT_EXPORT
@ -190,111 +55,20 @@ struct IdentityFunctor {
const T &operator()(const T &x) const { return x; }
};
// The following code uses the Boost preprocessor utilities to create
// definitions of DoInvoke functions for all supported number of arguments.
// The created functions are conceptually defined as follows:
//
// template<typename Function,
// typename TransformFunctor,
// typename P0,
// typename P1,
// typename P2,...>
// VTKM_CONT_EXPORT
// void DoInvokeCont(const Function &f,
// ParameterContainer<P0(P1,P2,...)> &parameters,
// FunctionInterfaceReturnContainer<P0> &result,
// const TransformFunctor &transform)
// {
// result.Value = transform(f(transform(parameters.Parameter1),...));
// }
//
// We define multiple DoInvokeCont and DoInvokeExec that do identical things
// with different exports. It is important to have these separate definitions
// instead of a single version with VTKM_EXEC_CONT_EXPORT because the function
// to be invoked may only be viable in one or the other. There are also
// separate versions that support const functions and non-const functions.
// (However, the structures from the FunctionInterface must always be
// non-const.) Finally, there is a special version for functions that return
// void so that the function does not try to invalidly save a void value.
#define VTK_M_DO_INVOKE_TPARAM(z, count, data) \
transform(BOOST_PP_CAT(parameters.Parameter, count))
#define VTK_M_DO_INVOKE(NumParamsPlusOne) \
template<typename Function, \
typename TransformFunctor, \
BOOST_PP_ENUM_PARAMS(NumParamsPlusOne, typename P)> \
VTK_M_DO_INVOKE_EXPORT \
void VTK_M_DO_INVOKE_NAME( \
VTK_M_DO_INVOKE_FUNCTION_CONST Function &f, \
ParameterContainer<P0(BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, P))> &parameters, \
FunctionInterfaceReturnContainer<P0> &result, \
const TransformFunctor &transform) \
{ \
(void)parameters; \
(void)transform; \
result.Value = \
transform( \
f(BOOST_PP_ENUM_SHIFTED(NumParamsPlusOne, VTK_M_DO_INVOKE_TPARAM, ))); \
} \
\
template<typename Function, \
typename TransformFunctor BOOST_PP_COMMA_IF(BOOST_PP_DEC(NumParamsPlusOne)) \
BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, typename P)> \
VTK_M_DO_INVOKE_EXPORT \
void VTK_M_DO_INVOKE_NAME( \
VTK_M_DO_INVOKE_FUNCTION_CONST Function &f, \
ParameterContainer<void(BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, P))> &parameters, \
FunctionInterfaceReturnContainer<void> &, \
const TransformFunctor &transform) \
{ \
(void)parameters; \
(void)transform; \
f(BOOST_PP_ENUM_SHIFTED(NumParamsPlusOne, VTK_M_DO_INVOKE_TPARAM, )); \
}
#define VTK_M_DO_INVOKE_REPEAT(z, NumParams, data) \
VTK_M_DO_INVOKE(BOOST_PP_INC(NumParams))
#define VTK_M_DO_INVOKE_NAME DoInvokeCont
#define VTK_M_DO_INVOKE_EXPORT VTKM_CONT_EXPORT
#define VTK_M_DO_INVOKE_FUNCTION_CONST const
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_INVOKE_REPEAT,)
#undef VTK_M_DO_INVOKE_NAME
#undef VTK_M_DO_INVOKE_EXPORT
#undef VTK_M_DO_INVOKE_FUNCTION_CONST
#define VTK_M_DO_INVOKE_NAME DoInvokeCont
#define VTK_M_DO_INVOKE_EXPORT VTKM_CONT_EXPORT
#define VTK_M_DO_INVOKE_FUNCTION_CONST
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_INVOKE_REPEAT,)
#undef VTK_M_DO_INVOKE_NAME
#undef VTK_M_DO_INVOKE_EXPORT
#undef VTK_M_DO_INVOKE_FUNCTION_CONST
#define VTK_M_DO_INVOKE_NAME DoInvokeExec
#define VTK_M_DO_INVOKE_EXPORT VTKM_EXEC_EXPORT
#define VTK_M_DO_INVOKE_FUNCTION_CONST const
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_INVOKE_REPEAT,)
#undef VTK_M_DO_INVOKE_NAME
#undef VTK_M_DO_INVOKE_EXPORT
#undef VTK_M_DO_INVOKE_FUNCTION_CONST
#define VTK_M_DO_INVOKE_NAME DoInvokeExec
#define VTK_M_DO_INVOKE_EXPORT VTKM_EXEC_EXPORT
#define VTK_M_DO_INVOKE_FUNCTION_CONST
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_INVOKE_REPEAT,)
#undef VTK_M_DO_INVOKE_NAME
#undef VTK_M_DO_INVOKE_EXPORT
#undef VTK_M_DO_INVOKE_FUNCTION_CONST
#undef VTK_M_DO_INVOKE_REPEAT
#undef VTK_M_DO_INVOKE
#undef VTK_M_DO_INVOKE_TPARAM
template<int ParameterIndex, typename FunctionSignature>
VTKM_EXEC_CONT_EXPORT
typename ParameterContainerAccess<ParameterIndex,FunctionSignature>::ParameterType
GetParameter(const ParameterContainer<FunctionSignature> &parameters) {
return ParameterContainerAccess<ParameterIndex,FunctionSignature>::GetParameter(parameters);
}
template<int ParameterIndex, typename FunctionSignature>
VTKM_EXEC_CONT_EXPORT
void SetParameter(ParameterContainer<FunctionSignature> &parameters,
const typename ParameterContainerAccess<ParameterIndex,FunctionSignature>::ParameterType &value) {
return ParameterContainerAccess<ParameterIndex,FunctionSignature>::SetParameter(parameters, value);
}
// These functions exist to help copy components of a FunctionInterface.
@ -327,156 +101,12 @@ struct FunctionInterfaceCopyParameters<0, ParameterIndex> {
template<typename OriginalSignature, typename Transform>
struct FunctionInterfaceStaticTransformType;
// The following code uses the Boost preprocessor utilities to create
// definitions of DoStaticTransform functions for all supported number of
// arguments. The created functions are conceptually defined as follows:
//
// template<typename Transform,
// typename OriginalSignature,
// typename TransformedSignature>
// VTKM_CONT_EXPORT
// void DoStaticTransformCont(
// const Transform &transform,
// const ParameterContainer<OriginalSignature> &originalParameters,
// ParameterContainer<TransformedSignature> &transformedParameters)
// {
// transformedParameters.Parameter1 = transform(originalParameters.Parameter1);
// transformedParameters.Parameter2 = transform(originalParameters.Parameter2);
// ...
// }
//
// We define multiple DoStaticTransformCont and DoStaticTransformExec that do
// identical things with different exports. It is important to have these
// separate definitions instead of a single version with VTKM_EXEC_CONT_EXPORT
// because the transform to be invoked may only be viable in one or the other.
#define VTK_M_DO_STATIC_TRANSFORM_ASSIGN(z, count, data) \
BOOST_PP_IF(count, \
BOOST_PP_CAT(transformedParameters.Parameter, count) = \
transform(BOOST_PP_CAT(originalParameters.Parameter, count));,)
#define VTK_M_DO_STATIC_TRANSFORM(NumParamsPlusOne) \
template<typename Transform, \
BOOST_PP_ENUM_PARAMS(NumParamsPlusOne, typename OriginalP), \
BOOST_PP_ENUM_PARAMS(NumParamsPlusOne, typename TransformedP)> \
VTK_M_DO_STATIC_TRANSFORM_EXPORT \
void VTK_M_DO_STATIC_TRANSFORM_NAME( \
const Transform &transform, \
const ParameterContainer<OriginalP0(BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, OriginalP))> &originalParameters, \
ParameterContainer<TransformedP0(BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, TransformedP))> &transformedParameters) \
{ \
(void)transform; \
(void)originalParameters; \
(void)transformedParameters; \
BOOST_PP_REPEAT(NumParamsPlusOne, VTK_M_DO_STATIC_TRANSFORM_ASSIGN,) \
}
#define VTK_M_DO_STATIC_TRANSFORM_REPEAT(z, NumParams, data) \
VTK_M_DO_STATIC_TRANSFORM(BOOST_PP_INC(NumParams))
#define VTK_M_DO_STATIC_TRANSFORM_NAME DoStaticTransformCont
#define VTK_M_DO_STATIC_TRANSFORM_EXPORT VTKM_CONT_EXPORT
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_STATIC_TRANSFORM_REPEAT,)
#undef VTK_M_DO_STATIC_TRANSFORM_EXPORT
#undef VTK_M_DO_STATIC_TRANSFORM_NAME
#define VTK_M_DO_STATIC_TRANSFORM_NAME DoStaticTransformExec
#define VTK_M_DO_STATIC_TRANSFORM_EXPORT VTKM_EXEC_EXPORT
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_STATIC_TRANSFORM_REPEAT,)
#undef VTK_M_DO_STATIC_TRANSFORM_EXPORT
#undef VTK_M_DO_STATIC_TRANSFORM_NAME
#undef VTK_M_DO_STATIC_TRANSFORM_REPEAT
#undef VTK_M_DO_STATIC_TRANSFORM
#undef VTK_M_DO_STATIC_TRANSFORM_ASSIGN
template<typename OriginalFunction,
typename NewFunction,
typename TransformFunctor,
typename FinishFunctor>
class FunctionInterfaceDynamicTransformContContinue;
// The following code uses the Boost preprocessor utilities to create
// definitions of DoForEach functions for all supported number of arguments.
// The created functions are conceptually defined as follows:
//
// template<typename Functor, typename P0, typename P1, typename P2,...>
// VTKM_CONT_EXPORT
// void DoForEachCont(const Functor &f,
// ParameterContainer<P0(P1,P2,...)> &parameters)
//
// {
// f(parameters.Parameter1);
// f(parameters.Parameter2);
// ...
// }
//
// We define multiple DoForEachCont and DoForEachExec that do identical things
// with different exports. It is important to have these separate definitions
// instead of a single version with VTKM_EXEC_CONT_EXPORT because the functor
// to be invoked on each parameter may only be viable in one or the other.
// There are also separate versions that support a const FunctionInterface and
// a non-const FunctionInterface.
#define VTK_M_DO_FOR_EACH_CALL_PARAM(z, count, data) \
BOOST_PP_IF(count, f(BOOST_PP_CAT(parameters.Parameter, count));,)
#define VTK_M_DO_FOR_EACH(NumParamsPlusOne) \
template<typename Functor, \
BOOST_PP_ENUM_PARAMS(NumParamsPlusOne, typename P)> \
VTK_M_DO_FOR_EACH_EXPORT \
void VTK_M_DO_FOR_EACH_NAME( \
const Functor &f, \
VTK_M_DO_FOR_EACH_FI_CONST ParameterContainer<P0(BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, P))> &parameters) \
{ \
(void)f; \
(void)parameters; \
BOOST_PP_REPEAT(NumParamsPlusOne, VTK_M_DO_FOR_EACH_CALL_PARAM,) \
}
#define VTK_M_DO_FOR_EACH_REPEAT(z, NumParams, data) \
VTK_M_DO_FOR_EACH(BOOST_PP_INC(NumParams))
#define VTK_M_DO_FOR_EACH_EXPORT VTKM_CONT_EXPORT
#define VTK_M_DO_FOR_EACH_NAME DoForEachCont
#define VTK_M_DO_FOR_EACH_FI_CONST const
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_FOR_EACH_REPEAT,)
#undef VTK_M_DO_FOR_EACH_FI_CONST
#undef VTK_M_DO_FOR_EACH_NAME
#undef VTK_M_DO_FOR_EACH_EXPORT
#define VTK_M_DO_FOR_EACH_EXPORT VTKM_CONT_EXPORT
#define VTK_M_DO_FOR_EACH_NAME DoForEachCont
#define VTK_M_DO_FOR_EACH_FI_CONST
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_FOR_EACH_REPEAT,)
#undef VTK_M_DO_FOR_EACH_FI_CONST
#undef VTK_M_DO_FOR_EACH_NAME
#undef VTK_M_DO_FOR_EACH_EXPORT
#define VTK_M_DO_FOR_EACH_EXPORT VTKM_EXEC_EXPORT
#define VTK_M_DO_FOR_EACH_NAME DoForEachExec
#define VTK_M_DO_FOR_EACH_FI_CONST const
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_FOR_EACH_REPEAT,)
#undef VTK_M_DO_FOR_EACH_FI_CONST
#undef VTK_M_DO_FOR_EACH_NAME
#undef VTK_M_DO_FOR_EACH_EXPORT
#define VTK_M_DO_FOR_EACH_EXPORT VTKM_EXEC_EXPORT
#define VTK_M_DO_FOR_EACH_NAME DoForEachExec
#define VTK_M_DO_FOR_EACH_FI_CONST
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_DO_FOR_EACH_REPEAT,)
#undef VTK_M_DO_FOR_EACH_FI_CONST
#undef VTK_M_DO_FOR_EACH_NAME
#undef VTK_M_DO_FOR_EACH_EXPORT
#undef VTK_M_DO_FOR_EACH_REPEAT
#undef VTK_M_DO_FOR_EACH
#undef VTK_M_DO_FOR_EACH_CALL_PARAM
} // namespace detail
/// \brief Holds parameters and result of a function.
@ -1044,46 +674,6 @@ private:
namespace detail {
// The following code uses the Boost preprocessor utilities to create
// definitions of FunctionInterfaceStaticTransformType for all supported number
// of arguments. The created classes are conceptually defined as follows:
//
// template<typename Transform,
// typename P0, // Return type
// typename P1,
// typename P2, ...>
// struct FunctionInterfaceStaticTransformType<P0(P1,P2,...), Transform> {
// typedef P0(type)(typename Transform::template ReturnType<P1>::type,
// typename Transform::template ReturnType<P2>::type, ...);
// };
#define VTK_M_STATIC_TRANSFORM_TPARAM(z, ParamIndex, data) \
BOOST_PP_IF( \
ParamIndex, \
typename Transform::template ReturnType<BOOST_PP_CAT(P,ParamIndex)>::type,)
#define VTK_M_STATIC_TRANSFORM_TYPE(NumParamsPlusOne) \
template<typename Transform, \
BOOST_PP_ENUM_PARAMS(NumParamsPlusOne, typename P)> \
struct FunctionInterfaceStaticTransformType< \
P0(BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, P)), \
Transform> \
{ \
typedef P0(type)( \
BOOST_PP_ENUM_SHIFTED(NumParamsPlusOne, VTK_M_STATIC_TRANSFORM_TPARAM,) \
); \
};
#define VTK_M_STATIC_TRANSFORM_TYPE_REPEAT(z, NumParams, data) \
VTK_M_STATIC_TRANSFORM_TYPE(BOOST_PP_INC(NumParams))
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_STATIC_TRANSFORM_TYPE_REPEAT,)
#undef VTK_M_STATIC_TRANSFORM_TYPE_REPEAT
#undef VTK_M_STATIC_TRANSFORM_TYPE
#undef VTK_M_STATIC_TRANSFORM_TPARAM
template<typename OriginalFunction,
typename NewFunction,
typename TransformFunctor,
@ -1158,69 +748,9 @@ private:
} // namespace detail
#ifdef VTKM_DOXYGEN_ONLY
/// \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<typename P0, typename... P>
VTKM_EXEC_CONT_EXPORT
vtkm::internal::FunctionInterface<P0(P...)>
make_FunctionInterface(P... parameters);
#endif //VTKM_DOXYGEN_ONLY
// The following code uses the Boost preprocessor utilities to create
// definitions of make_FunctionInterface for all supported number of arguments.
// The created functions are conceptually defined as follows:
//
// template<typename P0, // Return type
// typename P1,
// typename P2, ...>
// VTKM_EXEC_CONT_EXPORT
// FunctionInterface<P0(P1,P2,...)>
// make_FunctionInterface(P1 p1, P2 p2,...) {
// FunctionInterface<P0(P1,P2,...)> fi;
// fi.template SetParameters<1>(p1);
// fi.template SetParameters<2>(p2);
// ...
// return fi;
// }
#define VTK_M_SET_PARAMETER(z, ParamIndex, data) \
BOOST_PP_IF( \
ParamIndex, \
fi.template SetParameter<ParamIndex>(BOOST_PP_CAT(p, ParamIndex));,)
#define VTK_M_MAKE_FUNCTION_INTERFACE(NumParamsPlusOne) \
template<BOOST_PP_ENUM_PARAMS(NumParamsPlusOne, typename P)> \
VTKM_EXEC_CONT_EXPORT \
FunctionInterface<P0(BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, P))> \
make_FunctionInterface( \
BOOST_PP_ENUM_SHIFTED_BINARY_PARAMS(NumParamsPlusOne, P, p)) \
{ \
FunctionInterface<P0(BOOST_PP_ENUM_SHIFTED_PARAMS(NumParamsPlusOne, P))> fi; \
BOOST_PP_REPEAT(NumParamsPlusOne, VTK_M_SET_PARAMETER,) \
return fi; \
}
#define VTK_M_MAKE_FUNCITON_INTERFACE_REPEAT(z, NumParams, data) \
VTK_M_MAKE_FUNCTION_INTERFACE(BOOST_PP_INC(NumParams))
BOOST_PP_REPEAT(BOOST_PP_INC(VTKM_MAX_FUNCTION_PARAMETERS),
VTK_M_MAKE_FUNCITON_INTERFACE_REPEAT,)
#undef VTK_M_MAKE_FUNCITON_INTERFACE_REPEAT
#undef VTK_M_MAKE_FUNCTION_INTERFACE
#undef VTK_M_SET_PARAMETER
}
} // namespace vtkm::internal
#include <vtkm/internal/FunctionInterfaceDetailPost.h>
#endif //vtk_m_cont_internal_FunctionInterface_h

@ -0,0 +1,647 @@
//============================================================================
// 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.
//============================================================================
// **** DO NOT EDIT THIS FILE!!! ****
// This file is automatically generated by FunctionInterfaceDetailPost.h.in
#ifndef vtk_m_cont_internal_FunctionInterfaceDetailPost_h
#define vtk_m_cont_internal_FunctionInterfaceDetailPost_h
#if !defined(vtk_m_cont_internal_FunctionInterface_h) && !defined(VTKM_TEST_HEADER_BUILD)
#error FunctionInterfaceDetailPre.h must be included from FunctionInterface.h
#endif
#include <vtkm/internal/FunctionInterface.h>
#if VTKM_MAX_FUNCTION_PARAMETERS != 10
#error Mismatch of maximum parameters between FunctionInterfaceDatailPre.h.in and FunctionInterfaceDetailPost.h.in
#endif
namespace vtkm {
namespace internal {
namespace detail {
//============================================================================
template<typename Transform,
typename R>
struct FunctionInterfaceStaticTransformType<R(), Transform> {
typedef R(type)(
);
};
template<typename Transform,
typename R,
typename P1>
struct FunctionInterfaceStaticTransformType<R(P1), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type
);
};
template<typename Transform,
typename R,
typename P1,
typename P2>
struct FunctionInterfaceStaticTransformType<R(P1,P2), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type,
typename Transform::template ReturnType<P2>::type
);
};
template<typename Transform,
typename R,
typename P1,
typename P2,
typename P3>
struct FunctionInterfaceStaticTransformType<R(P1,P2,P3), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type,
typename Transform::template ReturnType<P2>::type,
typename Transform::template ReturnType<P3>::type
);
};
template<typename Transform,
typename R,
typename P1,
typename P2,
typename P3,
typename P4>
struct FunctionInterfaceStaticTransformType<R(P1,P2,P3,P4), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type,
typename Transform::template ReturnType<P2>::type,
typename Transform::template ReturnType<P3>::type,
typename Transform::template ReturnType<P4>::type
);
};
template<typename Transform,
typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5>
struct FunctionInterfaceStaticTransformType<R(P1,P2,P3,P4,P5), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type,
typename Transform::template ReturnType<P2>::type,
typename Transform::template ReturnType<P3>::type,
typename Transform::template ReturnType<P4>::type,
typename Transform::template ReturnType<P5>::type
);
};
template<typename Transform,
typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6>
struct FunctionInterfaceStaticTransformType<R(P1,P2,P3,P4,P5,P6), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type,
typename Transform::template ReturnType<P2>::type,
typename Transform::template ReturnType<P3>::type,
typename Transform::template ReturnType<P4>::type,
typename Transform::template ReturnType<P5>::type,
typename Transform::template ReturnType<P6>::type
);
};
template<typename Transform,
typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7>
struct FunctionInterfaceStaticTransformType<R(P1,P2,P3,P4,P5,P6,P7), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type,
typename Transform::template ReturnType<P2>::type,
typename Transform::template ReturnType<P3>::type,
typename Transform::template ReturnType<P4>::type,
typename Transform::template ReturnType<P5>::type,
typename Transform::template ReturnType<P6>::type,
typename Transform::template ReturnType<P7>::type
);
};
template<typename Transform,
typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7,
typename P8>
struct FunctionInterfaceStaticTransformType<R(P1,P2,P3,P4,P5,P6,P7,P8), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type,
typename Transform::template ReturnType<P2>::type,
typename Transform::template ReturnType<P3>::type,
typename Transform::template ReturnType<P4>::type,
typename Transform::template ReturnType<P5>::type,
typename Transform::template ReturnType<P6>::type,
typename Transform::template ReturnType<P7>::type,
typename Transform::template ReturnType<P8>::type
);
};
template<typename Transform,
typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7,
typename P8,
typename P9>
struct FunctionInterfaceStaticTransformType<R(P1,P2,P3,P4,P5,P6,P7,P8,P9), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type,
typename Transform::template ReturnType<P2>::type,
typename Transform::template ReturnType<P3>::type,
typename Transform::template ReturnType<P4>::type,
typename Transform::template ReturnType<P5>::type,
typename Transform::template ReturnType<P6>::type,
typename Transform::template ReturnType<P7>::type,
typename Transform::template ReturnType<P8>::type,
typename Transform::template ReturnType<P9>::type
);
};
template<typename Transform,
typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7,
typename P8,
typename P9,
typename P10>
struct FunctionInterfaceStaticTransformType<R(P1,P2,P3,P4,P5,P6,P7,P8,P9,P10), Transform> {
typedef R(type)(
typename Transform::template ReturnType<P1>::type,
typename Transform::template ReturnType<P2>::type,
typename Transform::template ReturnType<P3>::type,
typename Transform::template ReturnType<P4>::type,
typename Transform::template ReturnType<P5>::type,
typename Transform::template ReturnType<P6>::type,
typename Transform::template ReturnType<P7>::type,
typename Transform::template ReturnType<P8>::type,
typename Transform::template ReturnType<P9>::type,
typename Transform::template ReturnType<P10>::type
);
};
} // namespace detail
//============================================================================
/// \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<typename R>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R()>
make_FunctionInterface(
)
{
FunctionInterface<R()> fi;
return fi;
}
/// \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<typename R,
typename P1>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1)>
make_FunctionInterface(
P1 p1
)
{
FunctionInterface<R(P1)> fi;
fi.template SetParameter<1>(p1);
return fi;
}
/// \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<typename R,
typename P1,
typename P2>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1,P2)>
make_FunctionInterface(
P1 p1,
P2 p2
)
{
FunctionInterface<R(P1,P2)> fi;
fi.template SetParameter<1>(p1);
fi.template SetParameter<2>(p2);
return fi;
}
/// \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<typename R,
typename P1,
typename P2,
typename P3>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1,P2,P3)>
make_FunctionInterface(
P1 p1,
P2 p2,
P3 p3
)
{
FunctionInterface<R(P1,P2,P3)> fi;
fi.template SetParameter<1>(p1);
fi.template SetParameter<2>(p2);
fi.template SetParameter<3>(p3);
return fi;
}
/// \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<typename R,
typename P1,
typename P2,
typename P3,
typename P4>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1,P2,P3,P4)>
make_FunctionInterface(
P1 p1,
P2 p2,
P3 p3,
P4 p4
)
{
FunctionInterface<R(P1,P2,P3,P4)> fi;
fi.template SetParameter<1>(p1);
fi.template SetParameter<2>(p2);
fi.template SetParameter<3>(p3);
fi.template SetParameter<4>(p4);
return fi;
}
/// \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<typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1,P2,P3,P4,P5)>
make_FunctionInterface(
P1 p1,
P2 p2,
P3 p3,
P4 p4,
P5 p5
)
{
FunctionInterface<R(P1,P2,P3,P4,P5)> fi;
fi.template SetParameter<1>(p1);
fi.template SetParameter<2>(p2);
fi.template SetParameter<3>(p3);
fi.template SetParameter<4>(p4);
fi.template SetParameter<5>(p5);
return fi;
}
/// \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<typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1,P2,P3,P4,P5,P6)>
make_FunctionInterface(
P1 p1,
P2 p2,
P3 p3,
P4 p4,
P5 p5,
P6 p6
)
{
FunctionInterface<R(P1,P2,P3,P4,P5,P6)> fi;
fi.template SetParameter<1>(p1);
fi.template SetParameter<2>(p2);
fi.template SetParameter<3>(p3);
fi.template SetParameter<4>(p4);
fi.template SetParameter<5>(p5);
fi.template SetParameter<6>(p6);
return fi;
}
/// \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<typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1,P2,P3,P4,P5,P6,P7)>
make_FunctionInterface(
P1 p1,
P2 p2,
P3 p3,
P4 p4,
P5 p5,
P6 p6,
P7 p7
)
{
FunctionInterface<R(P1,P2,P3,P4,P5,P6,P7)> fi;
fi.template SetParameter<1>(p1);
fi.template SetParameter<2>(p2);
fi.template SetParameter<3>(p3);
fi.template SetParameter<4>(p4);
fi.template SetParameter<5>(p5);
fi.template SetParameter<6>(p6);
fi.template SetParameter<7>(p7);
return fi;
}
/// \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<typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7,
typename P8>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1,P2,P3,P4,P5,P6,P7,P8)>
make_FunctionInterface(
P1 p1,
P2 p2,
P3 p3,
P4 p4,
P5 p5,
P6 p6,
P7 p7,
P8 p8
)
{
FunctionInterface<R(P1,P2,P3,P4,P5,P6,P7,P8)> fi;
fi.template SetParameter<1>(p1);
fi.template SetParameter<2>(p2);
fi.template SetParameter<3>(p3);
fi.template SetParameter<4>(p4);
fi.template SetParameter<5>(p5);
fi.template SetParameter<6>(p6);
fi.template SetParameter<7>(p7);
fi.template SetParameter<8>(p8);
return fi;
}
/// \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<typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7,
typename P8,
typename P9>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1,P2,P3,P4,P5,P6,P7,P8,P9)>
make_FunctionInterface(
P1 p1,
P2 p2,
P3 p3,
P4 p4,
P5 p5,
P6 p6,
P7 p7,
P8 p8,
P9 p9
)
{
FunctionInterface<R(P1,P2,P3,P4,P5,P6,P7,P8,P9)> fi;
fi.template SetParameter<1>(p1);
fi.template SetParameter<2>(p2);
fi.template SetParameter<3>(p3);
fi.template SetParameter<4>(p4);
fi.template SetParameter<5>(p5);
fi.template SetParameter<6>(p6);
fi.template SetParameter<7>(p7);
fi.template SetParameter<8>(p8);
fi.template SetParameter<9>(p9);
return fi;
}
/// \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<typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6,
typename P7,
typename P8,
typename P9,
typename P10>
VTKM_EXEC_CONT_EXPORT
FunctionInterface<R(P1,P2,P3,P4,P5,P6,P7,P8,P9,P10)>
make_FunctionInterface(
P1 p1,
P2 p2,
P3 p3,
P4 p4,
P5 p5,
P6 p6,
P7 p7,
P8 p8,
P9 p9,
P10 p10
)
{
FunctionInterface<R(P1,P2,P3,P4,P5,P6,P7,P8,P9,P10)> fi;
fi.template SetParameter<1>(p1);
fi.template SetParameter<2>(p2);
fi.template SetParameter<3>(p3);
fi.template SetParameter<4>(p4);
fi.template SetParameter<5>(p5);
fi.template SetParameter<6>(p6);
fi.template SetParameter<7>(p7);
fi.template SetParameter<8>(p8);
fi.template SetParameter<9>(p9);
fi.template SetParameter<10>(p10);
return fi;
}
}
} // namespace vtkm::internal
#endif //vtk_m_cont_internal_FunctionInterfaceDetailPost_h

@ -0,0 +1,142 @@
//============================================================================
// 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_cont_internal_FunctionInterfaceDetailPost_h
#define vtk_m_cont_internal_FunctionInterfaceDetailPost_h
#if !defined(vtk_m_cont_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, return_type=ptype(0), name=''):
result = '%s(' % return_type
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\
}
} // namespace vtkm::internal
#endif //vtk_m_cont_internal_FunctionInterfaceDetailPost_h

File diff suppressed because it is too large Load Diff

@ -0,0 +1,272 @@
//============================================================================
// 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 FunctionInterfaceDetailPre.h.in > FunctionInterfaceDetailPre.h
$#
$# Ignore the following comment. It is meant for the generated file.
// **** DO NOT EDIT THIS FILE!!! ****
// This file is automatically generated by FunctionInterfaceDetailPre.h.in
#ifndef vtk_m_cont_internal_FunctionInterfaceDetailPre_h
#define vtk_m_cont_internal_FunctionInterfaceDetailPre_h
#if !defined(vtk_m_cont_internal_FunctionInterface_h) && !defined(VTKM_TEST_HEADER_BUILD)
#error FunctionInterfaceDetailPre.h must be included from FunctionInterface.h
#endif
#include <vtkm/Types.h>
#include <boost/function_types/function_type.hpp>
#include <boost/mpl/at.hpp>
$py(max_parameters=10)\
#define VTKM_MAX_FUNCTION_PARAMETERS $(max_parameters)
$# 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, return_type=ptype(0), name=''):
result = '%s(' % return_type
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 {
/// This struct is used internally by FunctionInterface to store the return
/// value of a function. There is a special implementation for a return type of
/// void, which stores nothing.
///
template<typename T>
struct FunctionInterfaceReturnContainer {
T Value;
static const bool VALID = true;
};
template<>
struct FunctionInterfaceReturnContainer<void> {
// Nothing to store for void return.
static const bool VALID = false;
};
namespace detail {
//============================================================================
// This templated class contains the state of parameters. If you get a compiler
// error stating that this class is not specialized, that probably means that
// you are using FunctionInterface with an unsupported number of arguments.
template<typename FunctionSignature>
struct ParameterContainer;
$for(num_params in range(0, max_parameters+1))\
template<$template_params(num_params)>
struct ParameterContainer<$signature(num_params)> {
$for(param_index in range(1, num_params+1))\
$ptype(param_index) Parameter$(param_index);
$endfor\
};
$endfor\
//============================================================================
template<int ParameterIndex, typename FunctionSignature>
struct ParameterContainerAccess;
$for(param_index in range(1, max_parameters+1))\
template<typename FunctionSignature>
struct ParameterContainerAccess<$(param_index), FunctionSignature> {
typedef typename boost::mpl::at_c<
boost::function_types::components<FunctionSignature>, $(param_index)>::type
ParameterType;
VTKM_EXEC_CONT_EXPORT
static
ParameterType
GetParameter(const ParameterContainer<FunctionSignature> &parameters) {
return parameters.Parameter$(param_index);
}
VTKM_EXEC_CONT_EXPORT
static
void SetParameter(ParameterContainer<FunctionSignature> &parameters,
const ParameterType &value) {
parameters.Parameter$(param_index) = value;
}
};
$endfor\
//============================================================================
$for(num_params in range(0, max_parameters+1))\
$# Invoke functions need both control and execution versions
$for(environment in ['Cont', 'Exec'])\
$# Invoke functions also need to accept const and non-const versions of the functor
$for(functor_const in ['const ', ''])\
template<typename Functor,
typename TransformFunctor,
$template_params(num_params)>
VTKM_$(environment.upper())_EXPORT
void DoInvoke$(environment)(
$(functor_const)Functor &f,
ParameterContainer<$signature(num_params)> &parameters,
FunctionInterfaceReturnContainer<$ptype(0)> &result,
const TransformFunctor &transform)
{
$if(num_params < 1)\
(void) parameters;
result.Value = transform(f());
$else\
result.Value = transform(f(
$for(param_index in xrange(1, num_params))\
transform(parameters.Parameter$(param_index)),
$endfor\
transform(parameters.Parameter$(num_params))));
$endif\
}
template<typename Functor,
typename TransformFunctor$comma_if(num_params>0)
$template_params(num_params,1)>
VTKM_$(environment.upper())_EXPORT
void DoInvoke$(environment)(
$(functor_const)Functor &f,
ParameterContainer<$signature(num_params,'void')> &parameters,
FunctionInterfaceReturnContainer<void> &,
const TransformFunctor &transform)
{
$if(num_params < 1)\
(void) parameters;
(void) transform;
f();
$else\
f(
$for(param_index in xrange(1, num_params))\
transform(parameters.Parameter$(param_index)),
$endfor\
transform(parameters.Parameter$(num_params)));
$endif\
}
$endfor\
$endfor\
$endfor\
//============================================================================
template<typename OriginalSignature, typename Transform>
struct FunctionInterfaceStaticTransformType;
$for(num_params in xrange(0, max_parameters))\
$# Transform functions need both control and execution versions
$for(environment in ['Cont', 'Exec'])\
template<typename Transform,
$template_params(num_params,0,'Original'),
$template_params(num_params,0,'Transformed')>
VTKM_$(environment.upper())_EXPORT
void DoStaticTransform$(environment)(
const Transform &transform,
const ParameterContainer<$signature(num_params,ptype(0,'Original'),'Original')> &originalParameters,
ParameterContainer<$signature(num_params,ptype(0,'Transformed'),'Transformed')> &transformedParameters)
{
$if(num_params < 1)\
(void)transform;
(void)originalParameters;
(void)transformedParameters;
$else\
$for(param_index in xrange(1, num_params+1))\
transformedParameters.Parameter$(param_index) = transform(originalParameters.Parameter$(param_index));
$endfor\
$endif\
}
$endfor\
$endfor\
//============================================================================
$for(num_params in xrange(0, max_parameters))\
$# ForEach functions need both control and execution versions
$for(environment in ['Cont', 'Exec'])\
$# ForEach functions also need to accept const and non-const versions of the FunctionInterface
$for(function_interface_const in ['const ', ''])\
template<typename Functor,
$template_params(num_params)>
VTKM_$(environment.upper())_EXPORT
void DoForEach$(environment)(
const Functor &f,
$(function_interface_const)ParameterContainer<$signature(num_params)> &parameters)
{
$if(num_params < 1)\
(void)f;
(void)parameters;
$else\
$for(param_index in xrange(1, num_params+1))\
f(parameters.Parameter$(param_index));
$endfor\
$endif\
}
$endfor\
$endfor\
$endfor\
} // namespace detail
}
} // namespace vtkm::internal
#endif //vtk_m_cont_internal_FunctionInterfaceDetailPre_h