//============================================================================
//  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.
//============================================================================
$# 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=20)\
#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 range(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 range(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
{

//============================================================================

// clang-format off

$for(num_params in range(0, max_parameters+1))\
template<typename Transform,
         $template_params(num_params)>
struct FunctionInterfaceStaticTransformType<$signature(num_params), Transform>
{
  using type = $ptype(0)(
$for(param_index in range(1, num_params+1))\
        typename Transform::template ReturnType<$ptype(param_index),$(param_index)>::type$comma_if(param_index<num_params)
$endfor\
        );
};

$endfor\

// clang-format on

} // namespace detail

}
} // namespace vtkm::internal

#endif //vtk_m_internal_FunctionInterfaceDetailPost_h
