[Rcpp-commits] r4239 - in pkg/Rcpp: . inst/include/Rcpp inst/include/Rcpp/internal inst/include/Rcpp/vector

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Feb 4 16:54:58 CET 2013


Author: romain
Date: 2013-02-04 16:54:58 +0100 (Mon, 04 Feb 2013)
New Revision: 4239

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/String.h
   pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
   pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
Log:
more wstring support in String and CharacterVector

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-02-04 15:16:01 UTC (rev 4238)
+++ pkg/Rcpp/ChangeLog	2013-02-04 15:54:58 UTC (rev 4239)
@@ -10,6 +10,7 @@
         of wstring 
         * include/Rcpp/traits/char_type.h : new trait to help the wstring support
         * include/Rcpp/String.h : added some support for wstring 
+        * include/Rcpp/vector/string_proxy.h : adapt to add wstring support 
         
 2013-02-03 Romain Francois <romain at r-enthusiasts.com>
 

Modified: pkg/Rcpp/inst/include/Rcpp/String.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/String.h	2013-02-04 15:16:01 UTC (rev 4238)
+++ pkg/Rcpp/inst/include/Rcpp/String.h	2013-02-04 15:54:58 UTC (rev 4239)
@@ -384,7 +384,12 @@
             RCPP_DEBUG( "string_element_converter::get< Rcpp::String >()" )
 		     return input.get_sexp() ;   
 		}
-		
+        
+        template <>
+        inline SEXP make_charsexp<Rcpp::String>( const Rcpp::String& s){
+            return s.get_sexp() ;    
+        }
+        
 	}
     
 	template <>
@@ -397,6 +402,7 @@
     	return res ;
     }
 
+    
 } // Rcpp 
 
 #endif 

Modified: pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2013-02-04 15:16:01 UTC (rev 4238)
+++ pkg/Rcpp/inst/include/Rcpp/internal/wrap.h	2013-02-04 15:54:58 UTC (rev 4239)
@@ -71,6 +71,8 @@
 	inline SEXP make_charsexp( const T& s) {
 		return make_charsexp__impl<T>( s, typename Rcpp::traits::is_wide_string<T>::type() ) ;
 	}
+	template <>
+	inline SEXP make_charsexp<Rcpp::String>( const Rcpp::String& );
 	
 	template <typename InputIterator> SEXP range_wrap(InputIterator first, InputIterator last) ;
 	template <typename InputIterator> SEXP rowmajor_wrap(InputIterator first, int nrow, int ncol) ;

Modified: pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h	2013-02-04 15:16:01 UTC (rev 4238)
+++ pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h	2013-02-04 15:54:58 UTC (rev 4239)
@@ -2,7 +2,8 @@
 //
 // string_proxy.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 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.
 //
@@ -67,8 +68,9 @@
 		 *
 		 * @param rhs new content for the element referred by this proxy
 		 */
-		string_proxy& operator=(const std::string& rhs){
-			set( Rf_mkChar( rhs.c_str() ) ) ;
+		template <typename T>
+		string_proxy& operator=(const std::basic_string<T>& rhs){
+			set( rhs ) ;
 			return *this ;
 		}
 		
@@ -77,7 +79,12 @@
 			return *this ;	
 		}
 		
+		string_proxy& operator=(const wchar_t* rhs){
+			set( internal::make_charsexp( rhs ) ) ;
+			return *this ;	
+		}
 		
+		
 		string_proxy& operator=(SEXP rhs){
 			// TODO: check this is a CHARSXP
 			set( rhs ) ;
@@ -89,28 +96,19 @@
 			index  = other.index ;
 		}
 		
-		/**
-		 * lhs use. Adds the content of the rhs proxy to the 
-		 * element this proxy refers to.
-		 */
-		string_proxy& operator+=(const string_proxy& rhs){
-			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 ;
-		}
+        /**
+         * lhs use. Adds the content of the rhs proxy to the 
+         * element this proxy refers to.
+         */
+        template <typename T>
+        string_proxy& operator+=(const T& rhs){
+        	String tmp = get() ;
+        	tmp += rhs ;
+        	set( tmp ) ;
+        	return *this ;
+        }
 		
 		/**
-		 * lhs use. Adds the string to the element this proxy refers to
-		 */
-		string_proxy& operator+=(const std::string& rhs){
-			buffer = CHAR(STRING_ELT(*parent,index)) ;
-			buffer += rhs ;
-			SET_STRING_ELT( *parent, index, Rf_mkChar(buffer.c_str()) ) ;
-			return *this ;
-		} 	 
-		
-		/**
 		 * rhs use. Retrieves the current value of the 
 		 * element this proxy refers to.
 		 */
@@ -151,12 +149,13 @@
 		inline SEXP get() const {
 			return STRING_ELT( *parent, index ) ;
 		}
+		template <typename T>
+		inline void set( const T& x ){
+			set( internal::make_charsexp(x) ) ;
+		}
 		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() const { return CHAR( STRING_ELT( *parent, index ) ) ; }
 		inline iterator end() const { return begin() + size() ; }



More information about the Rcpp-commits mailing list