add std_vector items`
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13159 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6a20df2bb8
commit
cf16f43e51
1 changed files with 428 additions and 90 deletions
|
|
@ -11,86 +11,87 @@
|
||||||
template <>
|
template <>
|
||||||
struct traits_from_ptr<std::vector<double> > {
|
struct traits_from_ptr<std::vector<double> > {
|
||||||
static SEXP from (std::vector<double > *val, int owner = 0) {
|
static SEXP from (std::vector<double > *val, int owner = 0) {
|
||||||
SEXP result;
|
SEXP result;
|
||||||
PROTECT(result = Rf_allocVector(REALSXP, val->size()));
|
PROTECT(result = Rf_allocVector(REALSXP, val->size()));
|
||||||
for (unsigned pos = 0; pos < val->size(); pos++)
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
{
|
{
|
||||||
NUMERIC_POINTER(result)[pos] = ((*val)[pos]);
|
NUMERIC_POINTER(result)[pos] = ((*val)[pos]);
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// vectors of floats
|
// vectors of floats
|
||||||
template <>
|
template <>
|
||||||
struct traits_from_ptr<std::vector<float> > {
|
struct traits_from_ptr<std::vector<float> > {
|
||||||
static SEXP from (std::vector<float > *val, int owner = 0) {
|
static SEXP from (std::vector<float > *val, int owner = 0) {
|
||||||
SEXP result;
|
SEXP result;
|
||||||
PROTECT(result = Rf_allocVector(REALSXP, val->size()));
|
PROTECT(result = Rf_allocVector(REALSXP, val->size()));
|
||||||
for (unsigned pos = 0; pos < val->size(); pos++)
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
{
|
{
|
||||||
NUMERIC_POINTER(result)[pos] = ((*val)[pos]);
|
NUMERIC_POINTER(result)[pos] = ((*val)[pos]);
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// vectors of unsigned int
|
// vectors of unsigned int
|
||||||
template <>
|
template <>
|
||||||
struct traits_from_ptr<std::vector<unsigned int> > {
|
struct traits_from_ptr<std::vector<unsigned int> > {
|
||||||
static SEXP from (std::vector<unsigned int > *val, int owner = 0) {
|
static SEXP from (std::vector<unsigned int > *val, int owner = 0) {
|
||||||
SEXP result;
|
SEXP result;
|
||||||
PROTECT(result = Rf_allocVector(INTSXP, val->size()));
|
PROTECT(result = Rf_allocVector(INTSXP, val->size()));
|
||||||
for (unsigned pos = 0; pos < val->size(); pos++)
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
{
|
{
|
||||||
INTEGER_POINTER(result)[pos] = ((*val)[pos]);
|
INTEGER_POINTER(result)[pos] = ((*val)[pos]);
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// vectors of int
|
// vectors of int
|
||||||
template <>
|
template <>
|
||||||
struct traits_from_ptr<std::vector<int> > {
|
struct traits_from_ptr<std::vector<int> > {
|
||||||
static SEXP from (std::vector<int > *val, int owner = 0) {
|
static SEXP from (std::vector<int > *val, int owner = 0) {
|
||||||
SEXP result;
|
SEXP result;
|
||||||
PROTECT(result = Rf_allocVector(INTSXP, val->size()));
|
PROTECT(result = Rf_allocVector(INTSXP, val->size()));
|
||||||
for (unsigned pos = 0; pos < val->size(); pos++)
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
{
|
{
|
||||||
INTEGER_POINTER(result)[pos] = ((*val)[pos]);
|
INTEGER_POINTER(result)[pos] = ((*val)[pos]);
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// vectors of bool
|
// vectors of bool
|
||||||
template <>
|
template <>
|
||||||
struct traits_from_ptr<std::vector<bool> > {
|
struct traits_from_ptr<std::vector<bool> > {
|
||||||
static SEXP from (std::vector<bool> *val, int owner = 0) {
|
static SEXP from (std::vector<bool> *val, int owner = 0) {
|
||||||
SEXP result;
|
SEXP result;
|
||||||
PROTECT(result = Rf_allocVector(LGLSXP, val->size()));
|
PROTECT(result = Rf_allocVector(LGLSXP, val->size()));
|
||||||
for (unsigned pos = 0; pos < val->size(); pos++)
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
{
|
{
|
||||||
LOGICAL_POINTER(result)[pos] = ((*val)[pos]);
|
LOGICAL_POINTER(result)[pos] = ((*val)[pos]);
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return(result);
|
return(result);
|
||||||
//return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner);
|
//return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// vectors of strings
|
// vectors of strings
|
||||||
template <>
|
template <>
|
||||||
struct traits_from_ptr<std::vector<std::basic_string<char> > > {
|
struct traits_from_ptr<std::vector<std::basic_string<char> > > {
|
||||||
static SEXP from (std::vector<std::basic_string<char> > *val, int owner = 0) {
|
static SEXP from (std::vector<std::basic_string<char> > *val, int owner = 0) {
|
||||||
SEXP result;
|
SEXP result;
|
||||||
PROTECT(result = Rf_allocVector(STRSXP, val->size()));
|
PROTECT(result = Rf_allocVector(STRSXP, val->size()));
|
||||||
for (unsigned pos = 0; pos < val->size(); pos++)
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
{
|
{
|
||||||
CHARACTER_POINTER(result)[pos] = Rf_mkChar(((*val)[pos]).c_str());
|
CHARACTER_POINTER(result)[pos] = Rf_mkChar(((*val)[pos]).c_str());
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return(result);
|
return(result);
|
||||||
//return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner);
|
//return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -98,7 +99,7 @@
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct traits_from_ptr< std::vector< T > > {
|
struct traits_from_ptr< std::vector< T > > {
|
||||||
static SEXP from (std::vector< T > *val, int owner = 0) {
|
static SEXP from (std::vector< T > *val, int owner = 0) {
|
||||||
return SWIG_R_NewPointerObj(val, type_info< std::vector< T > >(), owner);
|
return SWIG_R_NewPointerObj(val, type_info< std::vector< T > >(), owner);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -111,12 +112,12 @@
|
||||||
p = new std::vector<double>(sexpsz);
|
p = new std::vector<double>(sexpsz);
|
||||||
double *S = NUMERIC_POINTER(obj);
|
double *S = NUMERIC_POINTER(obj);
|
||||||
for (unsigned pos = 0; pos < p->size(); pos++)
|
for (unsigned pos = 0; pos < p->size(); pos++)
|
||||||
{
|
{
|
||||||
(*p)[pos] = static_cast<double>(S[pos]);
|
(*p)[pos] = static_cast<double>(S[pos]);
|
||||||
}
|
}
|
||||||
int res = SWIG_OK;
|
int res = SWIG_OK;
|
||||||
if (SWIG_IsOK(res)) {
|
if (SWIG_IsOK(res)) {
|
||||||
if (val) *val = p;
|
if (val) *val = p;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -131,12 +132,12 @@
|
||||||
p = new std::vector<float>(sexpsz);
|
p = new std::vector<float>(sexpsz);
|
||||||
double *S = NUMERIC_POINTER(obj);
|
double *S = NUMERIC_POINTER(obj);
|
||||||
for (unsigned pos = 0; pos < p->size(); pos++)
|
for (unsigned pos = 0; pos < p->size(); pos++)
|
||||||
{
|
{
|
||||||
(*p)[pos] = static_cast<double>(S[pos]);
|
(*p)[pos] = static_cast<double>(S[pos]);
|
||||||
}
|
}
|
||||||
int res = SWIG_OK;
|
int res = SWIG_OK;
|
||||||
if (SWIG_IsOK(res)) {
|
if (SWIG_IsOK(res)) {
|
||||||
if (val) *val = p;
|
if (val) *val = p;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -152,12 +153,12 @@
|
||||||
PROTECT(coerced = Rf_coerceVector(obj, INTSXP));
|
PROTECT(coerced = Rf_coerceVector(obj, INTSXP));
|
||||||
int *S = INTEGER_POINTER(coerced);
|
int *S = INTEGER_POINTER(coerced);
|
||||||
for (unsigned pos = 0; pos < p->size(); pos++)
|
for (unsigned pos = 0; pos < p->size(); pos++)
|
||||||
{
|
{
|
||||||
(*p)[pos] = static_cast<unsigned int>(S[pos]);
|
(*p)[pos] = static_cast<unsigned int>(S[pos]);
|
||||||
}
|
}
|
||||||
int res = SWIG_OK;
|
int res = SWIG_OK;
|
||||||
if (SWIG_IsOK(res)) {
|
if (SWIG_IsOK(res)) {
|
||||||
if (val) *val = p;
|
if (val) *val = p;
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -175,12 +176,35 @@
|
||||||
PROTECT(coerced = Rf_coerceVector(obj, INTSXP));
|
PROTECT(coerced = Rf_coerceVector(obj, INTSXP));
|
||||||
int *S = INTEGER_POINTER(coerced);
|
int *S = INTEGER_POINTER(coerced);
|
||||||
for (unsigned pos = 0; pos < p->size(); pos++)
|
for (unsigned pos = 0; pos < p->size(); pos++)
|
||||||
{
|
{
|
||||||
(*p)[pos] = static_cast<int>(S[pos]);
|
(*p)[pos] = static_cast<int>(S[pos]);
|
||||||
}
|
}
|
||||||
int res = SWIG_OK;
|
int res = SWIG_OK;
|
||||||
if (SWIG_IsOK(res)) {
|
if (SWIG_IsOK(res)) {
|
||||||
if (val) *val = p;
|
if (val) *val = p;
|
||||||
|
}
|
||||||
|
UNPROTECT(1);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct traits_asptr < std::vector<bool> > {
|
||||||
|
static int asptr(SEXP obj, std::vector<bool> **val) {
|
||||||
|
std::vector<bool> *p;
|
||||||
|
// not sure how to check the size of the SEXP obj is correct
|
||||||
|
int sexpsz = Rf_length(obj);
|
||||||
|
p = new std::vector<bool>(sexpsz);
|
||||||
|
SEXP coerced;
|
||||||
|
PROTECT(coerced = Rf_coerceVector(obj, LGLSXP));
|
||||||
|
int *S = LOGICAL_POINTER(coerced);
|
||||||
|
for (unsigned pos = 0; pos < p->size(); pos++)
|
||||||
|
{
|
||||||
|
(*p)[pos] = static_cast<bool>(S[pos]);
|
||||||
|
}
|
||||||
|
int res = SWIG_OK;
|
||||||
|
if (SWIG_IsOK(res)) {
|
||||||
|
if (val) *val = p;
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -192,14 +216,273 @@
|
||||||
struct traits_asptr < std::vector<T> > {
|
struct traits_asptr < std::vector<T> > {
|
||||||
static int asptr(SEXP obj, std::vector<T> **val) {
|
static int asptr(SEXP obj, std::vector<T> **val) {
|
||||||
std::vector<T> *p;
|
std::vector<T> *p;
|
||||||
|
Rprintf("my asptr\n");
|
||||||
int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector<T> >(), 0);
|
int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector<T> >(), 0);
|
||||||
if (SWIG_IsOK(res)) {
|
if (SWIG_IsOK(res)) {
|
||||||
if (val) *val = p;
|
if (val) *val = p;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// now for vectors of vectors. These will be represented as lists of vectors on the
|
||||||
|
// catch all that does everything with vectors
|
||||||
|
template <>
|
||||||
|
struct traits_from_ptr<std::vector<std::vector<unsigned int> > > {
|
||||||
|
static SEXP from (std::vector< std::vector<unsigned int > > *val, int owner = 0) {
|
||||||
|
SEXP result;
|
||||||
|
// allocate the R list
|
||||||
|
PROTECT(result = Rf_allocVector(VECSXP, val->size()));
|
||||||
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
|
{
|
||||||
|
// allocate the R vector
|
||||||
|
SET_VECTOR_ELT(result, pos, Rf_allocVector(INTSXP, val->at(pos).size()));
|
||||||
|
// Fill the R vector
|
||||||
|
for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos)
|
||||||
|
{
|
||||||
|
INTEGER_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast<int>(val->at(pos).at(vpos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNPROTECT(1);
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct traits_from_ptr<std::vector<std::vector<int> > > {
|
||||||
|
static SEXP from (std::vector< std::vector<int > > *val, int owner = 0) {
|
||||||
|
SEXP result;
|
||||||
|
// allocate the R list
|
||||||
|
PROTECT(result = Rf_allocVector(VECSXP, val->size()));
|
||||||
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
|
{
|
||||||
|
// allocate the R vector
|
||||||
|
SET_VECTOR_ELT(result, pos, Rf_allocVector(INTSXP, val->at(pos).size()));
|
||||||
|
// Fill the R vector
|
||||||
|
for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos)
|
||||||
|
{
|
||||||
|
INTEGER_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast<int>(val->at(pos).at(vpos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNPROTECT(1);
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct traits_from_ptr<std::vector<std::vector<float> > > {
|
||||||
|
static SEXP from (std::vector< std::vector<float > > *val, int owner = 0) {
|
||||||
|
SEXP result;
|
||||||
|
// allocate the R list
|
||||||
|
PROTECT(result = Rf_allocVector(VECSXP, val->size()));
|
||||||
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
|
{
|
||||||
|
// allocate the R vector
|
||||||
|
SET_VECTOR_ELT(result, pos, Rf_allocVector(REALSXP, val->at(pos).size()));
|
||||||
|
// Fill the R vector
|
||||||
|
for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos)
|
||||||
|
{
|
||||||
|
NUMERIC_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast<double>(val->at(pos).at(vpos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNPROTECT(1);
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct traits_from_ptr<std::vector<std::vector<double> > > {
|
||||||
|
static SEXP from (std::vector< std::vector<double > > *val, int owner = 0) {
|
||||||
|
SEXP result;
|
||||||
|
// allocate the R list
|
||||||
|
PROTECT(result = Rf_allocVector(VECSXP, val->size()));
|
||||||
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
|
{
|
||||||
|
// allocate the R vector
|
||||||
|
SET_VECTOR_ELT(result, pos, Rf_allocVector(REALSXP, val->at(pos).size()));
|
||||||
|
// Fill the R vector
|
||||||
|
for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos)
|
||||||
|
{
|
||||||
|
NUMERIC_POINTER(VECTOR_ELT(result, pos))[vpos] = static_cast<double>(val->at(pos).at(vpos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNPROTECT(1);
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct traits_from_ptr<std::vector<std::vector<bool> > > {
|
||||||
|
static SEXP from (std::vector< std::vector<bool> > *val, int owner = 0) {
|
||||||
|
SEXP result;
|
||||||
|
// allocate the R list
|
||||||
|
PROTECT(result = Rf_allocVector(VECSXP, val->size()));
|
||||||
|
for (unsigned pos = 0; pos < val->size(); pos++)
|
||||||
|
{
|
||||||
|
// allocate the R vector
|
||||||
|
SET_VECTOR_ELT(result, pos, Rf_allocVector(LGLSXP, val->at(pos).size()));
|
||||||
|
// Fill the R vector
|
||||||
|
for (unsigned vpos = 0; vpos < val->at(pos).size(); ++vpos)
|
||||||
|
{
|
||||||
|
LOGICAL_POINTER(VECTOR_ELT(result, pos))[vpos] = (val->at(pos).at(vpos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNPROTECT(1);
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct traits_from_ptr< std::vector < std::vector< T > > > {
|
||||||
|
static SEXP from (std::vector < std::vector< T > > *val, int owner = 0) {
|
||||||
|
return SWIG_R_NewPointerObj(val, type_info< std::vector < std::vector< T > > >(), owner);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// R side
|
||||||
|
template <>
|
||||||
|
struct traits_asptr < std::vector< std::vector<unsigned int> > > {
|
||||||
|
static int asptr(SEXP obj, std::vector< std::vector<unsigned int> > **val) {
|
||||||
|
std::vector <std::vector<unsigned int> > *p;
|
||||||
|
// this is the length of the list
|
||||||
|
unsigned int sexpsz = Rf_length(obj);
|
||||||
|
p = new std::vector< std::vector<unsigned int> > (sexpsz);
|
||||||
|
|
||||||
|
for (unsigned listpos = 0; listpos < sexpsz; ++listpos)
|
||||||
|
{
|
||||||
|
unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos));
|
||||||
|
for (unsigned vpos = 0; vpos < vecsize; ++vpos)
|
||||||
|
{
|
||||||
|
(*p)[listpos].push_back(static_cast<int>(INTEGER_POINTER(VECTOR_ELT(obj, listpos))[vpos]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = SWIG_OK;
|
||||||
|
|
||||||
|
if (SWIG_IsOK(res)) {
|
||||||
|
if (val) *val = p;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct traits_asptr < std::vector< std::vector< int> > > {
|
||||||
|
static int asptr(SEXP obj, std::vector< std::vector< int> > **val) {
|
||||||
|
std::vector <std::vector< int> > *p;
|
||||||
|
// this is the length of the list
|
||||||
|
unsigned int sexpsz = Rf_length(obj);
|
||||||
|
p = new std::vector< std::vector< int> > (sexpsz);
|
||||||
|
|
||||||
|
for (unsigned listpos = 0; listpos < sexpsz; ++listpos)
|
||||||
|
{
|
||||||
|
unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos));
|
||||||
|
for (unsigned vpos = 0; vpos < vecsize; ++vpos)
|
||||||
|
{
|
||||||
|
(*p)[listpos].push_back(static_cast<int>(INTEGER_POINTER(VECTOR_ELT(obj, listpos))[vpos]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = SWIG_OK;
|
||||||
|
|
||||||
|
if (SWIG_IsOK(res)) {
|
||||||
|
if (val) *val = p;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct traits_asptr < std::vector< std::vector< float> > > {
|
||||||
|
static int asptr(SEXP obj, std::vector< std::vector< float> > **val) {
|
||||||
|
std::vector <std::vector< float> > *p;
|
||||||
|
// this is the length of the list
|
||||||
|
unsigned int sexpsz = Rf_length(obj);
|
||||||
|
p = new std::vector< std::vector< float> > (sexpsz);
|
||||||
|
|
||||||
|
for (unsigned listpos = 0; listpos < sexpsz; ++listpos)
|
||||||
|
{
|
||||||
|
unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos));
|
||||||
|
for (unsigned vpos = 0; vpos < vecsize; ++vpos)
|
||||||
|
{
|
||||||
|
(*p)[listpos].push_back(static_cast<float>(NUMERIC_POINTER(VECTOR_ELT(obj, listpos))[vpos]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = SWIG_OK;
|
||||||
|
|
||||||
|
if (SWIG_IsOK(res)) {
|
||||||
|
if (val) *val = p;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct traits_asptr < std::vector< std::vector< double> > > {
|
||||||
|
static int asptr(SEXP obj, std::vector< std::vector< double> > **val) {
|
||||||
|
std::vector <std::vector< double> > *p;
|
||||||
|
// this is the length of the list
|
||||||
|
unsigned int sexpsz = Rf_length(obj);
|
||||||
|
p = new std::vector< std::vector< double> > (sexpsz);
|
||||||
|
|
||||||
|
for (unsigned listpos = 0; listpos < sexpsz; ++listpos)
|
||||||
|
{
|
||||||
|
unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos));
|
||||||
|
for (unsigned vpos = 0; vpos < vecsize; ++vpos)
|
||||||
|
{
|
||||||
|
(*p)[listpos].push_back(static_cast<double>(NUMERIC_POINTER(VECTOR_ELT(obj, listpos))[vpos]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = SWIG_OK;
|
||||||
|
|
||||||
|
if (SWIG_IsOK(res)) {
|
||||||
|
if (val) *val = p;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct traits_asptr < std::vector< std::vector< bool > > > {
|
||||||
|
static int asptr(SEXP obj, std::vector< std::vector< bool> > **val) {
|
||||||
|
std::vector <std::vector< bool > > *p;
|
||||||
|
// this is the length of the list
|
||||||
|
unsigned int sexpsz = Rf_length(obj);
|
||||||
|
p = new std::vector< std::vector< bool > > (sexpsz);
|
||||||
|
|
||||||
|
for (unsigned listpos = 0; listpos < sexpsz; ++listpos)
|
||||||
|
{
|
||||||
|
unsigned vecsize = Rf_length(VECTOR_ELT(obj, listpos));
|
||||||
|
for (unsigned vpos = 0; vpos < vecsize; ++vpos)
|
||||||
|
{
|
||||||
|
(*p)[listpos].push_back(static_cast<bool>(LOGICAL_POINTER(VECTOR_ELT(obj, listpos))[vpos]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = SWIG_OK;
|
||||||
|
|
||||||
|
if (SWIG_IsOK(res)) {
|
||||||
|
if (val) *val = p;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// catchall
|
||||||
|
template <typename T>
|
||||||
|
struct traits_asptr < std::vector< std::vector<T> > > {
|
||||||
|
static int asptr(SEXP obj, std::vector< std::vector<T> > **val) {
|
||||||
|
std::vector< std::vector<T> > *p;
|
||||||
|
Rprintf("vector of vectors - unsupported content\n");
|
||||||
|
int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector< std::vector<T> > > (), 0);
|
||||||
|
if (SWIG_IsOK(res)) {
|
||||||
|
if (val) *val = p;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
@ -209,12 +492,12 @@
|
||||||
|
|
||||||
%define %traits_type_name(Type...)
|
%define %traits_type_name(Type...)
|
||||||
%fragment(SWIG_Traits_frag(Type), "header",
|
%fragment(SWIG_Traits_frag(Type), "header",
|
||||||
fragment="StdTraits",fragment="StdVectorTraits") {
|
fragment="StdTraits",fragment="StdVectorTraits") {
|
||||||
namespace swig {
|
namespace swig {
|
||||||
template <> struct traits< Type > {
|
template <> struct traits< Type > {
|
||||||
typedef pointer_category category;
|
typedef pointer_category category;
|
||||||
static const char* type_name() {
|
static const char* type_name() {
|
||||||
return #Type;
|
return #Type;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -225,33 +508,72 @@
|
||||||
|
|
||||||
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<double>)
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<double>)
|
||||||
%traits_type_name(std::vector<double>)
|
%traits_type_name(std::vector<double>)
|
||||||
%typemap("rtypecheck") std::vector<double> %{ is.numeric($arg) %}
|
%typemap("rtypecheck") std::vector<double>, std::vector<double> const, std::vector<double> const&
|
||||||
|
%{ is.numeric($arg) %}
|
||||||
%typemap("rtype") std::vector<double> "numeric"
|
%typemap("rtype") std::vector<double> "numeric"
|
||||||
|
|
||||||
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<float>)
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<float>)
|
||||||
%traits_type_name(std::vector<float>)
|
%traits_type_name(std::vector<float>)
|
||||||
%typemap("rtypecheck") std::vector<float> %{ is.numeric($arg) %}
|
%typemap("rtypecheck") std::vector<float>, std::vector<float> const, std::vector<float> const&
|
||||||
|
%{ is.numeric($arg) %}
|
||||||
%typemap("rtype") std::vector<float> "numeric"
|
%typemap("rtype") std::vector<float> "numeric"
|
||||||
|
|
||||||
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool>);
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool>);
|
||||||
%traits_type_name(std::vector<bool>);
|
%traits_type_name(std::vector<bool>);
|
||||||
%typemap("rtypecheck") std::vector<bool> %{ is.logical($arg) %}
|
%typemap("rtypecheck") std::vector<bool> , std::vector<bool> const, std::vector<bool> const&
|
||||||
|
%{ is.logical($arg) %}
|
||||||
%typemap("rtype") std::vector<bool> "logical"
|
%typemap("rtype") std::vector<bool> "logical"
|
||||||
|
%typemap("scoercein") std::vector<bool> "$input = as.logical($input);";
|
||||||
|
|
||||||
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<int>);
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<int>);
|
||||||
%traits_type_name(std::vector<int>);
|
%traits_type_name(std::vector<int>);
|
||||||
%typemap("rtypecheck") std::vector<int>
|
%typemap("rtypecheck") std::vector<int> , std::vector<int> const, std::vector<int> const&
|
||||||
%{ is.integer($arg) || is.numeric($arg) %}
|
%{ is.integer($arg) || is.numeric($arg) %}
|
||||||
%typemap("rtype") std::vector<int> "integer"
|
%typemap("rtype") std::vector<int> "integer"
|
||||||
%typemap("scoercein") std::vector<int> "$input = as.integer($input);";
|
%typemap("scoercein") std::vector<int> "$input = as.integer($input);";
|
||||||
|
|
||||||
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<unsigned int>);
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<unsigned int>);
|
||||||
%traits_type_name(std::vector<unsigned int>);
|
%traits_type_name(std::vector<unsigned int>);
|
||||||
%typemap("rtypecheck") std::vector<unsigned int>
|
%typemap("rtypecheck") std::vector<unsigned int>, std::vector<unsigned int> const, std::vector<unsigned int> const&
|
||||||
%{ is.integer($arg) || is.numeric($arg) %}
|
%{ is.integer($arg) || is.numeric($arg) %}
|
||||||
%typemap("rtype") std::vector<unsigned int> "integer"
|
%typemap("rtype") std::vector<unsigned int> "integer"
|
||||||
%typemap("scoercein") std::vector<unsigned int> "$input = as.integer($input);";
|
%typemap("scoercein") std::vector<unsigned int> "$input = as.integer($input);";
|
||||||
|
|
||||||
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<unsigned int> >);
|
||||||
|
%traits_type_name(std::vector< std::vector<unsigned int> >);
|
||||||
|
%typemap("rtypecheck") std::vector<std::vector<unsigned int> >, std::vector<std::vector<unsigned int> > const, std::vector<std::vector<unsigned int> >const&
|
||||||
|
%{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %}
|
||||||
|
%typemap("rtype") std::vector<std::vector<unsigned int> > "list"
|
||||||
|
%typemap("scoercein") std::vector< std::vector<unsigned int> > "$input = lapply($input, as.integer);";
|
||||||
|
|
||||||
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<int> >);
|
||||||
|
%traits_type_name(std::vector< std::vector<int> >);
|
||||||
|
%typemap("rtypecheck") std::vector<std::vector<int> >, std::vector<std::vector<int> > const, std::vector<std::vector<int> >const&
|
||||||
|
%{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %}
|
||||||
|
%typemap("rtype") std::vector<std::vector<int> > "list"
|
||||||
|
%typemap("scoercein") std::vector< std::vector<int> > "$input = lapply($input, as.integer);";
|
||||||
|
|
||||||
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<float> >);
|
||||||
|
%traits_type_name(std::vector< std::vector<float> >);
|
||||||
|
%typemap("rtypecheck") std::vector<std::vector<float> >, std::vector<std::vector<float> > const, std::vector<std::vector<float> >const&
|
||||||
|
%{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %}
|
||||||
|
%typemap("rtype") std::vector<std::vector<float> > "list"
|
||||||
|
%typemap("scoercein") std::vector< std::vector<float> > "$input = lapply($input, as.numeric);";
|
||||||
|
|
||||||
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<double> >);
|
||||||
|
%traits_type_name(std::vector< std::vector<double> >);
|
||||||
|
%typemap("rtypecheck") std::vector<std::vector<double> >, std::vector<std::vector<double> > const, std::vector<std::vector<double> >const&
|
||||||
|
%{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %}
|
||||||
|
%typemap("rtype") std::vector<std::vector<double> > "list"
|
||||||
|
%typemap("scoercein") std::vector< std::vector<double> > "$input = lapply($input, as.numeric);";
|
||||||
|
|
||||||
|
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<bool> >);
|
||||||
|
%traits_type_name(std::vector< std::vector<bool> >);
|
||||||
|
%typemap("rtypecheck") std::vector<std::vector<bool> >, std::vector<std::vector<bool> > const, std::vector<std::vector<bool> >const&
|
||||||
|
%{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %}
|
||||||
|
%typemap("rtype") std::vector<std::vector<bool> > "list"
|
||||||
|
%typemap("scoercein") std::vector< std::vector<bool> > "$input = lapply($input, as.logical);";
|
||||||
|
|
||||||
// we don't want these to be given R classes as they
|
// we don't want these to be given R classes as they
|
||||||
// have already been turned into R vectors.
|
// have already been turned into R vectors.
|
||||||
%typemap(scoerceout) std::vector<double>,
|
%typemap(scoerceout) std::vector<double>,
|
||||||
|
|
@ -262,7 +584,23 @@
|
||||||
std::vector<bool> &,
|
std::vector<bool> &,
|
||||||
std::vector<unsigned int>,
|
std::vector<unsigned int>,
|
||||||
std::vector<unsigned int> *,
|
std::vector<unsigned int> *,
|
||||||
std::vector<unsigned int> &
|
std::vector<unsigned int> &,
|
||||||
|
// vectors of vectors
|
||||||
|
std::vector< std::vector<unsigned int> >,
|
||||||
|
std::vector< std::vector<unsigned int> >*,
|
||||||
|
std::vector< std::vector<unsigned int> >&,
|
||||||
|
std::vector< std::vector<int> >,
|
||||||
|
std::vector< std::vector<int> >*,
|
||||||
|
std::vector< std::vector<int> >&,
|
||||||
|
std::vector< std::vector<float> >,
|
||||||
|
std::vector< std::vector<float> >*,
|
||||||
|
std::vector< std::vector<float> >&,
|
||||||
|
std::vector< std::vector<double> >,
|
||||||
|
std::vector< std::vector<double> >*,
|
||||||
|
std::vector< std::vector<double> >&,
|
||||||
|
std::vector< std::vector<bool> >,
|
||||||
|
std::vector< std::vector<bool> >*,
|
||||||
|
std::vector< std::vector<bool> >&
|
||||||
|
|
||||||
|
|
||||||
%{ %}
|
%{ %}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue