[Rcpp-commits] r844 - in pkg/Rcpp: . src/Rcpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 7 12:45:01 CET 2010
Author: romain
Date: 2010-03-07 12:45:01 +0100 (Sun, 07 Mar 2010)
New Revision: 844
Modified:
pkg/Rcpp/DESCRIPTION
pkg/Rcpp/src/Rcpp/Vector.h
Log:
added string_proxy::transform
Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION 2010-03-07 11:22:24 UTC (rev 843)
+++ pkg/Rcpp/DESCRIPTION 2010-03-07 11:45:01 UTC (rev 844)
@@ -1,6 +1,6 @@
Package: Rcpp
Title: Rcpp R/C++ interface package
-Version: 0.7.7.13
+Version: 0.7.7.14
Date: $Date$
Author: Dirk Eddelbuettel and Romain Francois, with contributions
by Simon Urbanek and David Reiss; based on code written during
Modified: pkg/Rcpp/src/Rcpp/Vector.h
===================================================================
--- pkg/Rcpp/src/Rcpp/Vector.h 2010-03-07 11:22:24 UTC (rev 843)
+++ pkg/Rcpp/src/Rcpp/Vector.h 2010-03-07 11:45:01 UTC (rev 844)
@@ -1208,9 +1208,9 @@
* element this proxy refers to.
*/
string_proxy& operator+=(const string_proxy& rhs){
- std::string full( CHAR(STRING_ELT(*parent,index)) ) ;
- full += CHAR(STRING_ELT( *(rhs.parent), rhs.index)) ;
- SET_STRING_ELT( *parent, index, Rf_mkChar(full.c_str()) ) ;
+ buffer = CHAR(STRING_ELT(*parent,index)) ;
+ buffer += CHAR(STRING_ELT( *(rhs.parent), rhs.index)) ;
+ SET_STRING_ELT( *parent, index, Rf_mkChar(buffer.c_str()) ) ;
return *this ;
}
@@ -1218,9 +1218,9 @@
* lhs use. Adds the string to the element this proxy refers to
*/
string_proxy& operator+=(const std::string& rhs){
- std::string full( CHAR(STRING_ELT(*parent,index)) ) ;
- full += rhs ;
- SET_STRING_ELT( *parent, index, Rf_mkChar(full.c_str()) ) ;
+ buffer = CHAR(STRING_ELT(*parent,index)) ;
+ buffer += rhs ;
+ SET_STRING_ELT( *parent, index, Rf_mkChar(buffer.c_str()) ) ;
return *this ;
}
@@ -1268,12 +1268,25 @@
inline void set(SEXP x){
SET_STRING_ELT( *parent, index, x ) ;
}
+ inline void set( const std::string& x ){
+ set( ::Rf_mkChar(x.c_str()) ) ;
+ }
inline iterator begin(){ return CHAR( STRING_ELT( *parent, index ) ) ; }
inline iterator end(){ return begin() + size() ; }
inline int size(){ return strlen( begin() ) ; }
inline reference operator[]( int n ){ return *( begin() + n ) ; }
+ template <typename UnaryOperator>
+ void transform( UnaryOperator op ){
+ buffer = begin() ;
+ std::transform( buffer.begin(), buffer.end(), buffer.begin(), op ) ;
+ set( buffer ) ;
+ }
+
+ private:
+ static std::string buffer ;
+
} ;
inline std::ostream& operator<<(std::ostream& os, const string_proxy<STRSXP>& proxy) {
More information about the Rcpp-commits
mailing list