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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Feb 1 21:58:43 CET 2010


Author: romain
Date: 2010-02-01 21:58:43 +0100 (Mon, 01 Feb 2010)
New Revision: 550

Added:
   pkg/src/Rcpp/traits/storage_type.h
Modified:
   pkg/src/Rcpp/internal/wrap.h
   pkg/src/RcppCommon.h
Log:
move the storage_type template to the traits namespace

Modified: pkg/src/Rcpp/internal/wrap.h
===================================================================
--- pkg/src/Rcpp/internal/wrap.h	2010-02-01 20:52:05 UTC (rev 549)
+++ pkg/src/Rcpp/internal/wrap.h	2010-02-01 20:58:43 UTC (rev 550)
@@ -39,13 +39,6 @@
 // {{{ information about R vectors
 // welcome to template metaprogramming !!
 
-template<int RTYPE> struct storage_type{ typedef SEXP type ; } ;
-template<> struct storage_type<INTSXP>{  typedef int type ; } ;
-template<> struct storage_type<REALSXP>{ typedef double type ; } ;
-template<> struct storage_type<CPLXSXP>{ typedef Rcomplex type ; } ;
-template<> struct storage_type<RAWSXP>{ typedef Rbyte type ; } ;
-template<> struct storage_type<LGLSXP>{ typedef int type ; } ;
-
 template<int RTYPE, typename CTYPE> CTYPE* r_vector_start(SEXP x){ return static_cast<CTYPE*>(0) ; } ;
 template<> int* r_vector_start<INTSXP,int>(SEXP x) ; 
 template<> int* r_vector_start<LGLSXP,int>(SEXP x) ;
@@ -58,7 +51,7 @@
 
 // initializes a vector. The template does nothing because there is
 template<int RTYPE> void r_init_vector(SEXP x){
-	typedef storage_type<RTYPE> CTYPE ;
+	typedef ::Rcpp::traits::storage_type<RTYPE> CTYPE ;
 	CTYPE* start=r_vector_start<RTYPE>(x) ;
 	std::fill( start, start + Rf_length(x), get_zero<RTYPE,CTYPE>(0) ) ;
 }
@@ -84,7 +77,7 @@
 	size_t size = std::distance( first, last ) ;
 	const int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
 	SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
-	std::copy( first, last, r_vector_start<RTYPE, typename storage_type<RTYPE>::type >(x) ) ; 
+	std::copy( first, last, r_vector_start<RTYPE, typename ::Rcpp::traits::storage_type<RTYPE>::type >(x) ) ; 
 	UNPROTECT(1) ;
 	return x ;
 } ;
@@ -169,7 +162,8 @@
 	const int RTYPE = ::Rcpp::traits::r_sexptype_traits<typename T::second_type>::rtype ;
 	SEXP x = PROTECT( Rf_allocVector( RTYPE, size ) );
 	SEXP names = PROTECT( Rf_allocVector( STRSXP, size ) ) ;
-	typename storage_type<RTYPE>::type* start = r_vector_start<RTYPE, typename storage_type<RTYPE>::type >(x) ;
+	typedef typename ::Rcpp::traits::storage_type<RTYPE>::type CTYPE ;
+	CTYPE* start = r_vector_start<RTYPE,CTYPE>(x) ;
 	size_t i =0;
 	std::string buf ; 
 	for( ; i<size; i++, ++first){
@@ -294,7 +288,7 @@
 SEXP primitive_wrap__impl( const T& object, ::Rcpp::traits::r_type_primitive_tag ){
 	const int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
 	SEXP x = PROTECT( Rf_allocVector( RTYPE, 1 ) );
-	r_vector_start<RTYPE, typename storage_type<RTYPE>::type >(x)[0] = object ;
+	r_vector_start<RTYPE, typename ::Rcpp::traits::storage_type<RTYPE>::type >(x)[0] = object ;
 	UNPROTECT(1);
 	return x;
 }

Added: pkg/src/Rcpp/traits/storage_type.h
===================================================================
--- pkg/src/Rcpp/traits/storage_type.h	                        (rev 0)
+++ pkg/src/Rcpp/traits/storage_type.h	2010-02-01 20:58:43 UTC (rev 550)
@@ -0,0 +1,45 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// r_sexptype_traits.h: Rcpp R/C++ interface class library -- traits to help wrap
+//
+// 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__storage_type__h
+#define Rcpp__traits__storage_type__h
+
+namespace Rcpp{
+namespace traits{
+
+/**
+ * Indicates the storage type associated with a SEXP type
+ * for example: 
+ * storage_type<INTSXP>::type is a typedef to int
+ */
+template<int RTYPE> struct storage_type{ typedef SEXP type ; } ;
+
+template<> struct storage_type<INTSXP>{  typedef int type ; } ;
+template<> struct storage_type<REALSXP>{ typedef double type ; } ;
+template<> struct storage_type<CPLXSXP>{ typedef Rcomplex type ; } ;
+template<> struct storage_type<RAWSXP>{ typedef Rbyte type ; } ;
+template<> struct storage_type<LGLSXP>{ typedef int type ; } ;
+
+} // traits
+} // Rcpp
+
+#endif

Modified: pkg/src/RcppCommon.h
===================================================================
--- pkg/src/RcppCommon.h	2010-02-01 20:52:05 UTC (rev 549)
+++ pkg/src/RcppCommon.h	2010-02-01 20:58:43 UTC (rev 550)
@@ -226,6 +226,7 @@
 
 // DO NOT CHANGE THE ORDER OF THESE INCLUDES
 #include <Rcpp/traits/r_sexptype_traits.h>
+#include <Rcpp/traits/storage_type.h>
 #include <Rcpp/traits/r_type_traits.h>
 #include <Rcpp/traits/wrap_type_traits.h>
 



More information about the Rcpp-commits mailing list