[Rcpp-commits] r1529 - in pkg/Rcpp: inst inst/include src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jun 13 22:47:07 CEST 2010
Author: edd
Date: 2010-06-13 22:47:07 +0200 (Sun, 13 Jun 2010)
New Revision: 1529
Modified:
pkg/Rcpp/inst/ChangeLog
pkg/Rcpp/inst/include/RcppDateVector.h
pkg/Rcpp/inst/include/RcppResultSet.h
pkg/Rcpp/src/RcppDateVector.cpp
pkg/Rcpp/src/RcppResultSet.cpp
Log:
proper template specialisation for wrap()
add const qualifier to operator()(int i) for RcppDateVector
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-06-13 19:37:25 UTC (rev 1528)
+++ pkg/Rcpp/inst/ChangeLog 2010-06-13 20:47:07 UTC (rev 1529)
@@ -1,3 +1,11 @@
+2010-06-13 Dirk Eddelbuettel <edd at debian.org>
+
+ * src/RcppResultSet.cpp: Proper template specialisation for wrap
+ * inst/include/RcppResultSet.h: Idem
+
+ * src/RcppDateVector.cpp: Add const qualifier to operator()(int i)
+ * inst/include/RcppResultSet.h: Idem
+
2010-06-13 Romain Francois <romain at r-enthusiasts.com>
* inst/include/Rcpp/Vector.h: added new factory functions for Vector:
@@ -8,8 +16,6 @@
* src/RcppDate.cpp: Simple RcppDate(SEXP) ctor added
* inst/include/RcppDate.h: Idem
-2010-06-12 Dirk Eddelbuettel <edd at debian.org>
-
* src/RcppResultSet.cpp: carved out four new wrap() functions by
splitting the existing code in add() methods off
Modified: pkg/Rcpp/inst/include/RcppDateVector.h
===================================================================
--- pkg/Rcpp/inst/include/RcppDateVector.h 2010-06-13 19:37:25 UTC (rev 1528)
+++ pkg/Rcpp/inst/include/RcppDateVector.h 2010-06-13 20:47:07 UTC (rev 1529)
@@ -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.
//
@@ -30,7 +31,7 @@
public:
RcppDateVector(SEXP vec);
~RcppDateVector();
- RcppDate& operator()(int i);
+ RcppDate& operator()(int i) const;
int size() const;
private:
RcppDate *v;
Modified: pkg/Rcpp/inst/include/RcppResultSet.h
===================================================================
--- pkg/Rcpp/inst/include/RcppResultSet.h 2010-06-13 19:37:25 UTC (rev 1528)
+++ pkg/Rcpp/inst/include/RcppResultSet.h 2010-06-13 20:47:07 UTC (rev 1529)
@@ -39,10 +39,11 @@
#include <RcppVector.h>
namespace Rcpp {
- SEXP wrap(RcppDate &date);
- SEXP wrap(RcppDatetime &date);
- SEXP wrap(RcppDateVector &datevec);
- SEXP wrap(RcppDatetimeVector &dtvec);
+ // template specialisation for wrap() on the date and datetime classes
+ template <> SEXP wrap<RcppDate>(const RcppDate &date);
+ template <> SEXP wrap<RcppDatetime>(const RcppDatetime &date);
+ template <> SEXP wrap<RcppDateVector>(const RcppDateVector &datevec);
+ template <> SEXP wrap<RcppDatetimeVector>(const RcppDatetimeVector &dtvec);
}
class RcppResultSet {
Modified: pkg/Rcpp/src/RcppDateVector.cpp
===================================================================
--- pkg/Rcpp/src/RcppDateVector.cpp 2010-06-13 19:37:25 UTC (rev 1528)
+++ pkg/Rcpp/src/RcppDateVector.cpp 2010-06-13 20:47:07 UTC (rev 1529)
@@ -39,7 +39,7 @@
delete [] v;
}
-RcppDate& RcppDateVector::operator()(int i) {
+RcppDate& RcppDateVector::operator()(int i) const {
if (i < 0 || i >= length) {
std::ostringstream oss;
oss << "RcppDateVector: subscript out of range: " << i;
Modified: pkg/Rcpp/src/RcppResultSet.cpp
===================================================================
--- pkg/Rcpp/src/RcppResultSet.cpp 2010-06-13 19:37:25 UTC (rev 1528)
+++ pkg/Rcpp/src/RcppResultSet.cpp 2010-06-13 20:47:07 UTC (rev 1529)
@@ -27,7 +27,8 @@
namespace Rcpp {
- SEXP wrap(RcppDate &date) {
+ // template specialisation for wrap() on the date and datetime classes
+ template <> SEXP wrap(const RcppDate &date) {
SEXP value = PROTECT(Rf_allocVector(REALSXP, 1));
REAL(value)[0] = date.getJDN() - RcppDate::Jan1970Offset;
SEXP dateclass = PROTECT(Rf_allocVector(STRSXP,1));
@@ -37,7 +38,7 @@
return value;
}
- SEXP wrap(RcppDatetime &datetime) {
+ template <> SEXP wrap(const RcppDatetime &datetime) {
SEXP value = PROTECT(Rf_allocVector(REALSXP, 1));
REAL(value)[0] = datetime.getFractionalTimestamp();
SEXP datetimeclass = PROTECT(Rf_allocVector(STRSXP,2));
@@ -48,7 +49,7 @@
return value;
}
- SEXP wrap(RcppDateVector& datevec) {
+ template <> SEXP wrap(const RcppDateVector& datevec) {
SEXP value = PROTECT(Rf_allocVector(REALSXP, datevec.size()));
for (int i = 0; i < datevec.size(); i++) {
REAL(value)[i] = datevec(i).getJDN() - RcppDate::Jan1970Offset;
@@ -60,7 +61,7 @@
return value;
}
- SEXP wrap(RcppDatetimeVector &dtvec) {
+ template <> SEXP wrap(const RcppDatetimeVector &dtvec) {
SEXP value = PROTECT(Rf_allocVector(REALSXP, dtvec.size()));
for (int i = 0; i < dtvec.size(); i++) {
REAL(value)[i] = dtvec(i).getFractionalTimestamp();
More information about the Rcpp-commits
mailing list