summaryrefslogtreecommitdiff
path: root/Lib/r
diff options
context:
space:
mode:
authorRichard Beare <Richard.Beare@gmail.com>2016-04-04 16:06:27 +1000
committerRichard Beare <richard.beare@monash.edu>2016-04-05 09:39:47 +1000
commit720c4d3dfc43f4df40aa598e0b6b499ed310b546 (patch)
treee4feb26cb0c2486c0a0ba279a9a321e9b9eb4857 /Lib/r
parenta97441613eea16620505f30849713b99d2ac9051 (diff)
downloadswig-720c4d3dfc43f4df40aa598e0b6b499ed310b546.tar.gz
added R string vector to C++ std::vector of strings
Diffstat (limited to 'Lib/r')
-rw-r--r--Lib/r/std_vector.i38
1 files changed, 36 insertions, 2 deletions
diff --git a/Lib/r/std_vector.i b/Lib/r/std_vector.i
index d10097c1e..cd9f61468 100644
--- a/Lib/r/std_vector.i
+++ b/Lib/r/std_vector.i
@@ -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>);