[Rcpp-commits] r1131 - in pkg/Rcpp/inst: . include/Rcpp include/Rcpp/internal unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun May 2 12:18:01 CEST 2010


Author: romain
Date: 2010-05-02 12:18:01 +0200 (Sun, 02 May 2010)
New Revision: 1131

Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Vector.h
   pkg/Rcpp/inst/include/Rcpp/as.h
   pkg/Rcpp/inst/include/Rcpp/internal/export.h
   pkg/Rcpp/inst/unitTests/runTests.R
   pkg/Rcpp/inst/unitTests/runit.IntegerVector.R
Log:
add throw(not_compatible) to Rcpp::as

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-04-29 15:38:07 UTC (rev 1130)
+++ pkg/Rcpp/inst/ChangeLog	2010-05-02 10:18:01 UTC (rev 1131)
@@ -1,3 +1,7 @@
+2010-05-02	Romain Francois <romain at r-enthusiasts.com>
+
+	* inst/include/Rcpp/as.h: add throw(not_compatible) in Rcpp::as	
+
 2010-04-28	Romain Francois <romain at r-enthusiasts.com>
 
 	* inst/include/Rcpp/Vector.h: changed Vector( size_t ) to Vector( int )

Modified: pkg/Rcpp/inst/include/Rcpp/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Vector.h	2010-04-29 15:38:07 UTC (rev 1130)
+++ pkg/Rcpp/inst/include/Rcpp/Vector.h	2010-05-02 10:18:01 UTC (rev 1131)
@@ -769,7 +769,7 @@
 		cache.update(*this) ;
 	}
 		
-	Vector create(){
+	static Vector create(){
 		return Vector( 0 ) ;
 	}
 	

Modified: pkg/Rcpp/inst/include/Rcpp/as.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/as.h	2010-04-29 15:38:07 UTC (rev 1130)
+++ pkg/Rcpp/inst/include/Rcpp/as.h	2010-05-02 10:18:01 UTC (rev 1131)
@@ -26,8 +26,8 @@
 
 namespace internal{
 	
-	template <typename T> T as( SEXP x, ::Rcpp::traits::r_type_primitive_tag ){
-		if( ::Rf_length(x) != 1 ) throw std::range_error( "expecting a single value" ) ;
+	template <typename T> T as( SEXP x, ::Rcpp::traits::r_type_primitive_tag ) throw(::Rcpp::not_compatible) {
+		if( ::Rf_length(x) != 1 ) throw ::Rcpp::not_compatible( "expecting a single value" ) ;
 		const int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
 		SEXP y = PROTECT( r_cast<RTYPE>(x) );
 		typedef typename ::Rcpp::traits::storage_type<RTYPE>::type STORAGE;
@@ -36,17 +36,17 @@
 		return res ; 
 	}
 	
-	template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_string_tag ){
+	template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_string_tag ) throw(::Rcpp::not_compatible) {
 		if( ! ::Rf_isString(x) ){
-			throw std::range_error( "expecting a string" ) ;
+			throw ::Rcpp::not_compatible( "expecting a string" ) ;
 		}
 		if (Rf_length(x) != 1) {
-    			throw std::range_error( "expecting a single value");
+    			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_generic_tag ){
+	template <typename T> T as(SEXP x, ::Rcpp::traits::r_type_generic_tag ) throw(::Rcpp::not_compatible) {
 		RCPP_DEBUG( "as(SEXP = <%p>, r_type_generic_tag )", x ) ;
 		::Rcpp::traits::Exporter<T> exporter(x);
 		RCPP_DEBUG( "exporter type = %s", DEMANGLE(exporter) ) ;
@@ -71,7 +71,7 @@
  * Environment x = ... ; // some environment
  * Foo y = x["bla"] ;    // if as<Foo> makes sense then this works !!
  */
-template <typename T> T as( SEXP m_sexp) {
+template <typename T> T as( SEXP m_sexp) throw(not_compatible) {
 	return internal::as<T>( m_sexp, typename traits::r_type_traits<T>::r_category() ) ;
 }
 

Modified: pkg/Rcpp/inst/include/Rcpp/internal/export.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/export.h	2010-04-29 15:38:07 UTC (rev 1130)
+++ pkg/Rcpp/inst/include/Rcpp/internal/export.h	2010-05-02 10:18:01 UTC (rev 1131)
@@ -29,7 +29,7 @@
 	/* iterating */
 	
 	template <typename InputIterator, typename value_type>
-	void export_range__impl( SEXP x, InputIterator first, ::Rcpp::traits::false_type ){
+	void export_range__impl( SEXP x, InputIterator first, ::Rcpp::traits::false_type ) throw(::Rcpp::not_compatible){
 		const int RTYPE = ::Rcpp::traits::r_sexptype_traits<value_type>::rtype ;
 		typedef typename ::Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
 		SEXP y = PROTECT( ::Rcpp::r_cast<RTYPE>(x) ) ;
@@ -39,7 +39,7 @@
 	}
 	
 	template <typename InputIterator, typename value_type>
-	void export_range__impl( SEXP x, InputIterator first, ::Rcpp::traits::true_type ){
+	void export_range__impl( SEXP x, InputIterator first, ::Rcpp::traits::true_type ) throw(::Rcpp::not_compatible){
 		const int RTYPE = ::Rcpp::traits::r_sexptype_traits<value_type>::rtype ;
 		typedef typename ::Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
 		SEXP y = PROTECT( ::Rcpp::r_cast<RTYPE>(x) ) ;
@@ -49,7 +49,7 @@
 	}
 	
 	template <typename InputIterator, typename value_type>
-	void export_range__dispatch( SEXP x, InputIterator first, ::Rcpp::traits::r_type_primitive_tag ){
+	void export_range__dispatch( SEXP x, InputIterator first, ::Rcpp::traits::r_type_primitive_tag ) throw(::Rcpp::not_compatible){
 		export_range__impl<InputIterator,value_type>(
 			x, 
 			first,
@@ -57,8 +57,8 @@
 	}
 	
 	template <typename InputIterator, typename value_type>
-	void export_range__dispatch( SEXP x, InputIterator first, ::Rcpp::traits::r_type_string_tag ){
-		if( ! ::Rf_isString( x) ) throw std::range_error( "expecting a string vector" ) ;
+	void export_range__dispatch( SEXP x, InputIterator first, ::Rcpp::traits::r_type_string_tag ) throw(::Rcpp::not_compatible){
+		if( ! ::Rf_isString( x) ) throw ::Rcpp::not_compatible( "expecting a string vector" ) ;
 		std::string buf ;
 		R_len_t n = ::Rf_length(x) ;
 		for( R_len_t i=0; i<n; i++, ++first ){
@@ -67,7 +67,7 @@
 	}
 	
 	template <typename InputIterator>
-	void export_range( SEXP x, InputIterator first ){
+	void export_range( SEXP x, InputIterator first ) throw(::Rcpp::not_compatible){
 		export_range__dispatch<InputIterator,typename std::iterator_traits<InputIterator>::value_type>( 
 			x, 
 			first, 
@@ -79,7 +79,7 @@
 	/* indexing */
 	
 	template <typename T, typename value_type>
-	void export_indexing__impl( SEXP x, T& res, ::Rcpp::traits::false_type ){
+	void export_indexing__impl( SEXP x, T& res, ::Rcpp::traits::false_type ) throw(::Rcpp::not_compatible){
 		const int RTYPE = ::Rcpp::traits::r_sexptype_traits<value_type>::rtype ;
 		typedef typename ::Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
 		SEXP y = PROTECT( ::Rcpp::r_cast<RTYPE>(x) ) ;
@@ -92,7 +92,7 @@
 	}
 	
 	template <typename T, typename value_type>
-	void export_indexing__impl( SEXP x, T& res, ::Rcpp::traits::true_type ){
+	void export_indexing__impl( SEXP x, T& res, ::Rcpp::traits::true_type ) throw(::Rcpp::not_compatible){
 		const int RTYPE = ::Rcpp::traits::r_sexptype_traits<value_type>::rtype ;
 		typedef typename ::Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
 		SEXP y = PROTECT( ::Rcpp::r_cast<RTYPE>(x) ) ;
@@ -105,7 +105,7 @@
 	}
 
 	template <typename T, typename value_type>
-	void export_indexing__dispatch( SEXP x, T& res, ::Rcpp::traits::r_type_primitive_tag ){
+	void export_indexing__dispatch( SEXP x, T& res, ::Rcpp::traits::r_type_primitive_tag ) throw(::Rcpp::not_compatible){
 		export_indexing__impl<T,value_type>(
 			x, 
 			res,
@@ -113,8 +113,8 @@
 	}
 	
 	template <typename T, typename value_type>
-	void export_indexing__dispatch( SEXP x, T& res, ::Rcpp::traits::r_type_string_tag ){
-		if( ! ::Rf_isString( x) ) throw std::range_error( "expecting a string vector" ) ;
+	void export_indexing__dispatch( SEXP x, T& res, ::Rcpp::traits::r_type_string_tag ) throw(::Rcpp::not_compatible){
+		if( ! ::Rf_isString( x) ) throw Rcpp::not_compatible( "expecting a string vector" ) ;
 		std::string buf ;
 		R_len_t n = ::Rf_length(x) ;
 		for( R_len_t i=0; i<n; i++ ){
@@ -123,7 +123,7 @@
 	}
 	
 	template <typename T, typename value_type>
-	void export_indexing( SEXP x, T& res ){
+	void export_indexing( SEXP x, T& res ) throw(::Rcpp::not_compatible) {
 		export_indexing__dispatch<T,value_type>( 
 			x, 
 			res, 

Modified: pkg/Rcpp/inst/unitTests/runTests.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runTests.R	2010-04-29 15:38:07 UTC (rev 1130)
+++ pkg/Rcpp/inst/unitTests/runTests.R	2010-05-02 10:18:01 UTC (rev 1131)
@@ -82,7 +82,7 @@
             stop( sprintf( "unit test problems: %d failures, %d errors", err$nFail, err$nErr) )
         } else{
         	success <- err$nTestFunc - err$nFail - err$nErr - err$nDeactivated
-        	cat( sprintf( "%d / %d", success, err$nTestFunc ) )
+        	cat( sprintf( "%d / %d\n", success, err$nTestFunc ) )
         }
     }
 } else {

Modified: pkg/Rcpp/inst/unitTests/runit.IntegerVector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.IntegerVector.R	2010-04-29 15:38:07 UTC (rev 1130)
+++ pkg/Rcpp/inst/unitTests/runit.IntegerVector.R	2010-05-02 10:18:01 UTC (rev 1131)
@@ -247,12 +247,12 @@
 }
 
 test.IntegerVector.zero <- function( ){
-	funx <- cppfunction(signature(x = "integer"), 'return IntegerVector(0);' )
+	funx <- cppfunction(signature(), 'return IntegerVector(0);' )
 	checkEquals( funx(), integer(0), msg = "IntegerVector(0)" )
 }
 
 test.IntegerVector.create.zero <- function( ){
-	funx <- cppfunction(signature(x = "integer"), 'return IntegerVector::create();' )
+	funx <- cppfunction(signature(), 'return IntegerVector::create();' )
 	checkEquals( funx(), integer(0), msg = "IntegerVector::create()" )
 }
 



More information about the Rcpp-commits mailing list