[Rcpp-commits] r3986 - in pkg/Rcpp: . inst/include/Rcpp inst/include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Nov 16 22:28:10 CET 2012
Author: romain
Date: 2012-11-16 22:28:09 +0100 (Fri, 16 Nov 2012)
New Revision: 3986
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/Fast.h
pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h
pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
pkg/Rcpp/inst/include/Rcpp/vector/MatrixBase.h
pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h
pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
pkg/Rcpp/inst/include/Rcpp/vector/proxy.h
pkg/Rcpp/inst/include/Rcpp/vector/traits.h
Log:
deal with const ness
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/ChangeLog 2012-11-16 21:28:09 UTC (rev 3986)
@@ -2,8 +2,14 @@
* include/Rcpp/vector/Vector.h : added static methods Vector::is_na and
Vector::get_na
- * inst/include/Rcpp/sugar/functions/setdiff.h: initial version of
+ * include/Rcpp/sugar/functions/setdiff.h: initial version of
setdiff and intersect
+ * include/Rcpp/vector/MatrixColumn.h: dealing with const-ness
+ * include/Rcpp/vector/MatrixRow.h: dealing with const-ness
+ * include/Rcpp/vector/traits.h: dealing with const-ness
+ * include/Rcpp/vector/proxy.h: dealing with const-ness
+ * include/Rcpp/vector/MatrixBase.h: dealing with const-ness
+ * include/Rcpp/vector/Vector.h: dealing with const-ness
2012-11-15 Romain Francois <romain at r-enthusiasts.com>
Modified: pkg/Rcpp/inst/include/Rcpp/Fast.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Fast.h 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/inst/include/Rcpp/Fast.h 2012-11-16 21:28:09 UTC (rev 3986)
@@ -2,7 +2,7 @@
//
// Fast.h: Rcpp R/C++ interface class library -- faster vectors (less interface)
//
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
@@ -31,7 +31,7 @@
Fast( const VECTOR& v_) : v(v_), data( v_.begin() ){}
inline value_type& operator[]( int i){ return data[i] ; }
- inline value_type& operator[]( int i) const { return data[i] ; }
+ inline const value_type& operator[]( int i) const { return data[i] ; }
inline int size() const { return v.size() ; }
private:
Modified: pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h 2012-11-16 21:28:09 UTC (rev 3986)
@@ -37,6 +37,7 @@
template <int RTYPE> struct r_vector_cache_type ;
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/Matrix.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h 2012-11-16 21:28:09 UTC (rev 3986)
@@ -34,6 +34,7 @@
typedef typename VECTOR::converter_type converter_type ;
typedef typename VECTOR::stored_type stored_type ;
typedef typename VECTOR::Proxy Proxy ;
+ typedef typename VECTOR::const_Proxy const_Proxy ;
Matrix() : VECTOR() {}
@@ -147,6 +148,9 @@
inline Column operator()( internal::NamedPlaceHolder, int i ){
return Column( *this, i ) ;
}
+ inline Column operator()( internal::NamedPlaceHolder, int i ) const {
+ return Column( *this, i ) ;
+ }
inline Sub operator()( const Range& row_range, const Range& col_range){
return Sub( const_cast<Matrix&>(*this), row_range, col_range ) ;
Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixBase.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixBase.h 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixBase.h 2012-11-16 21:28:09 UTC (rev 3986)
@@ -43,9 +43,9 @@
return static_cast<const MATRIX*>(this)->operator()(i, j) ;
}
- inline int size() const { return static_cast<const MATRIX&>(*this).size() ; }
- inline int nrow() const { return static_cast<const MATRIX&>(*this).nrow() ; }
- inline int ncol() const { return static_cast<const MATRIX&>(*this).ncol() ; }
+ inline R_len_t size() const { return static_cast<const MATRIX&>(*this).size() ; }
+ inline R_len_t nrow() const { return static_cast<const MATRIX&>(*this).nrow() ; }
+ inline R_len_t ncol() const { return static_cast<const MATRIX&>(*this).ncol() ; }
class iterator {
public:
Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h 2012-11-16 21:28:09 UTC (rev 3986)
@@ -2,7 +2,7 @@
//
// MatrixColumn.h: Rcpp R/C++ interface class library -- matrices column
//
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
@@ -27,68 +27,78 @@
public:
typedef Matrix<RTYPE> MATRIX ;
typedef typename MATRIX::Proxy Proxy ;
+ typedef typename MATRIX::const_Proxy const_Proxy ;
typedef typename MATRIX::value_type value_type ;
typedef typename MATRIX::iterator iterator ;
+ typedef typename MATRIX::const_iterator const_iterator ;
- MatrixColumn( MATRIX& object, int i ) :
- parent(object), index(i), start(parent.begin() + i * parent.nrow() )
+ MatrixColumn( MATRIX& parent, int i ) :
+ n(parent.nrow()),
+ start(parent.begin() + i * n ),
+ const_start(parent.begin() + i *n)
{
if( i < 0 || i >= parent.ncol() ) throw index_out_of_bounds() ;
}
+
+ MatrixColumn( const MATRIX& parent, int i ) :
+ n(parent.nrow()),
+ start(parent.begin() + i * n ),
+ const_start(parent.begin() + i *n)
+ {
+ if( i < 0 || i >= parent.ncol() ) throw index_out_of_bounds() ;
+ }
MatrixColumn( const MatrixColumn& other ) :
- parent(other.parent), index(other.index), start(other.start){} ;
+ n(other.n),
+ start(other.start),
+ const_start(other.const_start) {}
template <int RT, bool NA, typename T>
MatrixColumn& operator=( const Rcpp::VectorBase<RT,NA,T>& rhs ){
- int n = size() ;
const T& ref = rhs.get_ref() ;
RCPP_LOOP_UNROLL(start,ref)
- return *this ;
+ return *this ;
}
MatrixColumn& operator=( const MatrixColumn& rhs ){
- int n = size() ;
iterator rhs_start = rhs.start ;
RCPP_LOOP_UNROLL(start,rhs_start)
- return *this ;
+ return *this ;
}
inline Proxy operator[]( int i ){
- /* TODO: should we cache nrow and ncol */
return start[i] ;
}
- inline Proxy operator[]( int i ) const {
- /* TODO: should we cache nrow and ncol */
- return start[i] ;
+ inline const_Proxy operator[]( int i ) const {
+ return const_start[i] ;
}
inline iterator begin(){
return start ;
}
- inline iterator begin() const {
- return start ;
+ inline const_iterator begin() const {
+ return const_start ;
}
inline iterator end(){
- return start + parent.nrow() ;
+ return start + n ;
}
- inline iterator end() const {
- return start + parent.nrow() ;
+ inline const_iterator end() const {
+ return const_start + n ;
}
- inline int size() const {
- return parent.nrow() ;
+ inline R_len_t size() const {
+ return n ;
}
-
+
private:
- MATRIX& parent;
- int index ;
+ const R_len_t n ;
iterator start ;
-
+ const_iterator const_start ;
+
} ;
#endif
Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h 2012-11-16 21:28:09 UTC (rev 3986)
@@ -2,7 +2,7 @@
//
// MatrixRow.h: Rcpp R/C++ interface class library -- matrices row
//
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h 2012-11-16 21:28:09 UTC (rev 3986)
@@ -42,6 +42,7 @@
{
public:
typedef typename traits::r_vector_proxy<RTYPE>::type Proxy ;
+ typedef typename traits::r_vector_const_proxy<RTYPE>::type const_Proxy ;
typedef typename traits::r_vector_name_proxy<RTYPE>::type NameProxy ;
typedef typename traits::r_vector_proxy<RTYPE>::type value_type ;
typedef typename traits::r_vector_iterator<RTYPE>::type iterator ;
Modified: pkg/Rcpp/inst/include/Rcpp/vector/proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/proxy.h 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/inst/include/Rcpp/vector/proxy.h 2012-11-16 21:28:09 UTC (rev 3986)
@@ -226,6 +226,20 @@
} ;
template <int RTYPE>
+ struct r_vector_const_proxy{
+ typedef const typename storage_type<RTYPE>::type& type ;
+ } ;
+ template<> struct r_vector_const_proxy<STRSXP> {
+ typedef ::Rcpp::internal::string_proxy<STRSXP> type ;
+ } ;
+ template<> struct r_vector_const_proxy<EXPRSXP> {
+ typedef ::Rcpp::internal::generic_proxy<EXPRSXP> type ;
+ } ;
+ template<> struct r_vector_const_proxy<VECSXP> {
+ typedef ::Rcpp::internal::generic_proxy<VECSXP> type ;
+ } ;
+
+ template <int RTYPE>
struct r_vector_iterator {
typedef typename storage_type<RTYPE>::type* type ;
};
Modified: pkg/Rcpp/inst/include/Rcpp/vector/traits.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/traits.h 2012-11-16 19:16:24 UTC (rev 3985)
+++ pkg/Rcpp/inst/include/Rcpp/vector/traits.h 2012-11-16 21:28:09 UTC (rev 3986)
@@ -31,6 +31,7 @@
typedef typename r_vector_iterator<RTYPE>::type iterator ;
typedef typename r_vector_const_iterator<RTYPE>::type const_iterator ;
typedef typename r_vector_proxy<RTYPE>::type proxy ;
+ typedef typename r_vector_const_proxy<RTYPE>::type const_proxy ;
typedef typename storage_type<RTYPE>::type storage_type ;
r_vector_cache() : start(0){} ;
@@ -56,6 +57,7 @@
typedef typename r_vector_iterator<RTYPE>::type iterator ;
typedef typename r_vector_const_iterator<RTYPE>::type const_iterator ;
typedef typename r_vector_proxy<RTYPE>::type proxy ;
+ typedef typename r_vector_const_proxy<RTYPE>::type const_proxy ;
proxy_cache(): p(0){}
~proxy_cache(){}
@@ -66,9 +68,12 @@
inline iterator get() const { return iterator( proxy(*p, 0 ) ) ;}
inline const_iterator get_const() const { return const_iterator( *p ) ;}
- inline proxy ref() const { return proxy(*p,0) ; }
- inline proxy ref(int i) const { return proxy(*p,i);}
+ inline proxy ref() { return proxy(*p,0) ; }
+ inline proxy ref(int i) { return proxy(*p,i);}
+ inline const_proxy ref() const { return const_proxy(*p,0) ; }
+ inline const_proxy ref(int i) const { return const_proxy(*p,i);}
+
private:
VECTOR* p ;
} ;
More information about the Rcpp-commits
mailing list