[Rcpp-commits] r1764 - in pkg/Rcpp: inst inst/include/classic inst/unitTests src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 1 23:42:45 CEST 2010


Author: edd
Date: 2010-07-01 23:42:45 +0200 (Thu, 01 Jul 2010)
New Revision: 1764

Added:
   pkg/Rcpp/inst/unitTests/runit.RcppList.R
Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/classic/RcppDateVector.h
   pkg/Rcpp/inst/include/classic/RcppDatetimeVector.h
   pkg/Rcpp/src/RcppDateVector.cpp
   pkg/Rcpp/src/RcppDatetimeVector.cpp
Log:
RcppDate(time)?Vector also uses int as index as before
added small test for RcppList


Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-06-30 11:48:38 UTC (rev 1763)
+++ pkg/Rcpp/inst/ChangeLog	2010-07-01 21:42:45 UTC (rev 1764)
@@ -1,3 +1,12 @@
+2010-07-01  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/RcppDateVector: Index argument is int here as well
+	* src/RcppDatetimeVector: Idem
+	* inst/include/classic/RcppDateVector.h: Idem
+	* inst/include/classic/RcppDatetimeVector.h: Idem
+
+	* inst/unitTests/runit.List.R: Added simple test for RcppList
+
 2010-06-30  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/DateVector: Index argument is int; throw declared

Modified: pkg/Rcpp/inst/include/classic/RcppDateVector.h
===================================================================
--- pkg/Rcpp/inst/include/classic/RcppDateVector.h	2010-06-30 11:48:38 UTC (rev 1763)
+++ pkg/Rcpp/inst/include/classic/RcppDateVector.h	2010-07-01 21:42:45 UTC (rev 1764)
@@ -32,8 +32,8 @@
     RcppDateVector(SEXP vec);
     RcppDateVector(int n);
     ~RcppDateVector() {};
-    const RcppDate& operator()(unsigned int i) const;
-    RcppDate& operator()(unsigned int i);
+    const RcppDate& operator()(int i) const;
+    RcppDate& operator()(int i);
     int size() const;
 private:
     std::vector<RcppDate> v;

Modified: pkg/Rcpp/inst/include/classic/RcppDatetimeVector.h
===================================================================
--- pkg/Rcpp/inst/include/classic/RcppDatetimeVector.h	2010-06-30 11:48:38 UTC (rev 1763)
+++ pkg/Rcpp/inst/include/classic/RcppDatetimeVector.h	2010-07-01 21:42:45 UTC (rev 1764)
@@ -31,8 +31,8 @@
     RcppDatetimeVector(SEXP vec);
     RcppDatetimeVector(int n);
     ~RcppDatetimeVector() {};
-    const RcppDatetime &operator()(unsigned int i) const;
-    RcppDatetime &operator()(unsigned int i);
+    const RcppDatetime &operator()(int i) const;
+    RcppDatetime &operator()(int i);
     int size() const;
 private:
     std::vector<RcppDatetime> v;

Added: pkg/Rcpp/inst/unitTests/runit.RcppList.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.RcppList.R	                        (rev 0)
+++ pkg/Rcpp/inst/unitTests/runit.RcppList.R	2010-07-01 21:42:45 UTC (rev 1764)
@@ -0,0 +1,29 @@
+#!/usr/bin/r -t
+#
+# Copyright (C) 2010	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/>.
+
+test.RcppList <- function() {
+    src <- 'RcppList l;
+            l.setSize(3);
+            l.append("foo", 1);
+            l.append("bar", 2.0);
+            l.append("biz", "xyz");
+            return l.getList();';
+    fun <- cxxfunction(signature(), src, plugin="Rcpp")
+    checkEquals(fun(), list(foo=1L, bar=2, biz="xyz"), msg="RcppList")
+}


Property changes on: pkg/Rcpp/inst/unitTests/runit.RcppList.R
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:eol-style
   + native

Modified: pkg/Rcpp/src/RcppDateVector.cpp
===================================================================
--- pkg/Rcpp/src/RcppDateVector.cpp	2010-06-30 11:48:38 UTC (rev 1763)
+++ pkg/Rcpp/src/RcppDateVector.cpp	2010-07-01 21:42:45 UTC (rev 1764)
@@ -39,8 +39,8 @@
     v.resize(n);
 }
 
-const RcppDate& RcppDateVector::operator()(unsigned int i) const {
-    if (i >= v.size()) {
+const RcppDate& RcppDateVector::operator()(int i) const {
+    if (i < 0 || i >= static_cast<int>(v.size())) {
 	std::ostringstream oss;
 	oss << "RcppDateVector: subscript out of range: " << i;
 	throw std::range_error(oss.str());
@@ -48,8 +48,8 @@
     return v[i];
 }
 
-RcppDate& RcppDateVector::operator()(unsigned int i) {
-    if (i >= v.size()) {
+RcppDate& RcppDateVector::operator()(int i) {
+    if (i < 0 || i >= static_cast<int>(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-30 11:48:38 UTC (rev 1763)
+++ pkg/Rcpp/src/RcppDatetimeVector.cpp	2010-07-01 21:42:45 UTC (rev 1764)
@@ -34,8 +34,8 @@
 	v[i] = RcppDatetime(REAL(vec)[i]);
 }
 
-const RcppDatetime & RcppDatetimeVector::operator()(unsigned int i) const {
-    if (i >= v.size()) {
+const RcppDatetime & RcppDatetimeVector::operator()(int i) const {
+    if (i < 0 || i >= static_cast<int>(v.size())) {
 	std::ostringstream oss;
 	oss << "RcppDatetimeVector: subscript out of range: " << i;
 	throw std::range_error(oss.str());
@@ -43,8 +43,8 @@
     return v[i];
 }
 
-RcppDatetime & RcppDatetimeVector::operator()(unsigned int i) {
-    if (i >= v.size()) {
+RcppDatetime & RcppDatetimeVector::operator()(int i) {
+    if (i < 0 || i >= static_cast<int>(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