[Rcpp-commits] r795 - in pkg/Rcpp: inst src src/Rcpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Mar 1 09:19:33 CET 2010
Author: romain
Date: 2010-03-01 09:19:33 +0100 (Mon, 01 Mar 2010)
New Revision: 795
Removed:
pkg/Rcpp/src/ExpressionVector.cpp
Modified:
pkg/Rcpp/inst/ChangeLog
pkg/Rcpp/src/Rcpp/Vector.h
Log:
move ExpressionVector methods to Vector.h as templates
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-02-28 13:57:28 UTC (rev 794)
+++ pkg/Rcpp/inst/ChangeLog 2010-03-01 08:19:33 UTC (rev 795)
@@ -1,3 +1,9 @@
+2010-03-01 Romain Francois <romain at r-enthusiasts.com>
+
+ * src/ExpressionVector.cpp : replaced by templates in Vector.h
+ * src/Rcpp/Vector.h: use templates to cover ExpressionVector additional
+ methods : eval() and eval(const Environment& )
+
2010-02-28 Romain Francois <romain at r-enthusiasts.com>
* src/Rcpp/Vector.h : more generic code for vectors. All vector
Deleted: pkg/Rcpp/src/ExpressionVector.cpp
===================================================================
--- pkg/Rcpp/src/ExpressionVector.cpp 2010-02-28 13:57:28 UTC (rev 794)
+++ pkg/Rcpp/src/ExpressionVector.cpp 2010-03-01 08:19:33 UTC (rev 795)
@@ -1,55 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
-//
-// ExpressionVector.cpp: Rcpp R/C++ interface class library -- expression 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/>.
-
-#include <Rcpp/Vector.h>
-#include <Rcpp/Environment.h>
-
-namespace Rcpp{
-namespace internal{
-
- template <>
- SEXP vector_from_string<EXPRSXP>( const std::string& code ){
- ParseStatus status;
- SEXP expr = PROTECT( Rf_mkString( code.c_str() ) );
- SEXP res = PROTECT( R_ParseVector(expr, -1, &status, R_NilValue));
- switch( status ){
- case PARSE_OK:
- UNPROTECT( 2) ;
- return(res) ;
- break;
- default:
- UNPROTECT(2) ;
- throw parse_error() ;
- }
- return R_NilValue ; /* -Wall */
- }
-
- SEXP eval_methods< ::Rcpp::Vector<EXPRSXP> >::eval(){
- SEXP xp = ( static_cast< ::Rcpp::Vector<EXPRSXP>& >(*this) ).asSexp() ;
- return try_catch( ::Rf_lcons( ::Rf_install( "eval" ) , ::Rf_cons( xp, R_NilValue) ) ) ;
- } ;
- SEXP eval_methods< ::Rcpp::Vector<EXPRSXP> >::eval( const ::Rcpp::Environment& env ){
- SEXP xp = ( static_cast< ::Rcpp::Vector<EXPRSXP>& >(*this) ).asSexp() ;
- return try_catch( ::Rf_lcons( ::Rf_install( "eval" ) , ::Rf_cons( xp, ::Rf_cons(env.asSexp(), R_NilValue)) ) ) ;
- } ;
-
-} // namespace internal
-} // namespace Rcpp
Modified: pkg/Rcpp/src/Rcpp/Vector.h
===================================================================
--- pkg/Rcpp/src/Rcpp/Vector.h 2010-02-28 13:57:28 UTC (rev 794)
+++ pkg/Rcpp/src/Rcpp/Vector.h 2010-03-01 08:19:33 UTC (rev 795)
@@ -247,16 +247,45 @@
return r_cast<RTYPE>( Rf_mkString( st.c_str() ) ) ;
}
+ template <int RTYPE>
+ SEXP vector_from_string_expr( const std::string& code){
+ ParseStatus status;
+ SEXP expr = PROTECT( ::Rf_mkString( code.c_str() ) );
+ SEXP res = PROTECT( ::R_ParseVector(expr, -1, &status, R_NilValue));
+ switch( status ){
+ case PARSE_OK:
+ UNPROTECT( 2) ;
+ return(res) ;
+ break;
+ default:
+ UNPROTECT(2) ;
+ throw parse_error() ;
+ }
+ return R_NilValue ; /* -Wall */
+ }
+
template <>
- SEXP vector_from_string<EXPRSXP>( const std::string& st ) ;
+ inline SEXP vector_from_string<EXPRSXP>( const std::string& st ){
+ return vector_from_string_expr<EXPRSXP>( st ) ;
+ } ;
template <typename VECTOR> class eval_methods {} ;
- template<> class eval_methods< ::Rcpp::Vector<EXPRSXP> > {
+
+ template <typename VECTOR> class expr_eval_methods {
public:
- SEXP eval() ;
- SEXP eval( const ::Rcpp::Environment& env ) ;
+ SEXP eval(){
+ SEXP xp = ( static_cast<VECTOR&>(*this) ).asSexp() ;
+ return try_catch( ::Rf_lcons( ::Rf_install( "eval" ) , ::Rf_cons( xp, R_NilValue) ) ) ;
+ } ;
+ SEXP eval( const ::Rcpp::Environment& env ){
+ SEXP xp = ( static_cast<VECTOR&>(*this) ).asSexp() ;
+ return try_catch( ::Rf_lcons( ::Rf_install( "eval" ) , ::Rf_cons( xp, ::Rf_cons(env.asSexp(), R_NilValue)) ) ) ;
+ } ;
} ;
+ template<> class eval_methods< ::Rcpp::Vector<EXPRSXP> > :
+ public expr_eval_methods< ::Rcpp::Vector<EXPRSXP> > {} ;
+
}
namespace traits{
More information about the Rcpp-commits
mailing list