scilab: fix constructor_copy and other STL container tests

finally vector<class> and vector<enum> are not supported
This commit is contained in:
Simon Marchetto 2014-03-10 15:21:46 +01:00
commit dc5de4b5c9
7 changed files with 37 additions and 58 deletions

View file

@ -43,8 +43,6 @@
fragment="StdTraits",
fragment="SwigSciIterator_T")
{
%#include <stdio.h>
namespace swig
{
template <class T>
@ -63,12 +61,7 @@ namespace swig
{
try
{
T value;
if (traits_asval_sequenceitem<T>::asval(_seq, _piSeqAddr, _index, &value) == SWIG_OK)
{
return value;
}
else throw std::invalid_argument("Cannot get sequence item.");
return traits_asval_sequenceitem<T>::asval(_seq, _piSeqAddr, _index);
}
catch (std::exception& e)
{

View file

@ -34,11 +34,6 @@
//
%fragment(SWIG_Traits_Sequence_frag(ptr), "header",
fragment=SWIG_AsCheck_Sequence_frag(int),
fragment=SWIG_AsGet_Sequence_frag(int),
fragment=SWIG_AsSize_Sequence_frag(int),
fragment=SWIG_FromCreate_Sequence_frag(int),
fragment=SWIG_FromSet_Sequence_frag(int),
fragment=SWIG_AsCheck_Sequence_frag(ptr),
fragment=SWIG_AsGet_Sequence_frag(ptr),
fragment=SWIG_AsSize_Sequence_frag(ptr),
@ -47,30 +42,28 @@
fragment="StdTraits") {
namespace swig {
// For sequence of values, considers int as default type (so it works for enums)
// Error returned for sequence containers of default item type
template <typename T> struct traits_as_sequence {
static int check(SwigSciObject obj) {
return SWIG_AsCheck_Sequence_dec(int)(obj);
SWIG_Error(SWIG_TypeError, type_name<T>());
}
static int get(SwigSciObject obj, void **sequence) {
return SWIG_AsGet_Sequence_dec(int)(obj, (int **)sequence);
SWIG_Error(SWIG_TypeError, type_name<T>());
}
static int size(SwigSciObject obj, int *size) {
return SWIG_AsSize_Sequence_dec(int)(obj, size);
SWIG_Error(SWIG_TypeError, type_name<T>());
}
};
template <typename T> struct traits_from_sequence {
static int create(int size, void **sequence) {
return SWIG_FromCreate_Sequence_dec(int)(size, (int **)sequence);
SWIG_Error(SWIG_TypeError, type_name<T>());
}
static SwigSciObject set(int size, void *sequence) {
return SWIG_FromSet_Sequence_dec(int)(size, (int *)sequence);
SWIG_Error(SWIG_TypeError, type_name<T>());
}
};
// For sequence of pointers
// Support sequence containers of pointers
template <typename T> struct traits_as_sequence<T*> {
static int check(SwigSciObject obj) {
return SWIG_AsCheck_Sequence_dec(ptr)(obj);
@ -132,31 +125,27 @@ namespace swig {
//
%fragment(SWIG_Traits_SequenceItem_frag(ptr), "header",
fragment=SWIG_AsVal_SequenceItem_frag(int),
fragment=SWIG_From_SequenceItem_frag(int),
fragment=SWIG_AsVal_SequenceItem_frag(ptr),
fragment=SWIG_From_SequenceItem_frag(ptr),
fragment="StdTraits") {
namespace swig {
// For sequence of values, considers int as default type (so it works for enums)
// Error returned for sequence containers of default item type
template <typename T> struct traits_asval_sequenceitem {
static int asval(SwigSciObject obj, void *pSequence, int iItemIndex, T *pItemValue) {
return SWIG_AsVal_SequenceItem_dec(int)(obj, (int *)pSequence, iItemIndex, (int *)pItemValue);
static T asval(SwigSciObject obj, void *pSequence, int iItemIndex) {
SWIG_Error(SWIG_TypeError, type_name<T>());
}
};
template <typename T> struct traits_from_sequenceitem {
static int from(void *pSequence, int iItemIndex, T itemValue) {
return SWIG_From_SequenceItem_dec(int)((int *)pSequence, iItemIndex, (int)itemValue);
SWIG_Error(SWIG_TypeError, type_name<T>());
}
};
// Sequence of pointers
// Support sequence containers of pointers
template <typename T> struct traits_asval_sequenceitem<T*> {
static int asval(SwigSciObject obj, void *pSequence, int iItemIndex, T **pItemValue) {
return SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (void **)pItemValue);
static T* asval(SwigSciObject obj, void *pSequence, int iItemIndex) {
return static_cast<T*>(SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex));
}
};
template <typename T> struct traits_from_sequenceitem<T*> {
@ -175,8 +164,8 @@ namespace swig {
namespace swig {
template <> struct traits_asval_sequenceitem<CppType > {
static int asval(SwigSciObject obj, void *pSequence, int iItemIndex, CppType *pItemValue) {
return SWIG_AsVal_SequenceItem_dec(CppType)(obj, (ScilabType *)pSequence, iItemIndex, pItemValue);
static CppType asval(SwigSciObject obj, void *pSequence, int iItemIndex) {
return SWIG_AsVal_SequenceItem_dec(CppType)(obj, (ScilabType *)pSequence, iItemIndex);
}
};
template <> struct traits_from_sequenceitem<CppType > {

View file

@ -84,10 +84,9 @@ SWIG_FromSet_Sequence_dec(bool)(int _size, int *_sequence) {
%fragment(SWIG_AsVal_SequenceItem_frag(bool), "header") {
SWIGINTERN int
SWIG_AsVal_SequenceItem_dec(bool)(SwigSciObject _obj, int *_pSequence, int _iItemIndex, bool *_pItemValue) {
*_pItemValue = _pSequence[_iItemIndex];
return SWIG_OK;
SWIGINTERN bool
SWIG_AsVal_SequenceItem_dec(bool)(SwigSciObject _obj, int *_pSequence, int _iItemIndex) {
return _pSequence[_iItemIndex];
}
}

View file

@ -84,10 +84,9 @@ SWIG_FromSet_Sequence_dec(double)(int _size, double *_sequence) {
%fragment(SWIG_AsVal_SequenceItem_frag(double), "header") {
SWIGINTERN int
SWIG_AsVal_SequenceItem_dec(double)(SwigSciObject _obj, double *_pSequence, int _iItemIndex, double *_pItemValue) {
*_pItemValue = _pSequence[_iItemIndex];
return SWIG_OK;
SWIGINTERN double
SWIG_AsVal_SequenceItem_dec(double)(SwigSciObject _obj, double *_pSequence, int _iItemIndex) {
return _pSequence[_iItemIndex];
}
}

View file

@ -84,9 +84,8 @@ SWIG_FromSet_Sequence_dec(int)(int _size, int *_sequence) {
%fragment(SWIG_AsVal_SequenceItem_frag(int), "header") {
SWIGINTERN int
SWIG_AsVal_SequenceItem_dec(int)(SwigSciObject _obj, int *_pSequence, int _iItemIndex, int *_pItemValue) {
*_pItemValue = _pSequence[_iItemIndex];
return SWIG_OK;
SWIG_AsVal_SequenceItem_dec(int)(SwigSciObject _obj, int *_pSequence, int _iItemIndex) {
return _pSequence[_iItemIndex];
}
}

View file

@ -74,41 +74,42 @@ SWIG_FromSet_Sequence_dec(ptr)(int _size, long long *_sequence) {
%fragment(SWIG_AsVal_SequenceItem_frag(ptr), "header") {
SWIGINTERN int
SWIG_AsVal_SequenceItem_dec(ptr)(SwigSciObject _obj, int *_piSequence, int _itemIndex, void **_pItemValue)
SWIGINTERN void*
SWIG_AsVal_SequenceItem_dec(ptr)(SwigSciObject _obj, int *_piSequence, int _itemIndex)
{
SciErr sciErr;
int *piItemAddr;
int iType;
void* pItemValue = NULL;
sciErr = getListItemAddress(pvApiCtx, _piSequence, _itemIndex + 1, &piItemAddr);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
return NULL;
}
sciErr = getVarType(pvApiCtx, piItemAddr, &iType);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
return NULL;
}
if (iType != sci_pointer)
{
Scierror(999, _("%s: Wrong type for input argument #%d: A pointer is expected at list item #%d.\n"), fname, _obj, _itemIndex + 1);
return SWIG_ERROR;
return NULL;
}
sciErr = getPointerInList(pvApiCtx, _piSequence, _itemIndex + 1, (void **)_pItemValue);
sciErr = getPointerInList(pvApiCtx, _piSequence, _itemIndex + 1, &pItemValue);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
return NULL;
}
return SWIG_OK;
return pItemValue;
}
}

View file

@ -76,10 +76,9 @@ SWIG_FromSet_Sequence_dec(std::string)(int _size, char **_sequence) {
%fragment(SWIG_AsVal_SequenceItem_frag(std::string), "header") {
SWIGINTERN int
SWIG_AsVal_SequenceItem_dec(std::string)(SwigSciObject _obj, char **_pSequence, int _iItemIndex, std::string *_pItemValue) {
*_pItemValue = std::string(_pSequence[_iItemIndex]);
return SWIG_OK;
SWIGINTERN std::string
SWIG_AsVal_SequenceItem_dec(std::string)(SwigSciObject _obj, char **_pSequence, int _iItemIndex) {
return std::string(_pSequence[_iItemIndex]);
}
}