<%
{
# Takes the input SPL tuple and converts it to
# the arguments needed to be passed to a Python
# function/callable decorated as a SPL operator.

# Variables that need to be set:

# $paramStyle - tuple or dictionary
# $iport - input port 
# $inputAttrs2Py - number of attributes to pass as tuple style

my $ipt = $iport->getCppTupleType();
my $ipv = $iport->getCppTupleName();

%>

   <%=$ipt%> const & <%=$ipv%> = static_cast< <%=$ipt%> const &>(tuple);

<%
    if ($paramStyle eq 'tuple') {
%>
// START-Processing passing SPL tuple as a Python tuple
// Declares: PyObject * pyTuple 
// Declares: PyObject * pyDict as NULL

    PyObject *pyDict = NULL; 
    PyObject * pyTuple = PyTuple_New(<%=$inputAttrs2Py%>);
    PyObject *pyValue;
<%
     for (my $i = 0; $i < $inputAttrs2Py; ++$i) {
         my $la = $iport->getAttributeAt($i);
         print convertToPythonValueAsTuple($ipv, $i, $la->getSPLType(), $la->getName());
     }
%>
// END-Processing passing SPL tuple as a Python tuple
<%
    }
%>

<%
    if ($paramStyle eq 'dictionary') {
%>
// START-Processing passing SPL tuple as a Python dictionary
// All attributes are passed in the dictionary
// Declares: PyObject * pyTuple as empty tuple
// Declares: PyObject * pyDict

    PyObject * pyTuple = PyTuple_New(0);
    PyObject * pyDict = PyDict_New();
<%
     my $ppn = '';
     if ($iport->getIndex() >= 1) {
         $ppn = $iport->getIndex();
     }

     for (my $i = 0; $i < $iport->getNumberOfAttributes(); ++$i) {
         my $la = $iport->getAttributeAt($i);
         print convertAndAddToPythonDictionaryObject($ipv, $i, $la->getSPLType(), $la->getName(), 'pyInNames_' . $ppn);
     }
%>
// END-Processing passing SPL tuple as a Python dictionary
<%
    }
}
%>

