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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 2 08:29:38 CET 2010


Author: romain
Date: 2010-02-02 08:29:37 +0100 (Tue, 02 Feb 2010)
New Revision: 553

Added:
   pkg/src/Rcpp/internal/r_vector.h
Modified:
   pkg/src/Rcpp/internal/wrap.h
   pkg/src/Rcpp/traits/storage_type.h
   pkg/src/RcppCommon.h
Log:
some more documentation

Added: pkg/src/Rcpp/internal/r_vector.h
===================================================================
--- pkg/src/Rcpp/internal/r_vector.h	                        (rev 0)
+++ pkg/src/Rcpp/internal/r_vector.h	2010-02-02 07:29:37 UTC (rev 553)
@@ -0,0 +1,77 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// r_vector.h: Rcpp R/C++ interface class library -- information about R vectors
+//
+// 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_wrap_h
+#define Rcpp_internal_wrap_h
+
+namespace Rcpp{
+namespace internal{
+
+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) ;
+template<> double* r_vector_start<REALSXP,double>(SEXP x) ;
+template<> Rbyte* r_vector_start<RAWSXP,Rbyte>(SEXP x) ; 
+template<> Rcomplex* r_vector_start<CPLXSXP,Rcomplex>(SEXP x) ;                         
+
+/**
+ * The value 0 statically casted to the appropriate type for 
+ * the given SEXP type
+ */
+template <int RTYPE,typename CTYPE> CTYPE get_zero(){ return static_cast<CTYPE>(0) ; } ;
+/**
+ * Specialization for Rcomplex
+ */
+template<> Rcomplex get_zero<CPLXSXP,Rcomplex>() ;
+
+/**
+ * Initializes a vector of the given SEXP type. The template fills the 
+ * vector with the value 0 of the appropriate type, for example
+ * an INTSXP vector is initialized with (int)0, etc...
+ */
+template<int RTYPE> void r_init_vector(SEXP x){
+	typedef ::Rcpp::traits::storage_type<RTYPE>::type CTYPE ;
+	CTYPE* start=r_vector_start<RTYPE>(x) ;
+	std::fill( start, start + Rf_length(x), get_zero<RTYPE,CTYPE>(0) ) ;
+}
+/**
+ * Initializes a generic vector (VECSXP). Does nothing since 
+ * R already initializes all elements to NULL
+ */
+template<> void r_init_vector<VECSXP>(SEXP x) ;
+
+/**
+ * Initializes an expression vector (EXPRSXP). Does nothing since 
+ * R already initializes all elements to NULL
+ */
+template<> void r_init_vector<EXPRSXP>(SEXP x) ;
+
+/**
+ * Initializes a character vector (STRSXP). Does nothing since 
+ * R already initializes all elements to ""
+ */ 
+template<> void r_init_vector<STRSXP>(SEXP x) ;
+
+} // internal
+} // internal
+
+#endif

Modified: pkg/src/Rcpp/internal/wrap.h
===================================================================
--- pkg/src/Rcpp/internal/wrap.h	2010-02-01 21:03:12 UTC (rev 552)
+++ pkg/src/Rcpp/internal/wrap.h	2010-02-02 07:29:37 UTC (rev 553)
@@ -37,35 +37,6 @@
 template <typename InputIterator> SEXP range_wrap(InputIterator first, InputIterator last) ;
 
 // {{{ information about R vectors
-// welcome to template metaprogramming !!
-
-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) ;
-template<> double* r_vector_start<REALSXP,double>(SEXP x) ;
-template<> Rbyte* r_vector_start<RAWSXP,Rbyte>(SEXP x) ; 
-template<> Rcomplex* r_vector_start<CPLXSXP,Rcomplex>(SEXP x) ;                         
-
-template <int RTYPE,typename CTYPE> CTYPE get_zero(){ return static_cast<CTYPE>(0) ; } ;
-template<> Rcomplex get_zero<CPLXSXP,Rcomplex>() ;
-
-/**
- * Initializes a vector of the given SEXP type. The template fills the 
- * vector with the value 0 of the appropriate type, for example
- * an INTSXP vector is initialized with (int)0, etc...
- */
-template<int RTYPE> void r_init_vector(SEXP x){
-	typedef ::Rcpp::traits::storage_type<RTYPE>::type CTYPE ;
-	CTYPE* start=r_vector_start<RTYPE>(x) ;
-	std::fill( start, start + Rf_length(x), get_zero<RTYPE,CTYPE>(0) ) ;
-}
-// these are specifically overwritten so that they do nothing
-// - character vectors : already initialized with ""
-// - generic vectors   : already initialized with R_NilValue
-// - expression vectors: already initialized with R_NilValue
-template<> void r_init_vector<VECSXP>(SEXP x) ;
-template<> void r_init_vector<EXPRSXP>(SEXP x) ;
-template<> void r_init_vector<STRSXP>(SEXP x) ;
 // }}}
 
 // {{{ range wrap 

Modified: pkg/src/Rcpp/traits/storage_type.h
===================================================================
--- pkg/src/Rcpp/traits/storage_type.h	2010-02-01 21:03:12 UTC (rev 552)
+++ pkg/src/Rcpp/traits/storage_type.h	2010-02-02 07:29:37 UTC (rev 553)
@@ -28,15 +28,40 @@
 
 /**
  * Indicates the storage type associated with a SEXP type
- * for example: 
- * storage_type<INTSXP>::type is a typedef to int
+ * for example: storage_type<INTSXP>::type is a typedef to int
+ *
+ * The default is SEXP, which works for VECSXP, EXPRSXP and STRSXP
  */
 template<int RTYPE> struct storage_type{ typedef SEXP type ; } ;
 
+/**
+ * Total specialization for integer vector (INTSXP)
+ * typedef to int
+ */
 template<> struct storage_type<INTSXP>{  typedef int type ; } ;
+
+/**
+ * Total specialization for numeric vectors (REALSXP)
+ * typedef to double
+ */
 template<> struct storage_type<REALSXP>{ typedef double type ; } ;
+
+/**
+ * Total specialization for numeric vectors (CPLXSXP)
+ * typedef to Rcomplex
+ */
 template<> struct storage_type<CPLXSXP>{ typedef Rcomplex type ; } ;
+
+/**
+ * Total specialization for raw vectors (RAWSXP)
+ * typedef to Rbyte
+ */
 template<> struct storage_type<RAWSXP>{ typedef Rbyte type ; } ;
+
+/**
+ * Total specialization for logical vectors (LGLSXP)
+ * typedef to int
+ */
 template<> struct storage_type<LGLSXP>{ typedef int type ; } ;
 
 } // traits

Modified: pkg/src/RcppCommon.h
===================================================================
--- pkg/src/RcppCommon.h	2010-02-01 21:03:12 UTC (rev 552)
+++ pkg/src/RcppCommon.h	2010-02-02 07:29:37 UTC (rev 553)
@@ -230,6 +230,7 @@
 #include <Rcpp/traits/r_type_traits.h>
 #include <Rcpp/traits/wrap_type_traits.h>
 
+#include <Rcpp/internal/r_vector.h>
 #include <Rcpp/internal/convertible.h>
 #include <Rcpp/internal/wrap.h>
 #include <Rcpp/RObject.h>



More information about the Rcpp-commits mailing list