added R string vector to C++ std::vector of strings
This commit is contained in:
parent
a97441613e
commit
720c4d3dfc
1 changed files with 36 additions and 2 deletions
|
|
@ -192,7 +192,6 @@
|
|||
}
|
||||
UNPROTECT(1);
|
||||
return(result);
|
||||
//return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -208,7 +207,6 @@
|
|||
}
|
||||
UNPROTECT(1);
|
||||
return(result);
|
||||
//return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -516,6 +514,31 @@
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct traits_asptr < std::vector<std::basic_string<char> > > {
|
||||
static int asptr(SEXP obj, std::vector<std::basic_string<char> > **val) {
|
||||
std::vector<std::basic_string<char> > *p;
|
||||
// R character vectors are STRSXP containing CHARSXP
|
||||
// access a CHARSXP using STRING_ELT
|
||||
int sexpsz = Rf_length(obj);
|
||||
p = new std::vector<std::basic_string<char> >(sexpsz);
|
||||
SEXP coerced;
|
||||
PROTECT(coerced = Rf_coerceVector(obj, STRSXP));
|
||||
//SEXP *S = CHARACTER_POINTER(coerced);
|
||||
for (unsigned pos = 0; pos < p->size(); pos++)
|
||||
{
|
||||
const char * thecstring = CHAR(STRING_ELT(coerced, pos));
|
||||
(*p)[pos] = std::basic_string<char>(thecstring);
|
||||
}
|
||||
int res = SWIG_OK;
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val) *val = p;
|
||||
}
|
||||
UNPROTECT(1);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
// catchall for R to vector conversion
|
||||
template <typename T>
|
||||
struct traits_asptr < std::vector<T> > {
|
||||
|
|
@ -846,6 +869,17 @@
|
|||
%typemap("rtype") std::vector<int> "integer"
|
||||
%typemap("scoercein") std::vector<int> , std::vector<int> const, std::vector<int> const& "$input = as.integer($input);";
|
||||
|
||||
// strings
|
||||
%typemap("rtype") std::vector< std::basic_string<char> >, std::vector< std::basic_string<char> > *,
|
||||
std::vector< std::basic_string<char> > & "character";
|
||||
|
||||
%typemap("scoercein") std::vector< std::basic_string<char> >, std::vector< std::basic_string<char> > *,
|
||||
std::vector< std::basic_string<char> > & "$input = as.character($input);";
|
||||
|
||||
%typemap("scoerceout") std::vector< std::basic_string<char> >, std::vector< std::basic_string<char> > *,
|
||||
std::vector< std::basic_string<char> > &
|
||||
%{ %}
|
||||
|
||||
// all the related integer vectors
|
||||
// signed
|
||||
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<signed char>);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue