[Rcpp-commits] r549 - 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:52:05 CET 2010
Author: romain
Date: 2010-02-01 21:52:05 +0100 (Mon, 01 Feb 2010)
New Revision: 549
Added:
pkg/src/Rcpp/traits/r_sexptype_traits.h
Modified:
pkg/src/Rcpp/internal/wrap.h
pkg/src/RcppCommon.h
Log:
moving r_sexptype_traits to the traits namespace
Modified: pkg/src/Rcpp/internal/wrap.h
===================================================================
--- pkg/src/Rcpp/internal/wrap.h 2010-02-01 18:06:39 UTC (rev 548)
+++ pkg/src/Rcpp/internal/wrap.h 2010-02-01 20:52:05 UTC (rev 549)
@@ -39,17 +39,6 @@
// {{{ information about R vectors
// welcome to template metaprogramming !!
-// template that returns the SEXP type that is appropriate for
-// the type T, this is allways VECSXP (lists) unless it is specialized
-template <typename T> struct r_sexptype{ enum{ rtype = VECSXP }; } ;
-template<> struct r_sexptype<int>{ enum{ rtype = INTSXP } ; } ;
-template<> struct r_sexptype<size_t>{ enum{ rtype = INTSXP } ; } ;
-template<> struct r_sexptype<double>{ enum{ rtype = REALSXP } ; } ;
-template<> struct r_sexptype<bool>{ enum{ rtype = LGLSXP } ; } ;
-template<> struct r_sexptype<std::string>{ enum{ rtype = STRSXP } ; } ;
-template<> struct r_sexptype<Rcomplex>{ enum{ rtype = CPLXSXP } ; } ;
-template<> struct r_sexptype<Rbyte>{ enum{ rtype = RAWSXP } ; } ;
-
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 ; } ;
@@ -93,7 +82,7 @@
template <typename InputIterator, typename T>
SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_primitive_tag){
size_t size = std::distance( first, last ) ;
- const int RTYPE = r_sexptype<T>::rtype ;
+ 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) ) ;
UNPROTECT(1) ;
@@ -177,7 +166,7 @@
template <typename InputIterator, typename T>
SEXP range_wrap_dispatch___impl( InputIterator first, InputIterator last, ::Rcpp::traits::r_type_pairstring_primitive_tag){
size_t size = std::distance( first, last ) ;
- const int RTYPE = r_sexptype<typename T::second_type>::rtype ;
+ 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) ;
@@ -303,7 +292,7 @@
*/
template <typename T>
SEXP primitive_wrap__impl( const T& object, ::Rcpp::traits::r_type_primitive_tag ){
- const int RTYPE = r_sexptype<T>::rtype ;
+ 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 ;
UNPROTECT(1);
Added: pkg/src/Rcpp/traits/r_sexptype_traits.h
===================================================================
--- pkg/src/Rcpp/traits/r_sexptype_traits.h (rev 0)
+++ pkg/src/Rcpp/traits/r_sexptype_traits.h 2010-02-01 20:52:05 UTC (rev 549)
@@ -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__r_sexptype_traits__h
+#define Rcpp__traits__r_sexptype_traits__h
+
+namespace Rcpp{
+namespace traits{
+
+/**
+ * template that returns the SEXP type that is appropriate for
+ * the type T, this is allways VECSXP (lists) unless it is specialized
+ */
+template <typename T> struct r_sexptype_traits{ enum{ rtype = VECSXP }; } ;
+template<> struct r_sexptype_traits<int>{ enum{ rtype = INTSXP } ; } ;
+template<> struct r_sexptype_traits<size_t>{ enum{ rtype = INTSXP } ; } ;
+template<> struct r_sexptype_traits<double>{ enum{ rtype = REALSXP } ; } ;
+template<> struct r_sexptype_traits<bool>{ enum{ rtype = LGLSXP } ; } ;
+template<> struct r_sexptype_traits<std::string>{ enum{ rtype = STRSXP } ; } ;
+template<> struct r_sexptype_traits<Rcomplex>{ enum{ rtype = CPLXSXP } ; } ;
+template<> struct r_sexptype_traits<Rbyte>{ enum{ rtype = RAWSXP } ; } ;
+
+} // traits
+} // Rcpp
+
+#endif
Modified: pkg/src/RcppCommon.h
===================================================================
--- pkg/src/RcppCommon.h 2010-02-01 18:06:39 UTC (rev 548)
+++ pkg/src/RcppCommon.h 2010-02-01 20:52:05 UTC (rev 549)
@@ -225,6 +225,7 @@
} // namespace Rcpp
// DO NOT CHANGE THE ORDER OF THESE INCLUDES
+#include <Rcpp/traits/r_sexptype_traits.h>
#include <Rcpp/traits/r_type_traits.h>
#include <Rcpp/traits/wrap_type_traits.h>
More information about the Rcpp-commits
mailing list