From: <and...@us...> - 2013-11-27 12:11:38
|
Revision: 12764 http://sourceforge.net/p/plplot/code/12764 Author: andrewross Date: 2013-11-27 12:11:34 +0000 (Wed, 27 Nov 2013) Log Message: ----------- Implement null arguments for plsvect for swig generated bindings. Modified Paths: -------------- trunk/bindings/java/plplotjavac.i trunk/bindings/lua/plplotluac.i trunk/bindings/octave/plplot_octave.i trunk/bindings/python/plplotcmodule.i trunk/bindings/swig-support/plplotcapi.i Modified: trunk/bindings/java/plplotjavac.i =================================================================== --- trunk/bindings/java/plplotjavac.i 2013-11-27 11:43:57 UTC (rev 12763) +++ trunk/bindings/java/plplotjavac.i 2013-11-27 12:11:34 UTC (rev 12764) @@ -716,6 +716,43 @@ return $jnicall; } +// trailing count, and check consistency with previous +%typemap( in ) ( const PLFLT * ArrayCkNull, PLINT n ) +{ + if ( $input != NULL ) + { + jPLFLT *jydata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 ); + $2 = ( *jenv )->GetArrayLength( jenv, $input ); + if ( ( *jenv )->GetArrayLength( jenv, $input ) != Alen ) + { + printf( "Vectors must be same length.\n" ); + return; + } + setup_array_1d_PLFLT( &$1, jydata, Alen ); + ( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jydata, 0 ); + } + else + { + $1 = NULL; + $2 = 0; + } +} +%typemap( freearg ) ( const PLFLT * ArrayCkNull, PLINT n ) +{ + if ( $1 != NULL ) + free( $1 ); + +} +%typemap( jni ) ( const PLFLT * ArrayCkNull, PLINT n ) jPLFLTArray +%typemap( jtype ) ( const PLFLT * ArrayCkNull, PLINT n ) jPLFLTbracket +%typemap( jstype ) ( const PLFLT * ArrayCkNull, PLINT n ) jPLFLTbracket +%typemap( javain ) ( const PLFLT * ArrayCkNull, PLINT n ) "$javainput" +%typemap( javaout ) ( const PLFLT * ArrayCkNull, PLINT n ) +{ + return $jnicall; +} + + // no count, but check consistency with previous or NULL %typemap( in ) const PLFLT * ArrayCkNull { if ( $input != NULL ) @@ -863,6 +900,34 @@ return $jnicall; } + +// with no trailing count +%typemap( in ) const PLFLT * ArrayNull { + if ( $input != NULL ) + { + jPLFLT *jxdata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 ); + Alen = ( *jenv )->GetArrayLength( jenv, $input ); + setup_array_1d_PLFLT( &$1, jxdata, Alen ); + ( *jenv )->ReleasePLFLTArrayElements( jenv, $input, jxdata, 0 ); + } + else + { + $1 = NULL; + Alen = 0; + } +} +%typemap( freearg ) const PLFLT * ArrayNull { + if ( $1 != NULL ) + free( $1 ); +} +%typemap( jni ) const PLFLT * ArrayNull jPLFLTArray +%typemap( jtype ) const PLFLT * ArrayNull jPLFLTbracket +%typemap( jstype ) const PLFLT * ArrayNull jPLFLTbracket +%typemap( javain ) const PLFLT * ArrayNull "$javainput" +%typemap( javaout ) const PLFLT * ArrayNull { + return $jnicall; +} + // check consistency with X dimension of previous %typemap( in ) const PLFLT * ArrayCkX { jPLFLT *jxdata = ( *jenv )->GetPLFLTArrayElements( jenv, $input, 0 ); Modified: trunk/bindings/lua/plplotluac.i =================================================================== --- trunk/bindings/lua/plplotluac.i 2013-11-27 11:43:57 UTC (rev 12763) +++ trunk/bindings/lua/plplotluac.i 2013-11-27 12:11:34 UTC (rev 12764) @@ -176,14 +176,21 @@ // No count but check consistency with previous, or NULL %typemap( in ) const PLINT * ArrayCkNull( int temp ) { - $1 = (PLINT *) LUA_get_int_num_array_var( L, $input, &temp ); - if ( !$1 ) - SWIG_fail; - if ( temp != Alen ) + if ( lua_isnil( L, $input ) ) { - lua_pushfstring( L, "Tables must be of same length." ); - SWIG_fail; + $1 = NULL; } + else + { + $1 = (PLINT *) LUA_get_int_num_array_var( L, $input, &temp ); + if ( !$1 ) + SWIG_fail; + if ( temp != Alen ) + { + lua_pushfstring( L, "Tables must be of same length." ); + SWIG_fail; + } + } } %typemap( freearg ) const PLINT * ArrayCkNull { LUA_FREE_ARRAY( $1 ); } %typemap( default ) const PLINT * ArrayCkNull { $1 = NULL; } @@ -204,14 +211,21 @@ %typemap( in ) const PLINT * ArrayCkMinus1Null( int temp ) { - $1 = (PLINT *) LUA_get_int_num_array_var( L, $input, &temp ); - if ( !$1 ) - SWIG_fail; - if ( temp < Alen - 1 ) + if ( lua_isnil( L, $input ) ) { - lua_pushfstring( L, "Tables must be at least length of others minus 1." ); - SWIG_fail; + $1 = NULL; } + else + { + $1 = (PLINT *) LUA_get_int_num_array_var( L, $input, &temp ); + if ( !$1 ) + SWIG_fail; + if ( temp < Alen - 1 ) + { + lua_pushfstring( L, "Tables must be at least length of others minus 1." ); + SWIG_fail; + } + } } %typemap( freearg ) const PLINT * ArrayCkMinus1Null { LUA_FREE_ARRAY( $1 ); } %typemap( default ) const PLINT * ArrayCkMinus1Null { $1 = NULL; } @@ -295,6 +309,33 @@ } +// Trailing count and check consistency with previous +%typemap( in ) ( const PLFLT * ArrayCkNull, PLINT n ) +{ + int temp = 0; + if ( lua_isnil( L, $input ) ) + { + $1 = NULL; + } + else + { + $1 = (PLFLT *) LUA_get_double_num_array_var( L, $input, &temp ); + if ( !$1 ) + SWIG_fail; + if ( temp != Alen ) + { + lua_pushfstring( L, "Tables must be of same length." ); + SWIG_fail; + } + } + $2 = temp; +} +%typemap( freearg ) ( const PLFLT * ArrayCkNull, PLINT n ) +{ + LUA_FREE_ARRAY( $1 ); +} + + // no count, but check consistency with previous %typemap( in ) const PLFLT * ArrayCk( int temp ) { @@ -313,14 +354,21 @@ // no count, but check consistency with previous, or NULL %typemap( in ) const PLFLT * ArrayCkNull( int temp ) { - $1 = (PLFLT *) LUA_get_double_num_array_var( L, $input, &temp ); - if ( !$1 ) - SWIG_fail; - if ( temp != Alen ) + if ( lua_isnil( L, $input ) ) { - lua_pushfstring( L, "Tables must be of same length." ); - SWIG_fail; + $1 = NULL; } + else + { + $1 = (PLFLT *) LUA_get_double_num_array_var( L, $input, &temp ); + if ( !$1 ) + SWIG_fail; + if ( temp != Alen ) + { + lua_pushfstring( L, "Tables must be of same length." ); + SWIG_fail; + } + } } %typemap( freearg ) const PLFLT * ArrayCkNull { LUA_FREE_ARRAY( $1 ); } @@ -337,6 +385,28 @@ { LUA_FREE_ARRAY( $1 ); } + +// No length but remember size to check others +%typemap( in ) const PLFLT * ArrayNull { + int temp; + if ( lua_isnil( L, $input ) ) + { + $1 = NULL; + Alen = 0; + } + else + { + $1 = (PLFLT *) LUA_get_double_num_array_var( L, $input, &temp ); + if ( !$1 ) + SWIG_fail; + Alen = temp; + } +} +%typemap( freearg ) ( const PLFLT * Array ) +{ + LUA_FREE_ARRAY( $1 ); +} + %typemap( default ) const PLFLT * ArrayCkNull { $1 = NULL; } // with trailing count Modified: trunk/bindings/octave/plplot_octave.i =================================================================== --- trunk/bindings/octave/plplot_octave.i 2013-11-27 11:43:57 UTC (rev 12763) +++ trunk/bindings/octave/plplot_octave.i 2013-11-27 12:11:34 UTC (rev 12764) @@ -401,6 +401,33 @@ { } +// With trailing count and check consistency with previous +%typemap( in ) ( const PLFLT * ArrayCkNull, PLINT n ) ( Matrix temp ) +{ + if ( _n_dims( $input ) > 1 ) + { + error( "argument must be a scalar or vector" ); SWIG_fail; + } + if ( !$input.is_empty() ) + { + if ( _dim( $input, 0 ) != Alen ) + { + error( "argument vectors must be same length" ); SWIG_fail; + } + temp = $input.matrix_value(); + $1 = &temp( 0, 0 ); + $2 = (PLINT) ( _dim( $input, 0 ) ); + } + else + { + $1 = NULL; + $2 = 0; + } +} +%typemap( freearg ) ( const PLFLT * ArrayCkNull, PLINT n ) +{ +} + // No count but check consistency with previous %typemap( in ) const PLFLT * ArrayCk( Matrix temp ) { @@ -472,6 +499,29 @@ { } +// No count but remember size to check others +%typemap( in ) const PLFLT * ArrayNull( Matrix temp ) +{ + if ( _n_dims( $input ) > 1 ) + { + error( "argument must be a scalar or vector" ); SWIG_fail; + } + if ( !$input.is_empty() ) + { + Alen = (PLINT) ( _dim( $input, 0 ) ); + temp = $input.matrix_value(); + $1 = &temp( 0, 0 ); + } + else + { + $1 = NULL; + Alen = 0; + } +} +%typemap( freearg ) ( const PLFLT * ArrayNull ) +{ +} + // With trailing count but remember size to check others %typemap( in ) ( const PLFLT * Array, PLINT n ) ( Matrix temp ) { Modified: trunk/bindings/python/plplotcmodule.i =================================================================== --- trunk/bindings/python/plplotcmodule.i 2013-11-27 11:43:57 UTC (rev 12763) +++ trunk/bindings/python/plplotcmodule.i 2013-11-27 12:11:34 UTC (rev 12764) @@ -327,6 +327,33 @@ Py_CLEAR( tmp$argnum ); } +// trailing count and check consistency with previous +%typemap( in ) ( const PLFLT * ArrayCkNull, PLINT n ) ( PyArrayObject * tmp = NULL ) +{ + if ( $input != Py_None ) + { + tmp = (PyArrayObject *) myArray_ContiguousFromObject( $input, NPY_PLFLT, 1, 1 ); + if ( tmp == NULL ) + return NULL; + if ( PyArray_DIMS( tmp )[0] != Alen ) + { + PyErr_SetString( PyExc_ValueError, "Vectors must be same length." ); + return NULL; + } + $1 = (PLFLT *) PyArray_DATA( tmp ); + $2 = PyArray_DIMS( tmp )[0]; + } + else + { + $1 = NULL; + $2 = 0; + } +} +%typemap( freearg ) ( const PLFLT * ArrayCkNull, PLINT n ) +{ + Py_CLEAR( tmp$argnum ); +} + // no count, but check consistency with previous %typemap( in ) const PLFLT * ArrayCk( PyArrayObject * tmp = NULL ) { @@ -345,6 +372,8 @@ // no count, but check consistency with previous, or NULL %typemap( in ) const PLFLT * ArrayCkNull( PyArrayObject * tmp = NULL ) { + if ( $input != Py_None ) + { tmp = (PyArrayObject *) myArray_ContiguousFromObject( $input, NPY_PLFLT, 1, 1 ); if ( tmp == NULL ) return NULL; @@ -354,6 +383,11 @@ return NULL; } $1 = (PLFLT *) PyArray_DATA( tmp ); + } + else + { + $1 = NULL; + } } %typemap( freearg ) const PLFLT * ArrayCkNull { Py_CLEAR( tmp$argnum );} @@ -465,6 +499,26 @@ } %typemap( freearg ) const PLFLT * Array { Py_CLEAR( tmp$argnum );} + +// with no count +%typemap( in ) const PLFLT * ArrayNull( PyArrayObject * tmp = NULL ) +{ + if ( $input != Py_None ) + { + tmp = (PyArrayObject *) myArray_ContiguousFromObject( $input, NPY_PLFLT, 1, 1 ); + if ( tmp == NULL ) + return NULL; + Alen = PyArray_DIMS( tmp )[0]; + $1 = (PLFLT *) PyArray_DATA( tmp ); + } + else + { + $1 = NULL; + Alen = 0; + } +} +%typemap( freearg ) const PLFLT * ArrayNull { Py_CLEAR( tmp$argnum );} + // 2D array with trailing dimensions, check consistency with previous %typemap( in ) ( const PLFLT * *MatrixCk, PLINT nx, PLINT ny ) ( PyArrayObject * tmp = NULL ) { Modified: trunk/bindings/swig-support/plplotcapi.i =================================================================== --- trunk/bindings/swig-support/plplotcapi.i 2013-11-27 11:43:57 UTC (rev 12763) +++ trunk/bindings/swig-support/plplotcapi.i 2013-11-27 12:11:34 UTC (rev 12764) @@ -764,7 +764,7 @@ plstyl( PLINT n, const PLINT *Array, const PLINT *ArrayCk ); void -plsvect( const PLFLT *Array, const PLFLT *ArrayCk, PLINT n, PLBOOL fill ); +plsvect( const PLFLT *ArrayNull, const PLFLT *ArrayCkNull, PLINT n, PLBOOL fill ); void plsvpa( PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |