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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 15 17:14:51 CEST 2010


Author: edd
Date: 2010-06-15 17:14:50 +0200 (Tue, 15 Jun 2010)
New Revision: 1544

Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/RcppDateVector.h
   pkg/Rcpp/inst/include/RcppDatetimeVector.h
   pkg/Rcpp/src/RcppDateVector.cpp
   pkg/Rcpp/src/RcppDatetimeVector.cpp
Log:
use std::vector rather than an array to hold the data


Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-06-15 06:16:59 UTC (rev 1543)
+++ pkg/Rcpp/inst/ChangeLog	2010-06-15 15:14:50 UTC (rev 1544)
@@ -1,3 +1,10 @@
+2010-06-15  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/RcppDatetimeVector.cpp: Use std::vector internally
+	* inst/include/RcppDatetimeVector.h: Idem
+	* src/RcppDateVector.cpp: Use std::vector internally
+	* inst/include/RcppDateVector.h: Idem
+
 2010-06-14  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/RcppDatetimeVector.cpp: Add ctor from int and setter method

Modified: pkg/Rcpp/inst/include/RcppDateVector.h
===================================================================
--- pkg/Rcpp/inst/include/RcppDateVector.h	2010-06-15 06:16:59 UTC (rev 1543)
+++ pkg/Rcpp/inst/include/RcppDateVector.h	2010-06-15 15:14:50 UTC (rev 1544)
@@ -31,13 +31,12 @@
 public:
     RcppDateVector(SEXP vec);
     RcppDateVector(int n);
-    ~RcppDateVector();
-    RcppDate& operator()(int i) const;
+    ~RcppDateVector() {};
+    const RcppDate& operator()(unsigned int i) const;
     int size() const;
-    void set(int i, const RcppDate &d);
+    void set(unsigned int i, const RcppDate &d);
 private:
-    RcppDate *v;
-    int length;
+    std::vector<RcppDate> v;
 };
 
 #endif

Modified: pkg/Rcpp/inst/include/RcppDatetimeVector.h
===================================================================
--- pkg/Rcpp/inst/include/RcppDatetimeVector.h	2010-06-15 06:16:59 UTC (rev 1543)
+++ pkg/Rcpp/inst/include/RcppDatetimeVector.h	2010-06-15 15:14:50 UTC (rev 1544)
@@ -3,6 +3,7 @@
 // RcppDatetimeeVector.h: Rcpp R/C++ interface class library -- Datetime vector support
 //
 // Copyright (C) 2008 - 2009 Dirk Eddelbuettel
+// Copyright (C) 2010	     Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -29,13 +30,12 @@
 public:
     RcppDatetimeVector(SEXP vec);
     RcppDatetimeVector(int n);
-    ~RcppDatetimeVector();
-    RcppDatetime &operator()(int i) const;
+    ~RcppDatetimeVector() {};
+    const RcppDatetime &operator()(unsigned int i) const;
     int size() const;
-    void set(int i, const RcppDatetime &dt);
+    void set(unsigned int i, const RcppDatetime &dt);
 private:
-    RcppDatetime *v;
-    int length;
+    std::vector<RcppDatetime> v;
 };
 
 #endif

Modified: pkg/Rcpp/src/RcppDateVector.cpp
===================================================================
--- pkg/Rcpp/src/RcppDateVector.cpp	2010-06-15 06:16:59 UTC (rev 1543)
+++ pkg/Rcpp/src/RcppDateVector.cpp	2010-06-15 15:14:50 UTC (rev 1544)
@@ -4,6 +4,7 @@
 //
 // Copyright (C) 2005 - 2006 Dominick Samperi
 // Copyright (C) 2008 - 2009 Dirk Eddelbuettel
+// Copyright (C) 2010	     Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -29,23 +30,17 @@
     int len = Rf_length(vec);
     if (len == 0)
 	throw std::range_error("RcppDateVector: null vector in constructor");
-    v = new RcppDate[len];
+    v.resize(len);
     for (i = 0; i < len; i++)
-	v[i] = RcppDate((int)REAL(vec)[i]);
-    length = len;
+	v[i] = RcppDate( (int) REAL(vec)[i]);
 }
 
 RcppDateVector::RcppDateVector(int n) {
-    v = new RcppDate[n];
-    length = n;
+    v.resize(n);
 }
 
-RcppDateVector::~RcppDateVector() {
-    delete [] v;
-}
-
-RcppDate& RcppDateVector::operator()(int i) const {
-    if (i < 0 || i >= length) {
+const RcppDate& RcppDateVector::operator()(unsigned int i) const {
+    if (i >= v.size()) {
 	std::ostringstream oss;
 	oss << "RcppDateVector: subscript out of range: " << i;
 	throw std::range_error(oss.str());
@@ -54,11 +49,11 @@
 }
 
 int RcppDateVector::size() const { 
-    return length; 
+    return v.size(); 
 }
 
-void RcppDateVector::set(int i, const RcppDate &d) {
-    if (i < 0 || i >= length) {
+void RcppDateVector::set(unsigned int i, const RcppDate &d) {
+    if (i >= v.size()) {
 	std::ostringstream oss;
 	oss << "RcppDateVector: subscript out of range: " << i;
 	throw std::range_error(oss.str());

Modified: pkg/Rcpp/src/RcppDatetimeVector.cpp
===================================================================
--- pkg/Rcpp/src/RcppDatetimeVector.cpp	2010-06-15 06:16:59 UTC (rev 1543)
+++ pkg/Rcpp/src/RcppDatetimeVector.cpp	2010-06-15 15:14:50 UTC (rev 1544)
@@ -3,6 +3,7 @@
 // RcppDatetimeVector.cpp: Rcpp R/C++ interface class library -- Datetime vector support
 //
 // Copyright (C) 2008 - 2009 Dirk Eddelbuettel
+// Copyright (C) 2010	     Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -28,18 +29,13 @@
     int len = Rf_length(vec);
     if (len == 0)
 	throw std::range_error("RcppDatetimeVector: null vector in constructor");
-    v = new RcppDatetime[len];
+    v.resize(len);
     for (i = 0; i < len; i++)
 	v[i] = RcppDatetime(REAL(vec)[i]);
-    length = len;
 }
 
-RcppDatetimeVector::~RcppDatetimeVector() {
-    delete [] v;
-}
-
-RcppDatetime & RcppDatetimeVector::operator()(int i) const {
-    if (i < 0 || i >= length) {
+const RcppDatetime & RcppDatetimeVector::operator()(unsigned int i) const {
+    if (i >= v.size()) {
 	std::ostringstream oss;
 	oss << "RcppDatetimeVector: subscript out of range: " << i;
 	throw std::range_error(oss.str());
@@ -48,11 +44,11 @@
 }
 
 int RcppDatetimeVector::size() const { 
-    return length; 
+    return v.size(); 
 }
 
-void RcppDatetimeVector::set(int i, const RcppDatetime &dt) {
-    if (i < 0 || i >= length) {
+void RcppDatetimeVector::set(unsigned int i, const RcppDatetime &dt) {
+    if (i >= v.size()) {
 	std::ostringstream oss;
 	oss << "RcppDatetimeVector: subscript out of range: " << i;
 	throw std::range_error(oss.str());



More information about the Rcpp-commits mailing list