[Rcpp-commits] r346 - in pkg: inst src src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jan 11 22:03:58 CET 2010


Author: romain
Date: 2010-01-11 22:03:55 +0100 (Mon, 11 Jan 2010)
New Revision: 346

Modified:
   pkg/inst/ChangeLog
   pkg/src/CharacterVector.cpp
   pkg/src/ComplexVector.cpp
   pkg/src/ExpressionVector.cpp
   pkg/src/GenericVector.cpp
   pkg/src/IntegerVector.cpp
   pkg/src/LogicalVector.cpp
   pkg/src/NumericVector.cpp
   pkg/src/RawVector.cpp
   pkg/src/Rcpp/CharacterVector.h
   pkg/src/Rcpp/ComplexVector.h
   pkg/src/Rcpp/ExpressionVector.h
   pkg/src/Rcpp/GenericVector.h
   pkg/src/Rcpp/IntegerVector.h
   pkg/src/Rcpp/LogicalVector.h
   pkg/src/Rcpp/NumericVector.h
   pkg/src/Rcpp/RawVector.h
Log:
*Vector::operator[] throw index out of bounds (FR#770)

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/inst/ChangeLog	2010-01-11 21:03:55 UTC (rev 346)
@@ -1,5 +1,9 @@
 2010-01-11  Romain Francois <francoisromain at free.fr>
 
+	* src/Rcpp/*Vector.h: operator[] now throws index out of bounds
+	exception when needed (FR#770)
+	* src/*Vector.cpp: same
+
 	* src/Rcpp/Environment.h: operator[](string) for environment
 	allowing to get/set values of a binding in this environment.
 	The Environment::Binding class has been created to act as

Modified: pkg/src/CharacterVector.cpp
===================================================================
--- pkg/src/CharacterVector.cpp	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/CharacterVector.cpp	2010-01-11 21:03:55 UTC (rev 346)
@@ -113,11 +113,13 @@
 	return *this ;
 }
 
-const CharacterVector::StringProxy CharacterVector::operator[](int i) const {
+const CharacterVector::StringProxy CharacterVector::operator[](int i) const throw(index_out_of_bounds){
+	if( i<0 || i>=length()) throw index_out_of_bounds() ;
 	return StringProxy(const_cast<CharacterVector&>(*this), i) ;
 }
 
-CharacterVector::StringProxy CharacterVector::operator[](int i) {
+CharacterVector::StringProxy CharacterVector::operator[](int i) throw(index_out_of_bounds) {
+	if( i<0 || i>=length()) throw index_out_of_bounds() ;
 	return StringProxy(*this, i ) ;
 }
 

Modified: pkg/src/ComplexVector.cpp
===================================================================
--- pkg/src/ComplexVector.cpp	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/ComplexVector.cpp	2010-01-11 21:03:55 UTC (rev 346)
@@ -55,7 +55,8 @@
 	}
 #endif
 
-Rcomplex& ComplexVector::operator[]( int i ) const { 
+Rcomplex& ComplexVector::operator[]( int i ) const throw(index_out_of_bounds){ 
+	if( i<0 || i>= length()) throw index_out_of_bounds() ;
 	return COMPLEX(m_sexp)[i] ;
 }
 Rcomplex* ComplexVector::begin() const { 

Modified: pkg/src/ExpressionVector.cpp
===================================================================
--- pkg/src/ExpressionVector.cpp	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/ExpressionVector.cpp	2010-01-11 21:03:55 UTC (rev 346)
@@ -89,11 +89,13 @@
 	return *this ;
 }
 
-const ExpressionVector::Proxy ExpressionVector::operator[](int i) const {
+const ExpressionVector::Proxy ExpressionVector::operator[](int i) const throw(index_out_of_bounds){
+	if( i<0 || i>= length()) throw index_out_of_bounds() ;
 	return Proxy(const_cast<ExpressionVector&>(*this), i) ;
 }
 
-ExpressionVector::Proxy ExpressionVector::operator[](int i) {
+ExpressionVector::Proxy ExpressionVector::operator[](int i) throw(index_out_of_bounds){
+	if( i<0 || i>= length()) throw index_out_of_bounds() ;
 	return Proxy(*this, i ) ;
 }
 

Modified: pkg/src/GenericVector.cpp
===================================================================
--- pkg/src/GenericVector.cpp	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/GenericVector.cpp	2010-01-11 21:03:55 UTC (rev 346)
@@ -89,11 +89,13 @@
 	return *this ;
 }
 
-const GenericVector::Proxy GenericVector::operator[](int i) const {
+const GenericVector::Proxy GenericVector::operator[](int i) const throw(index_out_of_bounds){
+	if( i<0 || i>=length()) throw index_out_of_bounds() ;
 	return Proxy(const_cast<GenericVector&>(*this), i) ;
 }
 
-GenericVector::Proxy GenericVector::operator[](int i) {
+GenericVector::Proxy GenericVector::operator[](int i) throw(index_out_of_bounds){
+	if( i<0 || i>=length()) throw index_out_of_bounds() ;
 	return Proxy(*this, i ) ;
 }
 

Modified: pkg/src/IntegerVector.cpp
===================================================================
--- pkg/src/IntegerVector.cpp	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/IntegerVector.cpp	2010-01-11 21:03:55 UTC (rev 346)
@@ -60,7 +60,8 @@
 	}
 #endif
 
-int& IntegerVector::operator[]( int i ) const { 
+int& IntegerVector::operator[]( int i ) const throw(index_out_of_bounds) { 
+	if( i < 0 || i >= length() ) throw index_out_of_bounds() ;
 	return INTEGER(m_sexp)[i] ;
 }
 int* IntegerVector::begin() const { 

Modified: pkg/src/LogicalVector.cpp
===================================================================
--- pkg/src/LogicalVector.cpp	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/LogicalVector.cpp	2010-01-11 21:03:55 UTC (rev 346)
@@ -66,7 +66,8 @@
 	}
 #endif
 
-int& LogicalVector::operator[]( int i ) const { 
+int& LogicalVector::operator[]( int i ) const throw(index_out_of_bounds){ 
+	if( i<0 || i>=length()) throw index_out_of_bounds() ;
 	return LOGICAL(m_sexp)[i] ;
 }
 int* LogicalVector::begin() const { 

Modified: pkg/src/NumericVector.cpp
===================================================================
--- pkg/src/NumericVector.cpp	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/NumericVector.cpp	2010-01-11 21:03:55 UTC (rev 346)
@@ -59,7 +59,8 @@
 	}
 #endif
 
-double& NumericVector::operator[]( int i ) const { 
+double& NumericVector::operator[]( int i ) const throw(index_out_of_bounds){ 
+	if( i<0 || i>=length()) throw index_out_of_bounds() ;
 	return REAL(m_sexp)[i] ;
 }
 double* NumericVector::begin() const { 

Modified: pkg/src/RawVector.cpp
===================================================================
--- pkg/src/RawVector.cpp	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/RawVector.cpp	2010-01-11 21:03:55 UTC (rev 346)
@@ -62,7 +62,8 @@
 	}
 #endif
 
-Rbyte& RawVector::operator[]( int i ) const { 
+Rbyte& RawVector::operator[]( int i ) const throw(index_out_of_bounds){ 
+	if( i<0 || i>= length() ) throw index_out_of_bounds() ;
 	return RAW(m_sexp)[i] ;
 }
 Rbyte* RawVector::begin() const { 

Modified: pkg/src/Rcpp/CharacterVector.h
===================================================================
--- pkg/src/Rcpp/CharacterVector.h	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/Rcpp/CharacterVector.h	2010-01-11 21:03:55 UTC (rev 346)
@@ -79,8 +79,8 @@
 	SEXP* begin(); 
 	SEXP* end() ;
 	
-	const StringProxy operator[]( int i ) const ;
-	StringProxy operator[]( int i ) ;
+	const StringProxy operator[]( int i ) const throw(index_out_of_bounds);
+	StringProxy operator[]( int i ) throw(index_out_of_bounds);
 	
 	friend class StringProxy; 
 	

Modified: pkg/src/Rcpp/ComplexVector.h
===================================================================
--- pkg/src/Rcpp/ComplexVector.h	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/Rcpp/ComplexVector.h	2010-01-11 21:03:55 UTC (rev 346)
@@ -52,7 +52,7 @@
 	 */
 	inline int size() const { return Rf_length( m_sexp ) ; }
 	
-	Rcomplex& operator[]( int i ) const ;
+	Rcomplex& operator[]( int i ) const throw(index_out_of_bounds) ;
 	Rcomplex* begin() const ; 
 	Rcomplex* end() const ;
 	

Modified: pkg/src/Rcpp/ExpressionVector.h
===================================================================
--- pkg/src/Rcpp/ExpressionVector.h	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/Rcpp/ExpressionVector.h	2010-01-11 21:03:55 UTC (rev 346)
@@ -78,8 +78,8 @@
 	SEXP* begin(); 
 	SEXP* end() ;
 
-	const Proxy operator[]( int i ) const ;
-	Proxy operator[]( int i ) ;
+	const Proxy operator[]( int i ) const throw(index_out_of_bounds);
+	Proxy operator[]( int i ) throw(index_out_of_bounds) ;
 
 	friend class Proxy; 
 

Modified: pkg/src/Rcpp/GenericVector.h
===================================================================
--- pkg/src/Rcpp/GenericVector.h	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/Rcpp/GenericVector.h	2010-01-11 21:03:55 UTC (rev 346)
@@ -76,11 +76,11 @@
 	 */
 	inline int size() const { return Rf_length( m_sexp ) ; }
 	
-	SEXP* begin(); 
-	SEXP* end() ;
+	// SEXP* begin(); 
+	// SEXP* end() ;
 	
-	const Proxy operator[]( int i ) const ;
-	Proxy operator[]( int i ) ;
+	const Proxy operator[]( int i ) const throw(index_out_of_bounds);
+	Proxy operator[]( int i ) throw(index_out_of_bounds) ;
 	
 	friend class Proxy; 
 	

Modified: pkg/src/Rcpp/IntegerVector.h
===================================================================
--- pkg/src/Rcpp/IntegerVector.h	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/Rcpp/IntegerVector.h	2010-01-11 21:03:55 UTC (rev 346)
@@ -53,7 +53,7 @@
 	 */
 	inline int size() const { return Rf_length( m_sexp ) ; }
 	
-	int& operator[]( int i ) const ;
+	int& operator[]( int i ) const throw(index_out_of_bounds) ;
 	int* begin() const ; 
 	int* end() const ;
 	

Modified: pkg/src/Rcpp/LogicalVector.h
===================================================================
--- pkg/src/Rcpp/LogicalVector.h	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/Rcpp/LogicalVector.h	2010-01-11 21:03:55 UTC (rev 346)
@@ -57,7 +57,7 @@
 	typedef Rboolean* iterator ;
 	typedef Rboolean value_type ;
 	
-	int& operator[]( int i ) const ;
+	int& operator[]( int i ) const throw(index_out_of_bounds) ;
 	int* begin() const ; 
 	int* end() const ;
 	

Modified: pkg/src/Rcpp/NumericVector.h
===================================================================
--- pkg/src/Rcpp/NumericVector.h	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/Rcpp/NumericVector.h	2010-01-11 21:03:55 UTC (rev 346)
@@ -53,7 +53,7 @@
 	 */
 	inline int size() const { return Rf_length( m_sexp ) ; }
 	
-	double& operator[]( int i ) const ;
+	double& operator[]( int i ) const throw(index_out_of_bounds) ;
 	double* begin() const ; 
 	double* end() const ;
 	

Modified: pkg/src/Rcpp/RawVector.h
===================================================================
--- pkg/src/Rcpp/RawVector.h	2010-01-11 20:35:19 UTC (rev 345)
+++ pkg/src/Rcpp/RawVector.h	2010-01-11 21:03:55 UTC (rev 346)
@@ -53,7 +53,7 @@
 	 */
 	inline int size() const { return Rf_length( m_sexp ) ; }
 	
-	Rbyte& operator[]( int i ) const ;
+	Rbyte& operator[]( int i ) const throw(index_out_of_bounds) ;
 	Rbyte* begin() const ; 
 	Rbyte* end() const ;
 	



More information about the Rcpp-commits mailing list