[Rcpp-commits] r482 - in pkg: inst inst/doc src src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 27 10:29:14 CET 2010


Author: romain
Date: 2010-01-27 10:29:14 +0100 (Wed, 27 Jan 2010)
New Revision: 482

Modified:
   pkg/inst/ChangeLog
   pkg/inst/doc/Makefile
   pkg/inst/doc/Rcpp-unitTests.Rnw
   pkg/src/Environment.cpp
   pkg/src/RObject.cpp
   pkg/src/Rcpp/Environment.h
   pkg/src/Rcpp/RObject.h
   pkg/src/Rcpp/as.h
Log:
various fixes

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-27 07:35:34 UTC (rev 481)
+++ pkg/inst/ChangeLog	2010-01-27 09:29:14 UTC (rev 482)
@@ -1,3 +1,17 @@
+2010-01-27  Romain Francois <francoisromain at free.fr>
+
+	* src/Rcpp/RObject.h: RObject::AttributeProxy::operator RObject
+	replaced by templated implicit conversion operator, delegating the
+	actual work to as<>.
+
+	* src/Environment.h: Binding::operator RObject is removed since
+	it can be automatically generated by the templated implicit
+	conversion operator
+
+	* man/RcpUnitTests.Rd: fix html rendering
+
+	* inst/doc/Makefile: clean the index.html file before copying it
+
 2010-01-26  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/RcppDatetime.cpp: New SEXP-based constructor

Modified: pkg/inst/doc/Makefile
===================================================================
--- pkg/inst/doc/Makefile	2010-01-27 07:35:34 UTC (rev 481)
+++ pkg/inst/doc/Makefile	2010-01-27 09:29:14 UTC (rev 482)
@@ -1,6 +1,9 @@
 
-all: index.html
+all: clean index.html
 
+clean:
+	rm index.html
+
 index.html: rcpp.index.html
 	cp rcpp.index.html index.html
 

Modified: pkg/inst/doc/Rcpp-unitTests.Rnw
===================================================================
--- pkg/inst/doc/Rcpp-unitTests.Rnw	2010-01-27 07:35:34 UTC (rev 481)
+++ pkg/inst/doc/Rcpp-unitTests.Rnw	2010-01-27 09:29:14 UTC (rev 482)
@@ -26,8 +26,8 @@
 printHTMLProtocol(tests, fileName= sprintf( "unitTests-results/%s-unitTests.html" , pkg ) )
 printTextProtocol(tests, fileName= sprintf( "unitTests-results/%s-unitTests.txt"  , pkg ) )
 if( file.exists( "/tmp" ) ){
-	file.copy( sprintf( "%s-unitTests.txt" , pkg ) , "/tmp", overwrite = TRUE )
-	file.copy( sprintf( "%s-unitTests.html", pkg ) , "/tmp", overwrite = TRUE )
+	file.copy( sprintf( "unitTests-results/%s-unitTests.txt" , pkg ) , "/tmp", overwrite = TRUE )
+	file.copy( sprintf( "unitTests-results/%s-unitTests.html", pkg ) , "/tmp", overwrite = TRUE )
 }
 @
 

Modified: pkg/src/Environment.cpp
===================================================================
--- pkg/src/Environment.cpp	2010-01-27 07:35:34 UTC (rev 481)
+++ pkg/src/Environment.cpp	2010-01-27 09:29:14 UTC (rev 482)
@@ -273,11 +273,7 @@
     Environment::Binding::operator SEXP() const{
     	return env.get( name );    
     }
-    
-    Environment::Binding::operator RObject() const{
-    	return wrap( env.get( name ) );
-    }
-    
+
     const Environment::Binding Environment::operator[]( const std::string& name) const{
     	return Binding( const_cast<Environment&>(*this), name );
     }

Modified: pkg/src/RObject.cpp
===================================================================
--- pkg/src/RObject.cpp	2010-01-27 07:35:34 UTC (rev 481)
+++ pkg/src/RObject.cpp	2010-01-27 09:29:14 UTC (rev 482)
@@ -114,10 +114,6 @@
 	return Rf_getAttrib( parent , Rf_install( attr_name.c_str() ) ) ;
 }
 
-RObject::AttributeProxy::operator RObject() const {
-	return wrap( Rf_getAttrib( parent, Rf_install( attr_name.c_str() ) ) ) ;
-}
-
 RObject::AttributeProxy RObject::attr( const std::string& name) const{
 	return AttributeProxy( *this, name)  ;
 }

Modified: pkg/src/Rcpp/Environment.h
===================================================================
--- pkg/src/Rcpp/Environment.h	2010-01-27 07:35:34 UTC (rev 481)
+++ pkg/src/Rcpp/Environment.h	2010-01-27 09:29:14 UTC (rev 482)
@@ -227,10 +227,12 @@
     	    operator SEXP() const ;
     	    
     	    /**
-    	     * retrieves the value for this binding as an RObject
+    	     * Retrieves the value of the binding as a T object
+    	     *
+    	     * The requirement on the T type is that as<T> makes sense
+    	     * which can either mean that a specialization exists
+    	     * or that T has a T(SEXP) constructor
     	     */
-    	    operator RObject() const ;
-    	    
     	    template <typename T> 
     	    operator T() const{
     	    	    SEXP x = env.get(name) ;

Modified: pkg/src/Rcpp/RObject.h
===================================================================
--- pkg/src/Rcpp/RObject.h	2010-01-27 07:35:34 UTC (rev 481)
+++ pkg/src/Rcpp/RObject.h	2010-01-27 09:29:14 UTC (rev 482)
@@ -23,6 +23,7 @@
 #define Rcpp_RObject_h
 
 #include <RcppCommon.h>
+#include <Rcpp/as.h>
 #include <set>
 
 namespace Rcpp{ 
@@ -126,19 +127,24 @@
     class AttributeProxy {
 	public:
 		AttributeProxy( const RObject& v, const std::string& attr_name) ;
-		
+
 		/* lvalue uses */
 		AttributeProxy& operator=(const AttributeProxy& rhs) ;
-		
+
 		template <typename T>
 		AttributeProxy& operator=(const T& rhs){
 			Rf_setAttrib( parent, Rf_install(attr_name.c_str()), wrap(rhs) ) ;
 			return *this ;
 		}
-		
+
 		/* rvalue use */
 		operator SEXP() const ;
-		operator RObject() const ;
+
+		template <typename T> operator T() const {
+			SEXP att = Rf_getAttrib( parent, Rf_install( attr_name.c_str() ) );
+			T t = Rcpp::as<T>(att) ;
+			return t ;
+		} ;
 		
 	private:
 		const RObject& parent; 

Modified: pkg/src/Rcpp/as.h
===================================================================
--- pkg/src/Rcpp/as.h	2010-01-27 07:35:34 UTC (rev 481)
+++ pkg/src/Rcpp/as.h	2010-01-27 09:29:14 UTC (rev 482)
@@ -23,7 +23,6 @@
 #define Rcpp_as_h
 
 #include <RcppCommon.h>
-#include <Rcpp/RObject.h>
 #include <algorithm>
 
 namespace Rcpp{ 



More information about the Rcpp-commits mailing list