[Rcpp-commits] r745 - in pkg/Rcpp: . inst src src/Rcpp src/Rcpp/internal src/Rcpp/traits

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 19 16:30:54 CET 2010


Author: romain
Date: 2010-02-19 16:30:54 +0100 (Fri, 19 Feb 2010)
New Revision: 745

Added:
   pkg/Rcpp/src/Rcpp/internal/caster.h
   pkg/Rcpp/src/Rcpp/internal/export.h
   pkg/Rcpp/src/Rcpp/traits/Exporter.h
Modified:
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/src/Rcpp.h
   pkg/Rcpp/src/Rcpp/VectorBase.h
   pkg/Rcpp/src/Rcpp/as.h
   pkg/Rcpp/src/Rcpp/internal/wrap.h
   pkg/Rcpp/src/Rcpp/r_cast.h
   pkg/Rcpp/src/Rcpp/traits/has_iterator.h
   pkg/Rcpp/src/Rcpp/traits/wrap_type_traits.h
   pkg/Rcpp/src/RcppCommon.cpp
   pkg/Rcpp/src/RcppCommon.h
   pkg/Rcpp/src/as.cpp
   pkg/Rcpp/src/r_cast.cpp
Log:
monster commit of the day, reorganizing some things, to facilitate a more flexible Rcpp::as<>

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/DESCRIPTION	2010-02-19 15:30:54 UTC (rev 745)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Rcpp R/C++ interface package
-Version: 0.7.7.7
+Version: 0.7.7.8
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, with contributions 
  by Simon Urbanek and David Reiss; based on code written during 

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/inst/ChangeLog	2010-02-19 15:30:54 UTC (rev 745)
@@ -1,5 +1,8 @@
 2010-02-19  Romain Francois <romain at r-enthusiasts.com>
 
+	* src/Rcpp/internal/wrap.h: support for std::complex<double>
+	and std::complex<float> (needed for RcppArmadillo)
+
 	* src/Rcpp/traits/wrap_type_traits.h : The Importer concept 
 	has been introduced to support wrap() of more types. If a 
 	class has a typedef "r_import_type" then the following interface

Modified: pkg/Rcpp/src/Rcpp/VectorBase.h
===================================================================
--- pkg/Rcpp/src/Rcpp/VectorBase.h	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/Rcpp/VectorBase.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -23,7 +23,7 @@
 #define Rcpp_VectorBase_h
 
 #include <RcppCommon.h>
-
+#include <Rcpp/RObject.h>
 #include <Rcpp/r_cast.h>
 
 namespace Rcpp{ 

Modified: pkg/Rcpp/src/Rcpp/as.h
===================================================================
--- pkg/Rcpp/src/Rcpp/as.h	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/Rcpp/as.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -40,8 +40,8 @@
  * Foo y = x["bla"] ;    // if as<Foo> makes sense then this works !!
  */
 template <typename T> T as( SEXP m_sexp) {
-	T t(m_sexp);
-	return t ;
+	traits::Exporter<T> exporter(m_sexp);
+	return exporter.get() ;
 }
 
 template<> SEXP as(SEXP m_sexp) ;
@@ -89,42 +89,12 @@
 template<> std::string              	as<std::string>(SEXP m_sexp) ;
 
 /**
- * Converts the R object to a std::vector<int>
- *
- * The R object must be a logical, integer, raw or numeric vector
- */
-template<> std::vector<int>         	as< std::vector<int> >(SEXP m_sexp) ;
-
-/**
- * Converts the R object to a std::vector<double>
- *
- * The R object must be a logical, integer, raw ornumeric vector
- */
-template<> std::vector<double>      	as< std::vector<double> >(SEXP m_sexp) ;
-
-/**
  * Converts the R object to a std::vector<std::string>
  *
  * The R object must be a character vector
  */
 template<> std::vector<std::string> 	as< std::vector<std::string> >(SEXP m_sexp) ;
 
-/**
- * Converts the R object to a std::vector<Rbyte>
- *
- * The R object must be a logical, integer, raw or numeric vector
- */
-template<> std::vector<Rbyte>       	as< std::vector<Rbyte> >(SEXP m_sexp) ;
-
-/**
- * Converts the R object to a std::vector<Rbyte>
- *
- * The R object must be a logical, integer, raw or numeric vector
- *
- * since bool can not handle missing values, they are converted to false
- */
-template<> std::vector<bool>        	as< std::vector<bool> >(SEXP m_sexp) ;
-
 } // Rcpp 
 
 #endif

Added: pkg/Rcpp/src/Rcpp/internal/caster.h
===================================================================
--- pkg/Rcpp/src/Rcpp/internal/caster.h	                        (rev 0)
+++ pkg/Rcpp/src/Rcpp/internal/caster.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -0,0 +1,43 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// caster.h: Rcpp R/C++ interface class library -- 
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__internal__caster__h
+#define Rcpp__internal__caster__h
+
+namespace Rcpp{
+namespace internal{
+
+template <typename FROM, typename TO> TO caster(FROM from){
+	return static_cast<TO>(from) ;
+}
+template<> Rcomplex caster<std::complex<double>, Rcomplex>( std::complex<double> from) ;
+template<> Rcomplex caster<std::complex<float>, Rcomplex>( std::complex<float> from) ;
+
+template<> std::complex<double> caster<Rcomplex,std::complex<double> >( Rcomplex from) ;
+template<> std::complex<float>  caster<Rcomplex,std::complex<float>  >( Rcomplex from) ;
+
+
+}
+}
+
+#endif
+

Added: pkg/Rcpp/src/Rcpp/internal/export.h
===================================================================
--- pkg/Rcpp/src/Rcpp/internal/export.h	                        (rev 0)
+++ pkg/Rcpp/src/Rcpp/internal/export.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -0,0 +1,97 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// export.h: Rcpp R/C++ interface class library -- 
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__internal__export__h
+#define Rcpp__internal__export__h
+
+namespace Rcpp{
+namespace internal{
+
+	
+	template <typename InputIterator, typename value_type>
+	void export_range__impl( SEXP x, InputIterator first, ::Rcpp::traits::false_type ){
+		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) ) ;
+		STORAGE* start = ::Rcpp::internal::r_vector_start<RTYPE,STORAGE>(y) ;
+		std::copy( start, start + ::Rf_length(y), first ) ;
+		UNPROTECT(1) ;
+	}
+	
+	template <typename InputIterator, typename value_type>
+	void export_range__impl( SEXP x, InputIterator first, ::Rcpp::traits::true_type ){
+		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) ) ;
+		STORAGE* start = ::Rcpp::internal::r_vector_start<RTYPE,STORAGE>(y) ;
+		std::transform( start, start + ::Rf_length(y) , first, caster<STORAGE,value_type> ) ;
+		UNPROTECT(1) ;
+	}
+	
+	
+	template <typename T, typename value_type>
+	void export_indexing__impl( SEXP x, T& res, ::Rcpp::traits::false_type ){
+		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) ) ;
+		STORAGE* start = ::Rcpp::internal::r_vector_start<RTYPE,STORAGE>(y) ;
+		R_len_t size = ::Rf_length(y)  ;
+		for( R_len_t i=0; i<size; i++){
+			res.set( i, start[i] ) ;
+		}
+		UNPROTECT(1) ;
+	}
+	
+	template <typename T, typename value_type>
+	void export_indexing__impl( SEXP x, T& res, ::Rcpp::traits::true_type ){
+		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) ) ;
+		STORAGE* start = ::Rcpp::internal::r_vector_start<RTYPE,STORAGE>(y) ;
+		R_len_t size = ::Rf_length(y)  ;
+		for( R_len_t i=0; i<size; i++){
+			res.set( i, caster<STORAGE,value_type>(start[i]) ) ;
+		}
+		UNPROTECT(1) ;
+	}
+
+	
+	template <typename InputIterator>
+	void export_range( SEXP x, InputIterator first){
+		export_range__impl<InputIterator,typename std::iterator_traits<InputIterator>::value_type>(
+			x, 
+			first,
+			typename ::Rcpp::traits::r_sexptype_needscast< typename std::iterator_traits<InputIterator>::value_type >() );
+	}
+	
+	template <typename T>
+	void export_indexing( SEXP x, T& res ){
+		export_indexing__impl<T,typename T::value_type>( 
+			x, 
+			res, 
+			typename ::Rcpp::traits::r_sexptype_needscast< typename T::r_export_type >() ) ;
+	}
+	
+}
+}
+
+#endif

Modified: pkg/Rcpp/src/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/src/Rcpp/internal/wrap.h	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/Rcpp/internal/wrap.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -42,10 +42,6 @@
 // {{{ range wrap 
 // {{{ unnamed range wrap
 
-template <typename FROM, typename TO> TO caster(FROM from){
-	return static_cast<TO>(from) ;
-}
-
 /**
  * Range based primitive wrap implementation. used when 
  * - T is a primitive type, indicated by the r_type_traits
@@ -538,9 +534,6 @@
  * class to dispatch to the appropriate internal implementation 
  * method
  * 
- * If your type has a begin and end method returning stl-like iterator
- * you should specialize the wrap_type_traits template so that it 
- * defines wrap_category to be ::Rcpp::traits::wrap_type_stl_container_tag
  */
 template <typename T> SEXP wrap(const T& object){
 	return internal::wrap_dispatch( object, typename ::Rcpp::traits::wrap_type_traits<T>::wrap_category() ) ;

Modified: pkg/Rcpp/src/Rcpp/r_cast.h
===================================================================
--- pkg/Rcpp/src/Rcpp/r_cast.h	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/Rcpp/r_cast.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -22,9 +22,6 @@
 #ifndef Rcpp_rcast_h
 #define Rcpp_rcast_h
 
-#include <RcppCommon.h>
-#include <Rcpp/RObject.h>
-
 namespace Rcpp{
 namespace internal {
 	
@@ -32,7 +29,7 @@
 //   is different from the SEXP type of x */
 template <int TARGET>
 SEXP r_true_cast( SEXP x){
-	throw RObject::not_compatible( "not compatible" ) ;
+	throw std::exception( "not compatible" ) ;
 }
 
 template<> SEXP r_true_cast<INTSXP>(SEXP x);

Added: pkg/Rcpp/src/Rcpp/traits/Exporter.h
===================================================================
--- pkg/Rcpp/src/Rcpp/traits/Exporter.h	                        (rev 0)
+++ pkg/Rcpp/src/Rcpp/traits/Exporter.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -0,0 +1,67 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// exporter.h: Rcpp R/C++ interface class library -- identify if a class has a nested iterator typedef
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+   
+#ifndef Rcpp__traits__exporter__h
+#define Rcpp__traits__exporter__h
+
+namespace Rcpp{
+namespace traits{
+
+template <typename T> class Exporter{
+public:
+	Exporter( SEXP x ) : T(x){}
+	inline T get(){ return t ; }
+
+private:
+	T t ;
+} ;
+
+template <typename T> class StdVectorExporter {
+public:
+	typedef typename T::value_type r_export_type ;
+	
+	StdVectorExporter( SEXP x ) : object(x){
+		// R_PreserveObject(object) ;
+	}
+	~StdVectorExporter(){
+		// R_ReleaseObject(object) ;
+	}
+	
+	T get(){ 
+		T vec( ::Rf_length(object) );
+		::Rcpp::internal::export_range( object, vec.begin() ) ;
+		return vec ;
+	}
+	
+private:
+	SEXP object ;
+} ;
+
+template <typename T> class Exporter< std::vector<T> > : public StdVectorExporter< std::vector<T> > {
+	public:
+		Exporter(SEXP x) : StdVectorExporter< std::vector<T> >(x){}
+}; 
+
+
+} // namespace traits
+} // namespace Rcpp
+#endif

Modified: pkg/Rcpp/src/Rcpp/traits/has_iterator.h
===================================================================
--- pkg/Rcpp/src/Rcpp/traits/has_iterator.h	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/Rcpp/traits/has_iterator.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -64,6 +64,20 @@
       static const bool value = sizeof(__test<T>(0)) == 1;
     };
   
+  template<typename T>
+  class _is_exporter_helper : __sfinae_types {
+      template<typename U> struct _Wrap_type { };
+
+      template<typename U>
+        static __one __test(_Wrap_type<typename U::r_export_type>*);
+
+      template<typename U>
+        static __two __test(...);
+
+    public:
+      static const bool value = sizeof(__test<T>(0)) == 1;
+    };
+
   /** 
    * uses the SFINAE idiom to check if a class has an 
    * nested iterator typedef. For example : 
@@ -75,8 +89,7 @@
   	integral_constant<bool,_has_iterator_helper<T>::value> { };
 
   /**
-   * uses SFINAE to identify if a type is importable, i.e. if it conforms
-   * to the Rcpp::traits::Importer interface.
+   * uses SFINAE to identify if a type is importable
    *
    * The test is based on the presence of a typedef r_import_type in the 
    * class
@@ -84,7 +97,9 @@
   template<typename T> struct is_importer : 
     integral_constant<bool,_is_importer_helper<T>::value> { };
 	
-  	
+  template<typename T> struct is_exporter : 
+    integral_constant<bool,_is_exporter_helper<T>::value> { };
+
 } // traits
 } // Rcpp
 

Modified: pkg/Rcpp/src/Rcpp/traits/wrap_type_traits.h
===================================================================
--- pkg/Rcpp/src/Rcpp/traits/wrap_type_traits.h	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/Rcpp/traits/wrap_type_traits.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -58,8 +58,12 @@
 template <> struct wrap_type_traits<bool> { typedef wrap_type_primitive_tag wrap_category; } ;
 template <> struct wrap_type_traits<std::string> { typedef wrap_type_primitive_tag wrap_category; } ;
 template <> struct wrap_type_traits<char> { typedef wrap_type_primitive_tag wrap_category; } ;
+
 template <> struct wrap_type_traits<float> { typedef wrap_type_primitive_tag wrap_category; } ;
+template <> struct wrap_type_traits< std::complex<float> > { typedef wrap_type_primitive_tag wrap_category; } ;
+template <> struct wrap_type_traits< std::complex<double> > { typedef wrap_type_primitive_tag wrap_category; } ;
 
+
 } // namespace traits
 } // namespace Rcpp
 #endif

Modified: pkg/Rcpp/src/Rcpp.h
===================================================================
--- pkg/Rcpp/src/Rcpp.h	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/Rcpp.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -50,7 +50,6 @@
 #include <Rcpp/RObject.h>
 
 #include <Rcpp/clone.h>
-#include <Rcpp/r_cast.h>
 #include <Rcpp/grow.h>
 #include <Rcpp/Dimension.h>
 #include <Rcpp/VectorBase.h>

Modified: pkg/Rcpp/src/RcppCommon.cpp
===================================================================
--- pkg/Rcpp/src/RcppCommon.cpp	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/RcppCommon.cpp	2010-02-19 15:30:54 UTC (rev 745)
@@ -127,6 +127,7 @@
    
 namespace Rcpp{
 namespace internal{
+
 	template<> int* r_vector_start<INTSXP,int>(SEXP x){ return INTEGER(x) ; } ; 
 	template<> int* r_vector_start<LGLSXP,int>(SEXP x){ return LOGICAL(x) ; };
 	template<> double* r_vector_start<REALSXP,double>(SEXP x){ return REAL(x) ; } ;
@@ -144,6 +145,27 @@
 		return x ;
 	}
 
+	template<> Rcomplex caster<std::complex<double>, Rcomplex>( std::complex<double> from){
+		Rcomplex cx ;
+		cx.r = from.real() ; 
+		cx.i = from.imag() ;
+		return cx ;
+	}
+	template<> Rcomplex caster<std::complex<float>, Rcomplex>( std::complex<float> from){
+		Rcomplex cx ;
+		cx.r = static_cast<double>( from.real() ); 
+		cx.i = static_cast<double>( from.imag() );
+		return cx ;
+	}
+
+	template<> std::complex<double> caster<Rcomplex,std::complex<double> >( Rcomplex from){
+		return std::complex<double>(from.r, from.i ) ;
+	}
+	template<> std::complex<float> caster<Rcomplex,std::complex<float> >( Rcomplex from){
+		return std::complex<float>(static_cast<float>(from.r), static_cast<float>(from.i) ) ;
+	}
+
+	
 } // internal
 } // Rcpp
 

Modified: pkg/Rcpp/src/RcppCommon.h
===================================================================
--- pkg/Rcpp/src/RcppCommon.h	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/RcppCommon.h	2010-02-19 15:30:54 UTC (rev 745)
@@ -74,6 +74,7 @@
 #include <functional>
 #include <numeric>
 #include <algorithm>
+#include <complex>
 
 #ifdef HAS_INIT_LISTS
 #include <initializer_list>
@@ -167,11 +168,16 @@
 #include <Rcpp/traits/r_type_traits.h>
 #include <Rcpp/traits/wrap_type_traits.h>
 
+#include <Rcpp/internal/caster.h>
+#include <Rcpp/internal/r_vector.h>
+#include <Rcpp/internal/convertible.h>
+#include <Rcpp/r_cast.h>
+
+#include <Rcpp/internal/export.h>
+#include <Rcpp/traits/Exporter.h>
 #include <Rcpp/internal/r_coerce.h>
 #include <Rcpp/as.h>
 
-#include <Rcpp/internal/r_vector.h>
-#include <Rcpp/internal/convertible.h>
 #include <Rcpp/internal/wrap.h>
 
 RcppExport SEXP RcppXPtrExample_create_external_pointer() ;

Modified: pkg/Rcpp/src/as.cpp
===================================================================
--- pkg/Rcpp/src/as.cpp	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/as.cpp	2010-02-19 15:30:54 UTC (rev 745)
@@ -113,96 +113,6 @@
     return std::string(CHAR(STRING_ELT(m_sexp,0)));
 }
 
-template<> std::vector<bool> as< std::vector<bool> >(SEXP m_sexp) {
-    R_len_t n = Rf_length(m_sexp);
-    std::vector<bool> v(n);
-    switch( TYPEOF(m_sexp) ){
-    case LGLSXP:
-    	std::transform( LOGICAL(m_sexp), LOGICAL(m_sexp)+n, v.begin(), Rboolean_to_bool ) ;
-    	break ;
-    case INTSXP:
-    	std::transform( INTEGER(m_sexp), INTEGER(m_sexp)+n, v.begin(), int_to_bool ) ;
-    	break;
-    case REALSXP:
-    	std::transform( REAL(m_sexp), REAL(m_sexp)+n, v.begin(), double_to_bool ) ;
-    	break;
-    case RAWSXP:
-    	std::transform( RAW(m_sexp), RAW(m_sexp)+n, v.begin(), Rbyte_to_bool ) ;
-    	break;
-    default:
-    		throw std::range_error( "as< vector<bool> >: invalid R type" ) ; 
-    }
-    return v;
-}
-
-
-template<> std::vector<int> as< std::vector<int> >(SEXP m_sexp){
-    R_len_t n = Rf_length(m_sexp);
-    std::vector<int> v(n);
-    switch( TYPEOF(m_sexp) ){
-    case INTSXP:
-    	v.assign( INTEGER(m_sexp), INTEGER(m_sexp)+n ) ;
-    	break;
-    case LGLSXP:
-    	std::transform( LOGICAL(m_sexp), LOGICAL(m_sexp)+n, v.begin(), internal::r_coerce<LGLSXP,INTSXP> ) ;
-    	break;
-    case REALSXP:
-    	std::transform( REAL(m_sexp), REAL(m_sexp)+n, v.begin(), internal::r_coerce<REALSXP,INTSXP> ) ;
-    	break;
-    case RAWSXP:
-    	std::transform( RAW(m_sexp), RAW(m_sexp)+n, v.begin(), internal::r_coerce<RAWSXP,INTSXP> ) ;
-    	break;
-    default:
-    		throw std::range_error( "as< vector<int> >: invalid R type" ) ; 
-    }
-    return v;
-}
-
-template<> std::vector<Rbyte> as< std::vector<Rbyte> >(SEXP m_sexp) {
-    R_len_t n = Rf_length(m_sexp);
-    std::vector<Rbyte> v(n);
-    switch( TYPEOF(m_sexp) ){
-    case LGLSXP:
-    	std::transform( LOGICAL(m_sexp), LOGICAL(m_sexp)+n, v.begin(), internal::r_coerce<LGLSXP,RAWSXP> ) ;
-    	break ;
-    case RAWSXP:
-    	v.assign( RAW(m_sexp), RAW(m_sexp)+n ) ;
-    	break ;
-    case REALSXP:
-    	std::transform( REAL(m_sexp), REAL(m_sexp)+n, v.begin(), internal::r_coerce<REALSXP,RAWSXP> ) ;
-    	break;
-    case INTSXP:
-    	std::transform( INTEGER(m_sexp), INTEGER(m_sexp)+n, v.begin(), internal::r_coerce<INTSXP,RAWSXP> ) ;
-    	break;
-    default:
-    	throw std::range_error("as< vector<Rbyte> > expects raw, double or int");
-    }
-    return v;
-}
-
-template<> std::vector<double> as< std::vector<double> >(SEXP m_sexp){
-    R_len_t n = Rf_length(m_sexp);
-    std::vector<double> v(n);
-    switch( TYPEOF(m_sexp) ){
-    case LGLSXP:
-    	std::transform( LOGICAL(m_sexp), LOGICAL(m_sexp)+n, v.begin(), internal::r_coerce<LGLSXP,REALSXP> ) ;
-    	break ;
-    case RAWSXP:
-    	std::transform( RAW(m_sexp), RAW(m_sexp)+n, v.begin(), internal::r_coerce<RAWSXP,REALSXP> ) ;
-    	break ;
-    case REALSXP:
-    	v.assign( REAL(m_sexp), REAL(m_sexp)+n) ;
-    	break;
-    case INTSXP:
-    	std::transform( INTEGER(m_sexp), INTEGER(m_sexp)+n, v.begin(), internal::r_coerce<INTSXP,REALSXP>) ;
-    	break;
-    default:
-    	    throw std::range_error("as< vector<double> >:  expects raw, double or int");
-    }
-    return v;
-}
-
-
 template<> std::vector<std::string> as< std::vector<std::string> >(SEXP m_sexp){
     R_len_t n = Rf_length(m_sexp);
     std::vector<std::string> v(n);

Modified: pkg/Rcpp/src/r_cast.cpp
===================================================================
--- pkg/Rcpp/src/r_cast.cpp	2010-02-19 13:26:03 UTC (rev 744)
+++ pkg/Rcpp/src/r_cast.cpp	2010-02-19 15:30:54 UTC (rev 745)
@@ -19,7 +19,8 @@
 // You should have received a copy of the GNU General Public License
 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <Rcpp/r_cast.h>
+#include <RcppCommon.h>
+#include <Rcpp/RObject.h>
 
 namespace Rcpp{
 namespace internal{



More information about the Rcpp-commits mailing list