Sleds/cppcore/sequencelogic-misc.i

104 lines
3.1 KiB
OpenEdge ABL

/* Copyright (c) 2015,2016 Sequence Logic Inc. All rights reserved
*
* SWIG interface for converting between various vector implementations
*
*/
%typemap(jni) std::vector<int> & "jobjectArray"
%typemap(jtype) std::vector<int> & "int [][]"
%typemap(jstype) std::vector<int> & "int [][]"
%typemap(javain) std::vector<int> & "$javainput"
/* Convert from int [] to std::vector<int> */
%typemap(in) std::vector<int> &
{
$1 = new std::vector<int>();
if (!$input)
{
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "In sequencelogic-misc.i: NULL int[][]");
return $null;
}
if (jenv->GetArrayLength($input) == 0)
{
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "In sequencelogic-misc.i: Array must contain at least 1 element");
return $null;
}
jintArray tmpJIntArray = static_cast<jintArray>(jenv->GetObjectArrayElement($input, 0));
int nSize = static_cast<int>(jenv->GetArrayLength(tmpJIntArray));
jint *pTmpArray = new jint [nSize];
jenv->GetIntArrayRegion(tmpJIntArray, 0, nSize, pTmpArray);
$1->resize(nSize, 0);
::memcpy(&$1[0], pTmpArray, nSize*sizeof(int));
}
%typemap(freearg) std::vector<int> &
{
delete $1;
}
/* Convert from std::vector<int> to int [] */
%typemap(argout) std::vector<int> &
{
// Convert from $1 to $input
jintArray newIntArray = jenv->NewIntArray($1->size());
for (unsigned int i = 0; i < $1->size(); ++i)
{
jenv->SetIntArrayRegion(newIntArray, i, 1, reinterpret_cast<const jint *>(&$1[i]));
}
jenv->SetObjectArrayElement($input, 0, newIntArray);
}
%typemap(jni) int & "jintArray"
%typemap(jtype) int & "int[]"
%typemap(jstype) int & "int[]"
%typemap(javain) int & "$javainput"
%typemap(in) int &
{
if (!$input)
{
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "In sequencelogic-misc.i: NULL int array");
return $null;
}
if (JCALL1(GetArrayLength, jenv, $input) == 0)
{
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "In sequencelogic-misc.i: Array must contain at least 1 element");
return $null;
}
$1 = ($1_ltype) JCALL2(GetIntArrayElements, jenv, $input, 0);
}
%typemap(freearg) int & ""
%typemap(argout) int &
{ JCALL3(ReleaseIntArrayElements, jenv, $input, (jint *)$1, 0); }
%typemap(typecheck) int & = jintArray;
%typemap(jni) const std::vector<unsigned char> & "jbyteArray"
%typemap(jtype) const std::vector<unsigned char> & "byte []"
%typemap(jstype) const std::vector<unsigned char> & "byte []"
%typemap(javain) const std::vector<unsigned char> & "$javainput"
%typemap(in) const std::vector<unsigned char> &
{
$1 = new std::vector<unsigned char>();
if ($input != NULL)
{
int nSize = static_cast<int>(jenv->GetArrayLength($input));
jbyte *pTmpArray = new jbyte [nSize];
jenv->GetByteArrayRegion($input, 0, nSize, pTmpArray);
$1->reserve(nSize);
for (int i = 0; i < nSize; ++i)
$1->push_back(static_cast<unsigned char>(pTmpArray[i]));
delete [] pTmpArray;
}
}
%typemap(freearg) const std::vector<unsigned char> &
{
delete $1;
}