Skip to content

Commit 3c7f0b6

Browse files
committed
first step towards updated Date{time}Vector
1 parent 6f81b46 commit 3c7f0b6

File tree

9 files changed

+152
-4
lines changed

9 files changed

+152
-4
lines changed

ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2016-10-16 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/date_datetime/date_datetime.h: New header file (and
4+
directory) regrouping all Date and Datetime headers, scalar and vector
5+
6+
* inst/include/Rcpp/date_datetime/Date.h: Moved one directory down
7+
* inst/include/Rcpp/date_datetime/Datetime.h: Ditto
8+
* inst/include/Rcpp/date_datetime/oldDateVector.h: Moved and renamed
9+
* inst/include/Rcpp/date_datetime/oldDatetimeVector.h: Ditto
10+
11+
* inst/include/Rcpp/date_datetime/newDateVector.h: New implementation
12+
inheriting from NumericVector, still optional
13+
* inst/include/Rcpp/date_datetime/newDatetimeVector.h: Ditto
14+
115
2016-09-05 Dirk Eddelbuettel <[email protected]>
216

317
* DESCRIPTION (Version): Roll minor version

inst/include/Rcpp.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@
5555
#include <Rcpp/StringTransformer.h>
5656
#include <Rcpp/Formula.h>
5757
#include <Rcpp/DataFrame.h>
58-
#include <Rcpp/Date.h>
59-
#include <Rcpp/DateVector.h>
60-
#include <Rcpp/Datetime.h>
61-
#include <Rcpp/DatetimeVector.h>
58+
59+
#include <Rcpp/date_datetime/date_datetime.h>
6260

6361
#include <Rcpp/Na_Proxy.h>
6462

File renamed without changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2+
//
3+
// date_datetime.h: Rcpp R/C++ interface class library -- Date and Datetime support
4+
//
5+
// Copyright (C) 2016 Dirk Eddelbuettel
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#ifndef Rcpp__Date_Datetime_h
23+
#define Rcpp__Date_Datetime_h
24+
25+
#include <Rcpp/date_datetime/Date.h>
26+
#include <Rcpp/date_datetime/oldDateVector.h>
27+
#include <Rcpp/date_datetime/newDateVector.h>
28+
29+
#include <Rcpp/date_datetime/Datetime.h>
30+
#include <Rcpp/date_datetime/oldDatetimeVector.h>
31+
#include <Rcpp/date_datetime/newDatetimeVector.h>
32+
33+
#endif
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2+
//
3+
// newDateVector.h: Rcpp R/C++ interface class library -- Date vector support
4+
//
5+
// Copyright (C) 2016 Dirk Eddelbuettel
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#ifndef Rcpp__newDateVector_h
23+
#define Rcpp__newDateVector_h
24+
25+
#include <RcppCommon.h>
26+
27+
namespace Rcpp {
28+
29+
class newDateVector : public NumericVector {
30+
public:
31+
newDateVector(SEXP vec) : NumericVector(vec) { setClass(); }
32+
newDateVector(int n) : NumericVector(n) { setClass(); }
33+
34+
inline std::vector<Date> getDates() const {
35+
int n = this->size();
36+
std::vector<Date> v(n);
37+
for (int i=0; i<n; i++)
38+
v[i] = (*this)[i];
39+
return v;
40+
}
41+
42+
private:
43+
44+
void setClass() {
45+
Rf_setAttrib(*this, R_ClassSymbol, Rf_mkString("Date"));
46+
}
47+
};
48+
}
49+
50+
#endif
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2+
//
3+
// newDatetimeVector.h: Rcpp R/C++ interface class library -- Datetime vector support
4+
//
5+
// Copyright (C) 2016 Dirk Eddelbuettel
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#ifndef Rcpp__newDatetimeVector_h
23+
#define Rcpp__newDatetimeVector_h
24+
25+
#include <RcppCommon.h>
26+
27+
namespace Rcpp {
28+
29+
class newDatetimeVector : public NumericVector {
30+
public:
31+
newDatetimeVector(SEXP vec) : NumericVector(vec) { setClass(); }
32+
newDatetimeVector(int n) : NumericVector(n) { setClass(); }
33+
34+
inline std::vector<Datetime> getDatetimes() const {
35+
int n = this->size();
36+
std::vector<Datetime> v(n);
37+
for (int i=0; i<n; i++)
38+
v[i] = (*this)[i];
39+
return v;
40+
}
41+
42+
private:
43+
44+
void setClass() {
45+
Shield<SEXP> datetimeclass(Rf_allocVector(STRSXP,2));
46+
SET_STRING_ELT(datetimeclass, 0, Rf_mkChar("POSIXct"));
47+
SET_STRING_ELT(datetimeclass, 1, Rf_mkChar("POSIXt"));
48+
Rf_setAttrib(*this, R_ClassSymbol, datetimeclass);
49+
}
50+
};
51+
}
52+
53+
#endif
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)