[Rcpp-commits] r1763 - in pkg/Rcpp: inst inst/include/Rcpp src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 30 13:48:39 CEST 2010


Author: edd
Date: 2010-06-30 13:48:38 +0200 (Wed, 30 Jun 2010)
New Revision: 1763

Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/DateVector.h
   pkg/Rcpp/inst/include/Rcpp/DatetimeVector.h
   pkg/Rcpp/src/DateVector.cpp
   pkg/Rcpp/src/DatetimeVector.cpp
Log:
corrected date and datetime vector indexing to int


Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-06-29 23:00:49 UTC (rev 1762)
+++ pkg/Rcpp/inst/ChangeLog	2010-06-30 11:48:38 UTC (rev 1763)
@@ -1,4 +1,10 @@
+2010-06-30  Dirk Eddelbuettel  <edd at debian.org>
 
+	* src/DateVector: Index argument is int; throw declared
+	* src/DatetimeVector: Idem
+	* inst/include/Rcpp/DateVector.h: Idem
+	* inst/include/Rcpp/DatetimeVector.h: Idem
+
 2010-06-28  Romain Francois <romain at r-enthusiasts.com>
 
 	* inst/include/Rcpp/sugar/Im.h:

Modified: pkg/Rcpp/inst/include/Rcpp/DateVector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/DateVector.h	2010-06-29 23:00:49 UTC (rev 1762)
+++ pkg/Rcpp/inst/include/Rcpp/DateVector.h	2010-06-30 11:48:38 UTC (rev 1763)
@@ -36,11 +36,11 @@
 		DateVector(int n);
 		~DateVector() {};
 
-		const Date& operator()(unsigned int i) const throw(std::range_error);
-		Date& operator()(unsigned int i) throw(std::range_error);
+		const Date& operator()(int i) const throw(std::range_error);
+		Date& operator()(int i) throw(std::range_error);
 
-		const Date& operator[](unsigned int i) const;
-		Date& operator[](unsigned int i);
+		const Date& operator[](int i) const throw(std::range_error);
+		Date& operator[](int i) throw(std::range_error);
 
 		int size() const;
 

Modified: pkg/Rcpp/inst/include/Rcpp/DatetimeVector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/DatetimeVector.h	2010-06-29 23:00:49 UTC (rev 1762)
+++ pkg/Rcpp/inst/include/Rcpp/DatetimeVector.h	2010-06-30 11:48:38 UTC (rev 1763)
@@ -36,11 +36,11 @@
 		DatetimeVector(int n);
 		~DatetimeVector() {};
 
-		const Datetime& operator()(unsigned int i) const throw(std::range_error);
-		Datetime& operator()(unsigned int i) throw(std::range_error);
+		const Datetime& operator()(int i) const throw(std::range_error);
+		Datetime& operator()(int i) throw(std::range_error);
 
-		const Datetime& operator[](unsigned int i) const;
-		Datetime& operator[](unsigned int i);
+		const Datetime& operator[](int i) const throw(std::range_error);
+		Datetime& operator[](int i) throw(std::range_error);
 
 		int size() const;
 

Modified: pkg/Rcpp/src/DateVector.cpp
===================================================================
--- pkg/Rcpp/src/DateVector.cpp	2010-06-29 23:00:49 UTC (rev 1762)
+++ pkg/Rcpp/src/DateVector.cpp	2010-06-30 11:48:38 UTC (rev 1763)
@@ -39,8 +39,8 @@
 
 	DateVector::DateVector(int n) : v(n){}
 
-	const Date & DateVector::operator()(unsigned int i) const throw(std::range_error) {
-		if (i >= v.size()) {
+	const Date & DateVector::operator()(int i) const throw(std::range_error) {
+		if (i < 0 || i >= static_cast<int>(v.size())) {
 			std::ostringstream oss;
 			oss << "DateVector: subscript out of range: " << i;
 			throw std::range_error(oss.str());
@@ -48,8 +48,8 @@
 		return v[i];
 	}
 
-	Date & DateVector::operator()(unsigned int i) throw(std::range_error) {
-		if (i >= v.size()) {
+	Date & DateVector::operator()(int i) throw(std::range_error) {
+		if (i < 0 || i >= static_cast<int>(v.size())) {
 			std::ostringstream oss;
 			oss << "DateVector: subscript out of range: " << i;
 			throw std::range_error(oss.str());
@@ -57,11 +57,21 @@
 		return v[i];
 	}
 
-	const Date & DateVector::operator[](unsigned int i) const {
+	const Date & DateVector::operator[](int i) const throw(std::range_error) {
+		if (i < 0 || i >= static_cast<int>(v.size())) {
+			std::ostringstream oss;
+			oss << "DatetimeVector: subscript out of range: " << i;
+			throw std::range_error(oss.str());
+		}
 		return v[i];
 	}
 
-	Date & DateVector::operator[](unsigned int i) {
+	Date & DateVector::operator[](int i) throw(std::range_error) {
+		if (i < 0 || i >= static_cast<int>(v.size())) {
+			std::ostringstream oss;
+			oss << "DatetimeVector: subscript out of range: " << i;
+			throw std::range_error(oss.str());
+		}
 		return v[i];
 	}
 

Modified: pkg/Rcpp/src/DatetimeVector.cpp
===================================================================
--- pkg/Rcpp/src/DatetimeVector.cpp	2010-06-29 23:00:49 UTC (rev 1762)
+++ pkg/Rcpp/src/DatetimeVector.cpp	2010-06-30 11:48:38 UTC (rev 1763)
@@ -39,8 +39,8 @@
 
 	DatetimeVector::DatetimeVector(int n) : v(n) {}
 
-	const Datetime & DatetimeVector::operator()(unsigned int i) const throw(std::range_error) {
-		if (i >= v.size()) {
+	const Datetime & DatetimeVector::operator()(int i) const throw(std::range_error) {
+		if (i < 0 || i >= static_cast<int>(v.size())) {
 			std::ostringstream oss;
 			oss << "DatetimeVector: subscript out of range: " << i;
 			throw std::range_error(oss.str());
@@ -48,8 +48,8 @@
 		return v[i];
 	}
 
-	Datetime & DatetimeVector::operator()(unsigned int i) throw(std::range_error) {
-		if (i >= v.size()) {
+	Datetime & DatetimeVector::operator()(int i) throw(std::range_error) {
+		if (i < 0 || i >= static_cast<int>(v.size())) {
 			std::ostringstream oss;
 			oss << "DatetimeVector: subscript out of range: " << i;
 			throw std::range_error(oss.str());
@@ -57,11 +57,21 @@
 		return v[i];
 	}
 
-	const Datetime & DatetimeVector::operator[](unsigned int i) const {
+	const Datetime & DatetimeVector::operator[](int i) const throw(std::range_error) {
+		if (i < 0 || i >= static_cast<int>(v.size())) {
+			std::ostringstream oss;
+			oss << "DatetimeVector: subscript out of range: " << i;
+			throw std::range_error(oss.str());
+		}
 		return v[i];
 	}
 
-	Datetime & DatetimeVector::operator[](unsigned int i) {
+	Datetime & DatetimeVector::operator[](int i) throw(std::range_error) {
+		if (i < 0 || i >= static_cast<int>(v.size())) {
+			std::ostringstream oss;
+			oss << "DatetimeVector: subscript out of range: " << i;
+			throw std::range_error(oss.str());
+		}
 		return v[i];
 	}
 



More information about the Rcpp-commits mailing list