[Rcpp-commits] r1722 - in pkg/Rcpp: inst inst/include inst/include/Rcpp inst/unitTests src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jun 25 05:56:52 CEST 2010
Author: edd
Date: 2010-06-25 05:56:52 +0200 (Fri, 25 Jun 2010)
New Revision: 1722
Added:
pkg/Rcpp/inst/include/Rcpp/Datetime.h
pkg/Rcpp/inst/include/Rcpp/DatetimeVector.h
pkg/Rcpp/inst/include/Rcpp/Datetime_forward.h
pkg/Rcpp/inst/unitTests/runit.Datetime.R
pkg/Rcpp/src/Datetime.cpp
pkg/Rcpp/src/DatetimeVector.cpp
Modified:
pkg/Rcpp/inst/ChangeLog
pkg/Rcpp/inst/include/Rcpp.h
pkg/Rcpp/inst/include/Rcpp/Date_forward.h
pkg/Rcpp/inst/include/RcppCommon.h
pkg/Rcpp/src/Date.cpp
Log:
new classes Datetime and DatetimeVector
new unit test file
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-06-24 18:23:00 UTC (rev 1721)
+++ pkg/Rcpp/inst/ChangeLog 2010-06-25 03:56:52 UTC (rev 1722)
@@ -11,6 +11,14 @@
* src/Date.cpp: Implementation of the above
* inst/unitTests/runit.Date.R: tests for the above
+ * inst/include/Rcpp/Datetime.h: New Datetime class
+ * src/Datetime.cpp: Implementation for new Datetime class
+ * inst/unitTests/runit.Datetime.R: first tests for Rcpp::Datetime
+ * inst/include/Rcpp/Datetime_forward.h: API Integration
+
+ * inst/include/Rcpp/DatetimeVector.h: New DatetimeVector class
+ * src/Datetime.cpp: Implementation for new DatetimeVector class
+
2010-06-23 Dirk Eddelbuettel <edd at debian.org>
* src/Date.cpp: Import mktime00() from R's src/main/datetime.c,
@@ -24,7 +32,7 @@
* inst/include/Rcpp/Date_forward.h: forward declaration of Rcpp::Date and
support for wrap( container of Rcpp::Date ), e.g. wrap( vector<Date> )
-
+
* inst/include/Rcpp/sugar/Range.h: added the concept of range to allow
modification of several elements of a vector.
Modified: pkg/Rcpp/inst/include/Rcpp/Date_forward.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Date_forward.h 2010-06-24 18:23:00 UTC (rev 1721)
+++ pkg/Rcpp/inst/include/Rcpp/Date_forward.h 2010-06-25 03:56:52 UTC (rev 1722)
@@ -1,4 +1,4 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
//
// Date_forward.h: Rcpp R/C++ interface class library --
//
Added: pkg/Rcpp/inst/include/Rcpp/Datetime.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Datetime.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/Datetime.h 2010-06-25 03:56:52 UTC (rev 1722)
@@ -0,0 +1,96 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// Datetime.h: Rcpp R/C++ interface class library -- Datetime (POSIXct)
+//
+// 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/>.
+
+#ifndef Rcpp__Datetime_h
+#define Rcpp__Datetime_h
+
+#include <RcppCommon.h>
+
+namespace Rcpp {
+
+ class Datetime {
+ public:
+ Datetime();
+ Datetime(SEXP s);
+ Datetime(const double &dt); // from double, just like POSIXct
+ Datetime(const std::string &s, const std::string &fmt="%Y-%m-%d %H:%M:%0S");
+ Datetime(const Datetime ©);
+ ~Datetime() {};
+
+ double getFractionalTimestamp(void) const { return m_dt; }
+
+ int getMicroSeconds() const { return m_us; }
+ int getSeconds() const { return m_tm.tm_sec; }
+ int getMinutes() const { return m_tm.tm_min; }
+ int getHours() const { return m_tm.tm_hour; }
+ int getDay() const { return m_tm.tm_mday; }
+ int getMonth() const { return m_tm.tm_mon + 1; } // makes it 1 .. 12
+ int getYear() const { return m_tm.tm_year + 1900; }
+ int getWeekday() const { return m_tm.tm_wday + 1; } // makes it 1 .. 7
+ int getYearday() const { return m_tm.tm_yday + 1; } // makes it 1 .. 366
+
+ Datetime & operator=(const Datetime &newdt); // copy assignment operator
+
+ // Minimal set of date operations.
+ friend Datetime operator+(const Datetime &dt, double offset);
+ friend double operator-(const Datetime& dt1, const Datetime& dt2);
+ friend bool operator<(const Datetime &dt1, const Datetime& dt2);
+ friend bool operator>(const Datetime &dt1, const Datetime& dt2);
+ friend bool operator==(const Datetime &dt1, const Datetime& dt2);
+ friend bool operator>=(const Datetime &dt1, const Datetime& dt2);
+ friend bool operator<=(const Datetime &dt1, const Datetime& dt2);
+ friend bool operator!=(const Datetime &dt1, const Datetime& dt2);
+
+ private:
+ double m_dt; // fractional seconds since epoch
+ struct tm m_tm; // standard time representation
+ unsigned int m_us; // microsecond (to complement m_tm)
+
+ void update_tm(); // update m_tm based on m_dt
+
+ };
+
+
+ // template specialisation for wrap() on datetime
+ template <> SEXP wrap<Rcpp::Datetime>(const Rcpp::Datetime &dt);
+
+ // needed to wrap containers of Date such as vector<Date> or map<string,Date>
+ namespace internal {
+ template<> inline double caster<Rcpp::Datetime,double>( Rcpp::Datetime from){
+ return static_cast<double>( from.getFractionalTimestamp() ) ;
+ }
+ template<> inline Rcpp::Datetime caster<double,Rcpp::Datetime>( double from){
+ return Rcpp::Datetime( static_cast<double>( from ) ) ;
+ }
+ }
+
+ template<> inline SEXP wrap_extra_steps<Rcpp::Datetime>( SEXP x ){
+ SEXP datetimeclass = PROTECT(Rf_allocVector(STRSXP,2));
+ SET_STRING_ELT(datetimeclass, 0, Rf_mkChar("POSIXt"));
+ SET_STRING_ELT(datetimeclass, 1, Rf_mkChar("POSIXct"));
+ Rf_setAttrib(x, R_ClassSymbol, datetimeclass);
+ UNPROTECT(1);
+ return x ;
+ }
+
+}
+
+#endif
Added: pkg/Rcpp/inst/include/Rcpp/DatetimeVector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/DatetimeVector.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/DatetimeVector.h 2010-06-25 03:56:52 UTC (rev 1722)
@@ -0,0 +1,62 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// DatetimeVector.h: Rcpp R/C++ interface class library -- Datetime vector
+//
+// 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/>.
+
+#ifndef Rcpp__DatetimeVector_h
+#define Rcpp__DatetimeVector_h
+
+#include <RcppCommon.h>
+
+namespace Rcpp {
+
+ class DatetimeVector {
+ public:
+ typedef std::vector<Datetime>::iterator iterator;
+ typedef std::vector<Datetime>::const_iterator const_iterator;
+
+ // TODO: use a custom exception class instead of std::range_error
+ DatetimeVector(SEXP vec) throw(std::range_error);
+ 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[](unsigned int i) const;
+ Datetime& operator[](unsigned int i);
+
+ int size() const;
+
+ std::vector<Datetime> getDatetimes() const;
+
+ inline iterator begin(){ return v.begin(); }
+ inline iterator end(){ return v.end(); }
+
+ inline const_iterator begin() const { return v.begin(); }
+ inline const_iterator end() const { return v.end(); }
+
+ inline operator SEXP() const { return wrap( v ) ; }
+
+ private:
+ std::vector<Datetime> v;
+ };
+}
+
+#endif
Added: pkg/Rcpp/inst/include/Rcpp/Datetime_forward.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Datetime_forward.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/Datetime_forward.h 2010-06-25 03:56:52 UTC (rev 1722)
@@ -0,0 +1,49 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// Datetime_forward.h: Rcpp R/C++ interface class library --
+//
+// 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/>.
+
+#ifndef Rcpp__Datetime_forward_h
+#define Rcpp__Datetime_forward_h
+
+namespace Rcpp {
+ class Datetime ;
+ namespace traits{
+ template <> struct wrap_type_traits<Rcpp::Datetime>{
+ typedef wrap_type_primitive_tag wrap_category;
+ } ;
+ template<> struct r_type_traits<Rcpp::Datetime>{
+ typedef r_type_primitive_tag r_category ;
+ } ;
+ template<> struct r_type_traits< std::pair<const std::string,Rcpp::Datetime> >{
+ typedef r_type_primitive_tag r_category ;
+ } ;
+ template<> struct r_sexptype_traits<Rcpp::Datetime>{
+ enum{ rtype = REALSXP } ;
+ } ;
+ }
+
+ template<> SEXP wrap_extra_steps<Rcpp::Datetime>( SEXP ) ;
+ namespace internal{
+ template<> double caster<Rcpp::Datetime,double>( Rcpp::Datetime from) ;
+ template<> Rcpp::Datetime caster<double,Rcpp::Datetime>( double from) ;
+ }
+}
+
+#endif
Modified: pkg/Rcpp/inst/include/Rcpp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp.h 2010-06-24 18:23:00 UTC (rev 1721)
+++ pkg/Rcpp/inst/include/Rcpp.h 2010-06-25 03:56:52 UTC (rev 1722)
@@ -70,6 +70,8 @@
#include <Rcpp/DataFrame.h>
#include <Rcpp/Date.h>
#include <Rcpp/DateVector.h>
+#include <Rcpp/Datetime.h>
+#include <Rcpp/DatetimeVector.h>
#ifdef RCPP_ENABLE_MODULES
#include <Rcpp/Module.h>
Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h 2010-06-24 18:23:00 UTC (rev 1721)
+++ pkg/Rcpp/inst/include/RcppCommon.h 2010-06-25 03:56:52 UTC (rev 1722)
@@ -243,6 +243,7 @@
#include <Rcpp/internal/wrap_forward.h>
#include <Rcpp/Date_forward.h>
+#include <Rcpp/Datetime_forward.h>
#include <Rcpp/internal/export.h>
#include <Rcpp/traits/Exporter.h>
Added: pkg/Rcpp/inst/unitTests/runit.Datetime.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Datetime.R (rev 0)
+++ pkg/Rcpp/inst/unitTests/runit.Datetime.R 2010-06-25 03:56:52 UTC (rev 1722)
@@ -0,0 +1,61 @@
+#!/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.Datetime.get.functions <- function() {
+ src <- 'Datetime dt = Datetime(x);
+ return List::create(Named("year") = dt.getYear(),
+ Named("month") = dt.getMonth(),
+ Named("day") = dt.getDay(),
+ Named("wday") = dt.getWeekday(),
+ Named("hour") = dt.getHours(),
+ Named("minute") = dt.getMinutes(),
+ Named("second") = dt.getSeconds(),
+ Named("microsec") = dt.getMicroSeconds());'
+ fun <- cxxfunction(signature(x="Datetime"), src, plugin="Rcpp")
+ checkEquals(fun(as.numeric(as.POSIXct("2001-02-03 01:02:03.123456", tz="UTC"))),
+ list(year=2001, month=2, day=3, wday=7, hour=1, minute=2, second=3, microsec=123456),
+ msg = "Date.get.functions")
+}
+
+test.Datetime.operators <- function() {
+ src <- 'Datetime d1 = Datetime(946774923.123456);
+ Datetime d2 = d1 + 60*60;
+ return List::create(Named("diff") = d2 - d1,
+ Named("bigger") = d2 > d1,
+ Named("smaller") = d2 < d1,
+ Named("equal") = d2 == d1,
+ Named("ge") = d2 >= d1,
+ Named("le") = d2 <= d1,
+ Named("ne") = d2 != d1);'
+ fun <- cxxfunction(signature(), src, plugin="Rcpp")
+ checkEquals(fun(),
+ list(diff=-60*60, bigger=TRUE, smaller=FALSE, equal=FALSE, ge=TRUE, le=FALSE, ne=TRUE),
+ msg = "Datetime.operators")
+}
+
+
+# commented out for now : fails in europe
+test.RcppDatetime.wrap <- function() {
+ src <- 'Datetime dt = Datetime(981162123.123456);
+ return wrap(dt);';
+ fun <- cxxfunction(signature(), src, plugin = "Rcpp" )
+ checkEquals(as.numeric(fun()), as.numeric(as.POSIXct("2001-02-03 01:02:03.123456", tz="UTC")),
+ msg = "Datetime.wrap")
+}
+
Modified: pkg/Rcpp/src/Date.cpp
===================================================================
--- pkg/Rcpp/src/Date.cpp 2010-06-24 18:23:00 UTC (rev 1721)
+++ pkg/Rcpp/src/Date.cpp 2010-06-25 03:56:52 UTC (rev 1722)
@@ -46,7 +46,7 @@
Date::Date(const std::string &s, const std::string &fmt) {
Rcpp::Function strptime("strptime"); // we cheat and call strptime() from R
- m_d = Rcpp::as<int>(strptime(s, fmt));
+ m_d = Rcpp::as<int>(strptime(s, fmt, "UTC"));
update_tm();
}
@@ -132,6 +132,8 @@
Date operator+(const Date &date, int offset) {
Date newdate(date.m_d);
newdate.m_d += offset;
+ time_t t = 24*60*60 * newdate.m_d; // days since epoch to seconds since epo
+ newdate.m_tm = *gmtime(&t); // this may need a Windows fix, re-check R's datetime.c
return newdate;
}
Added: pkg/Rcpp/src/Datetime.cpp
===================================================================
--- pkg/Rcpp/src/Datetime.cpp (rev 0)
+++ pkg/Rcpp/src/Datetime.cpp 2010-06-25 03:56:52 UTC (rev 1722)
@@ -0,0 +1,102 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// Datetime.h: Rcpp R/C++ interface class library -- Datetime (POSIXct)
+//
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+//
+// The mktime00() function is
+// Copyright (C) 2000 - 2010 The R Development Core Team.
+//
+// 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/>.
+
+#include <Rcpp/Datetime.h>
+#include <Rcpp/Function.h>
+#include <Rmath.h> // for Rf_fround
+
+namespace Rcpp {
+
+ Datetime::Datetime() {
+ m_dt = 0;
+ update_tm();
+ }
+
+ Datetime::Datetime(SEXP d) {
+ m_dt = Rcpp::as<double>(d);
+ update_tm();
+ }
+
+ Datetime::Datetime(const double &dt) {
+ m_dt = dt;
+ update_tm();
+ }
+
+ Datetime::Datetime(const std::string &s, const std::string &fmt) {
+ Rcpp::Function strptime("strptime"); // we cheat and call strptime() from R
+ m_dt = Rcpp::as<double>(strptime(s, fmt));
+ update_tm();
+ }
+
+ Datetime::Datetime(const Datetime ©) {
+ m_dt = copy.m_dt;
+ m_us = copy.m_us;
+ m_tm = copy.m_tm;
+ }
+
+ Datetime & Datetime::operator=(const Datetime & newdt) {
+ if (this != &newdt) {
+ m_dt = newdt.m_dt;
+ m_us = newdt.m_us;
+ m_tm = newdt.m_tm;
+ }
+ return *this;
+ }
+
+ void Datetime::update_tm() {
+ time_t t = static_cast<time_t>(floor(m_dt));
+ m_tm = *gmtime(&t); // this may need a Windows fix, re-check R's datetime.c
+ // m_us is fractional (micro)secs as diff. between (fractional) m_dt and m_tm
+ m_us = static_cast<int>(::Rf_fround( (m_dt - t) * 1.0e6, 0.0));
+ }
+
+ Datetime operator+(const Datetime &datetime, double offset) {
+ Datetime newdt(datetime.m_dt);
+ newdt.m_dt += offset;
+ time_t t = static_cast<time_t>(floor(newdt.m_dt));
+ newdt.m_tm = *gmtime(&t); // this may need a Windows fix, re-check R's dat
+ newdt.m_us = static_cast<int>(::Rf_fround( (newdt.m_dt - t) * 1.0e6, 0.0));
+ return newdt;
+ }
+
+ double operator-(const Datetime& d1, const Datetime& d2) { return d2.m_dt - d1.m_dt; }
+ bool operator<(const Datetime &d1, const Datetime& d2) { return d1.m_dt < d2.m_dt; }
+ bool operator>(const Datetime &d1, const Datetime& d2) { return d1.m_dt > d2.m_dt; }
+ bool operator==(const Datetime &d1, const Datetime& d2) { return d1.m_dt == d2.m_dt; }
+ bool operator>=(const Datetime &d1, const Datetime& d2) { return d1.m_dt >= d2.m_dt; }
+ bool operator<=(const Datetime &d1, const Datetime& d2) { return d1.m_dt <= d2.m_dt; }
+ bool operator!=(const Datetime &d1, const Datetime& d2) { return d1.m_dt != d2.m_dt; }
+
+ template <> SEXP wrap(const Datetime &date) {
+ SEXP value = PROTECT(Rf_allocVector(REALSXP, 1));
+ REAL(value)[0] = date.getFractionalTimestamp();
+ SEXP datetimeclass = PROTECT(Rf_allocVector(STRSXP,2));
+ SET_STRING_ELT(datetimeclass, 0, Rf_mkChar("POSIXt"));
+ SET_STRING_ELT(datetimeclass, 1, Rf_mkChar("POSIXct"));
+ Rf_setAttrib(value, R_ClassSymbol, datetimeclass);
+ UNPROTECT(2);
+ return value;
+ }
+
+}
Added: pkg/Rcpp/src/DatetimeVector.cpp
===================================================================
--- pkg/Rcpp/src/DatetimeVector.cpp (rev 0)
+++ pkg/Rcpp/src/DatetimeVector.cpp 2010-06-25 03:56:52 UTC (rev 1722)
@@ -0,0 +1,76 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// DatetimeVector.cpp: Rcpp R/C++ interface class library -- Datetime vector
+//
+// 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/>.
+
+#include <Rcpp/DatetimeVector.h>
+#include <Rcpp/Datetime.h>
+
+namespace Rcpp {
+
+ DatetimeVector::DatetimeVector(SEXP vec) throw(std::range_error) : v() {
+ int i;
+ if (!Rf_isNumeric(vec) || Rf_isMatrix(vec) || Rf_isLogical(vec))
+ throw std::range_error("DatetimeVector: invalid numeric vector in constructor");
+ int len = Rf_length(vec);
+ if (len == 0)
+ throw std::range_error("DatetimeVector: null vector in constructor");
+ v.resize(len);
+ for (i = 0; i < len; i++)
+ v[i] = Datetime( static_cast<double>(REAL(vec)[i]));
+ }
+
+
+ DatetimeVector::DatetimeVector(int n) : v(n) {}
+
+ const Datetime & DatetimeVector::operator()(unsigned int i) const throw(std::range_error) {
+ if (i >= 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) throw(std::range_error) {
+ if (i >= v.size()) {
+ std::ostringstream oss;
+ oss << "DatetimeVector: subscript out of range: " << i;
+ throw std::range_error(oss.str());
+ }
+ return v[i];
+ }
+
+ const Datetime & DatetimeVector::operator[](unsigned int i) const {
+ return v[i];
+ }
+
+ Datetime & DatetimeVector::operator[](unsigned int i) {
+ return v[i];
+ }
+
+ int DatetimeVector::size() const {
+ return v.size();
+ }
+
+ std::vector<Datetime> DatetimeVector::getDatetimes() const {
+ return v;
+ }
+
+}
More information about the Rcpp-commits
mailing list