[Rcpp-commits] r760 - in pkg/Rcpp: . inst inst/unitTests src src/Rcpp src/Rcpp/traits
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Feb 21 20:17:05 CET 2010
Author: romain
Date: 2010-02-21 20:17:05 +0100 (Sun, 21 Feb 2010)
New Revision: 760
Removed:
pkg/Rcpp/src/as.cpp
Modified:
pkg/Rcpp/NEWS
pkg/Rcpp/inst/ChangeLog
pkg/Rcpp/inst/unitTests/runit.as.R
pkg/Rcpp/src/Rcpp/as.h
pkg/Rcpp/src/Rcpp/traits/Exporter.h
Log:
std::list<primitive> and std::deque<primitive> become possible candidates for as
Modified: pkg/Rcpp/NEWS
===================================================================
--- pkg/Rcpp/NEWS 2010-02-21 19:01:48 UTC (rev 759)
+++ pkg/Rcpp/NEWS 2010-02-21 19:17:05 UTC (rev 760)
@@ -1,5 +1,10 @@
0.7.8 (under development)
+ o The Rcpp::as template function has been reworked to be more
+ generic. It now handles more STL containers, such as deque and
+ list, and the genericity can be used to implement as for more
+ types. The package RcppArmadillo has examples of this
+
o new template class Rcpp::fixed_call that can be used in STL algorithms
such as std::generate.
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-02-21 19:01:48 UTC (rev 759)
+++ pkg/Rcpp/inst/ChangeLog 2010-02-21 19:17:05 UTC (rev 760)
@@ -1,6 +1,13 @@
2010-02-21 Romain Francois <romain at r-enthusiasts.com>
- * src/Rcpp/as.h: more generic as implementation for primitive types
+ * src/Rcpp/as.h: more generic as implementation. primitive
+ types are handled through templates which for example makes
+ it possible to as<GPB::int64> in RProtoBuf. std::deque<T>
+ and std::list<T> become as'able when T is a primitive type
+ as indicated by the Rcpp::traits::r_type_traits
+
+ * src/as.cpp: removed since as is now fully implemented via
+ templates
2010-02-19 Romain Francois <romain at r-enthusiasts.com>
Modified: pkg/Rcpp/inst/unitTests/runit.as.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.as.R 2010-02-21 19:01:48 UTC (rev 759)
+++ pkg/Rcpp/inst/unitTests/runit.as.R 2010-02-21 19:17:05 UTC (rev 760)
@@ -133,3 +133,21 @@
}
+test.as.deque.int <- function(){
+ funx <- cfunction(signature(x="integer"), '
+ deque<int> y = as< deque<int> >(x) ;
+ return wrap( accumulate( y.begin(), y.end(), 0.0 ) ) ;
+ ', Rcpp=TRUE, verbose=FALSE,
+ includes =c( "using namespace Rcpp;", "using namespace std;" ) )
+ checkEquals( funx(1:10), sum(1:10) , msg = "as<deque<int>>( INTSXP ) " )
+}
+
+test.as.list.int <- function(){
+ funx <- cfunction(signature(x="integer"), '
+ list<int> y = as< list<int> >(x) ;
+ return wrap( accumulate( y.begin(), y.end(), 0.0 ) ) ;
+ ', Rcpp=TRUE, verbose=FALSE,
+ includes =c( "using namespace Rcpp;", "using namespace std;" ) )
+ checkEquals( funx(1:10), sum(1:10) , msg = "as<list<int>>( INTSXP ) " )
+}
+
Modified: pkg/Rcpp/src/Rcpp/as.h
===================================================================
--- pkg/Rcpp/src/Rcpp/as.h 2010-02-21 19:01:48 UTC (rev 759)
+++ pkg/Rcpp/src/Rcpp/as.h 2010-02-21 19:17:05 UTC (rev 760)
@@ -73,7 +73,7 @@
return internal::as<T>( m_sexp, typename traits::r_type_traits<T>::r_category() ) ;
}
-template<> SEXP as(SEXP m_sexp) ;
+template<> inline SEXP as(SEXP m_sexp) { return m_sexp ; } ;
} // Rcpp
Modified: pkg/Rcpp/src/Rcpp/traits/Exporter.h
===================================================================
--- pkg/Rcpp/src/Rcpp/traits/Exporter.h 2010-02-21 19:01:48 UTC (rev 759)
+++ pkg/Rcpp/src/Rcpp/traits/Exporter.h 2010-02-21 19:17:05 UTC (rev 760)
@@ -100,9 +100,16 @@
template <typename T> class Exporter< std::vector<T> > : public RangeExporter< std::vector<T> > {
public:
Exporter(SEXP x) : RangeExporter< std::vector<T> >(x){}
-};
+};
+template <typename T> class Exporter< std::deque<T> > : public RangeExporter< std::deque<T> > {
+ public:
+ Exporter(SEXP x) : RangeExporter< std::deque<T> >(x){}
+};
+template <typename T> class Exporter< std::list<T> > : public RangeExporter< std::list<T> > {
+ public:
+ Exporter(SEXP x) : RangeExporter< std::list<T> >(x){}
+};
-
} // namespace traits
} // namespace Rcpp
#endif
Deleted: pkg/Rcpp/src/as.cpp
===================================================================
--- pkg/Rcpp/src/as.cpp 2010-02-21 19:01:48 UTC (rev 759)
+++ pkg/Rcpp/src/as.cpp 2010-02-21 19:17:05 UTC (rev 760)
@@ -1,31 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
-//
-// as.cpp: Rcpp R/C++ interface class library -- generic converters from SEXP
-//
-// 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/>.
-
-#include <RcppCommon.h>
-
-namespace Rcpp{
-
-template<> SEXP as<SEXP>(SEXP m_sexp){
- return m_sexp ;
-}
-
-} // namespace Rcpp
-
More information about the Rcpp-commits
mailing list