[Rcpp-commits] r4232 - in pkg/Rcpp: . inst/include/Rcpp inst/include/Rcpp/traits
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Feb 2 17:44:13 CET 2013
Author: romain
Date: 2013-02-02 17:44:13 +0100 (Sat, 02 Feb 2013)
New Revision: 4232
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/as.h
pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h
Log:
support for as<wstring>
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2013-02-02 16:17:21 UTC (rev 4231)
+++ pkg/Rcpp/ChangeLog 2013-02-02 16:44:13 UTC (rev 4232)
@@ -8,7 +8,8 @@
* include/Rcpp/vector/VectorBase.h : correct operators ++ and --
* unitTests/cpp/Vector.cpp: new unit tests
* unitTests/runit.Vector.R: new unit tests
- * src/api.cpp: comment dropTrailing0 which is not used anymore
+ * src/api.cpp: comment dropTrailing0 which is not used anymore
+ * include/Rcpp/as.h: support for as<wstring>
2013-01-15 Dirk Eddelbuettel <edd at debian.org>
Modified: pkg/Rcpp/inst/include/Rcpp/as.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/as.h 2013-02-02 16:17:21 UTC (rev 4231)
+++ pkg/Rcpp/inst/include/Rcpp/as.h 2013-02-02 16:44:13 UTC (rev 4232)
@@ -2,7 +2,8 @@
//
// as.h: Rcpp R/C++ interface class library -- convert SEXP to C++ objects
//
-// Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2009 - 2013 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2013 Rice University
//
// This file is part of Rcpp.
//
@@ -43,15 +44,23 @@
}
template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_string_tag ) {
- if( ! ::Rf_isString(x) ){
+ if( ! ::Rf_isString(x) )
throw ::Rcpp::not_compatible( "expecting a string" ) ;
- }
- if (Rf_length(x) != 1) {
+ if (Rf_length(x) != 1)
throw ::Rcpp::not_compatible( "expecting a single value");
- }
return T( CHAR( STRING_ELT( ::Rcpp::r_cast<STRSXP>(x) ,0 ) ) ) ;
}
+ template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_wstring_tag ) {
+ if( ! ::Rf_isString(x) )
+ throw ::Rcpp::not_compatible( "expecting a string" ) ;
+ if (Rf_length(x) != 1)
+ throw ::Rcpp::not_compatible( "expecting a single value");
+ const char* y = CHAR( STRING_ELT( ::Rcpp::r_cast<STRSXP>(x) ,0 ) ) ;
+ // TODO: deal about encoding
+ return std::wstring( y, y+strlen(y)) ;
+ }
+
template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_RcppString_tag ) {
if( ! ::Rf_isString(x) ){
throw ::Rcpp::not_compatible( "expecting a string" ) ;
Modified: pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h 2013-02-02 16:17:21 UTC (rev 4231)
+++ pkg/Rcpp/inst/include/Rcpp/traits/r_type_traits.h 2013-02-02 16:44:13 UTC (rev 4232)
@@ -3,7 +3,8 @@
//
// r_type_traits.h: Rcpp R/C++ interface class library -- traits to help wrap
//
-// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2013 Rice University
//
// This file is part of Rcpp.
//
@@ -39,6 +40,12 @@
struct r_type_string_tag{} ;
/**
+ * Identifies that the associated type can be implicitely converted
+ * to a std::wstring
+ */
+struct r_type_wstring_tag{} ;
+
+/**
* Default
*/
struct r_type_generic_tag{} ;
@@ -110,11 +117,14 @@
template<> struct r_type_traits<Rcomplex>{ typedef r_type_primitive_tag r_category ; } ;
template<> struct r_type_traits<bool>{ typedef r_type_primitive_tag r_category ; } ;
template<> struct r_type_traits<std::string>{ typedef r_type_string_tag r_category ; } ;
+template<> struct r_type_traits<std::wstring>{ typedef r_type_wstring_tag r_category ; } ;
template<> struct r_type_traits<char>{ typedef r_type_string_tag r_category ; } ;
+template<> struct r_type_traits<wchar_t>{ typedef r_type_wstring_tag r_category ; } ;
template<> struct r_type_traits<unsigned int>{ typedef r_type_primitive_tag r_category ; } ;
template<> struct r_type_traits<float>{ typedef r_type_primitive_tag r_category ; } ;
template<> struct r_type_traits<const char*>{ typedef r_type_string_tag r_category ; } ;
+template<> struct r_type_traits<const wchar_t*>{ typedef r_type_wstring_tag r_category ; } ;
/* long */
template<> struct r_type_traits<long>{ typedef r_type_primitive_tag r_category ; } ;
More information about the Rcpp-commits
mailing list