[Rcpp-commits] r3988 - in pkg/Rcpp: . inst/include inst/include/Rcpp/internal inst/include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Nov 17 10:43:46 CET 2012
Author: romain
Date: 2012-11-17 10:43:46 +0100 (Sat, 17 Nov 2012)
New Revision: 3988
Added:
pkg/Rcpp/inst/include/Rcpp/internal/SEXP_Iterator.h
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h
pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
pkg/Rcpp/inst/include/Rcpp/vector/proxy.h
pkg/Rcpp/inst/include/RcppCommon.h
Log:
added SEXP_Iterator as const iterator over lists
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-11-17 00:22:12 UTC (rev 3987)
+++ pkg/Rcpp/ChangeLog 2012-11-17 09:43:46 UTC (rev 3988)
@@ -1,7 +1,9 @@
2012-11-17 Romain Francois <romain at r-enthusiasts.com>
* include/Rcpp/internal/wrap_end.h: have calls to wrap as late as possible
- so that they "see" all (potentially user defined) overloads of wrap.
+ so that they "see" all (potentially user defined) overloads of wrap.
+ * include/Rcpp/internal/SEXP_Iterator.h: directly iterate over SEXP.
+ const iterator for List and ExpressionVector
2012-11-16 Romain Francois <romain at r-enthusiasts.com>
Added: pkg/Rcpp/inst/include/Rcpp/internal/SEXP_Iterator.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/SEXP_Iterator.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/internal/SEXP_Iterator.h 2012-11-17 09:43:46 UTC (rev 3988)
@@ -0,0 +1,75 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
+//
+// SEXP_Iterator.h: Rcpp R/C++ interface class library --
+//
+// Copyright (C) 2012 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__SEXP_Iterator__h
+#define Rcpp__internal__SEXP_Iterator__h
+
+namespace Rcpp{
+namespace internal{
+
+template <int RTYPE, typename VECTOR>
+class SEXP_Iterator {
+public:
+ typedef const SEXP& reference ;
+ typedef const SEXP* pointer ;
+ typedef int difference_type ;
+ typedef SEXP value_type;
+ typedef std::random_access_iterator_tag iterator_category ;
+
+ SEXP_Iterator( ): ptr(){} ;
+ SEXP_Iterator( const SEXP_Iterator& other) : ptr(other.ptr){} ;
+ SEXP_Iterator( const VECTOR& vec ) : ptr( get_vector_ptr(vec) ){} ;
+
+ SEXP_Iterator& operator=(const SEXP_Iterator& other){ ptr = other.ptr ; return *this ;}
+
+ int operator-( const SEXP_Iterator& other){ return ptr - other.ptr ; }
+
+ SEXP_Iterator operator+( int n){ return SEXP_Iterator(ptr+n); }
+ SEXP_Iterator operator-( int n){ return SEXP_Iterator(ptr-n); }
+
+ SEXP_Iterator& operator++(){ ptr++ ; return *this ; }
+ SEXP_Iterator& operator--(){ ptr-- ; return *this ; }
+ SEXP_Iterator& operator+=(int n){ ptr += n; return *this ; }
+ SEXP_Iterator& operator-=(int n){ ptr -= n; return *this ; }
+
+ bool operator<( const SEXP_Iterator& other ){ return ptr < other.ptr ; }
+ bool operator>( const SEXP_Iterator& other ){ return ptr > other.ptr ; }
+ bool operator<=( const SEXP_Iterator& other ){ return ptr <= other.ptr ; }
+ bool operator>=( const SEXP_Iterator& other ){ return ptr >= other.ptr ; }
+
+ reference operator*(){ return *ptr ; }
+ reference operator[](int n){ return ptr[n] ; }
+ bool operator==(const SEXP_Iterator& other) const { return ptr == other.ptr ;}
+ bool operator!=(const SEXP_Iterator& other) const { return ptr != other.ptr ;}
+
+
+private:
+ const SEXP* ptr ;
+ SEXP_Iterator( const SEXP* ptr_) : ptr(ptr_){}
+
+} ;
+
+}
+}
+
+#endif
+
Modified: pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h 2012-11-17 00:22:12 UTC (rev 3987)
+++ pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h 2012-11-17 09:43:46 UTC (rev 3988)
@@ -35,12 +35,15 @@
namespace traits {
template <int RTYPE> struct r_vector_cache_type ;
+ template <int RTYPE> class r_vector_cache ;
+
template <int RTYPE> struct r_vector_name_proxy ;
template <int RTYPE> struct r_vector_proxy ;
template <int RTYPE> struct r_vector_const_proxy ;
+
template <int RTYPE> struct r_vector_iterator ;
template <int RTYPE> struct r_vector_const_iterator ;
- template <int RTYPE> class r_vector_cache ;
+
}
Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h 2012-11-17 00:22:12 UTC (rev 3987)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h 2012-11-17 09:43:46 UTC (rev 3988)
@@ -35,7 +35,7 @@
MatrixColumn( MATRIX& parent, int i ) :
n(parent.nrow()),
start(parent.begin() + i * n ),
- const_start(parent.begin() + i *n)
+ const_start(const_cast<const MATRIX&>(parent).begin() + i *n)
{
if( i < 0 || i >= parent.ncol() ) throw index_out_of_bounds() ;
}
Modified: pkg/Rcpp/inst/include/Rcpp/vector/proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/proxy.h 2012-11-17 00:22:12 UTC (rev 3987)
+++ pkg/Rcpp/inst/include/Rcpp/vector/proxy.h 2012-11-17 09:43:46 UTC (rev 3988)
@@ -255,9 +255,11 @@
template<> struct r_vector_iterator<EXPRSXP> : proxy_based_iterator<EXPRSXP>{} ;
template<> struct r_vector_iterator<STRSXP> : proxy_based_iterator<STRSXP>{} ;
- template<> struct r_vector_const_iterator<VECSXP> : proxy_based_iterator<VECSXP>{} ;
- template<> struct r_vector_const_iterator<EXPRSXP> : proxy_based_iterator<EXPRSXP>{} ;
-
+ template <int RTYPE> struct proxy_based_const_iterator{
+ typedef ::Rcpp::internal::SEXP_Iterator<RTYPE, Vector<RTYPE> > type ;
+ } ;
+ template<> struct r_vector_const_iterator<VECSXP> : proxy_based_const_iterator<VECSXP>{} ;
+ template<> struct r_vector_const_iterator<EXPRSXP> : proxy_based_const_iterator<EXPRSXP>{} ;
template<> struct r_vector_const_iterator<STRSXP> {
typedef CharacterVectorExtractionIterator type ;
} ;
Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h 2012-11-17 00:22:12 UTC (rev 3987)
+++ pkg/Rcpp/inst/include/RcppCommon.h 2012-11-17 09:43:46 UTC (rev 3988)
@@ -339,6 +339,7 @@
#include <Rcpp/internal/ListInitialization.h>
#include <Rcpp/internal/Proxy_Iterator.h>
+#include <Rcpp/internal/SEXP_Iterator.h>
RcppExport SEXP RcppXPtrExample_create_external_pointer() ;
RcppExport SEXP RcppXPtrExample_get_external_pointer(SEXP );
More information about the Rcpp-commits
mailing list