Rcpp Version 1.1.2
Loading...
Searching...
No Matches
newDateVector.h
Go to the documentation of this file.
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 - 2025 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
27namespace Rcpp {
28
30 public:
34
35 template <int RTYPE, bool NA, typename VEC>
39
40 newDateVector(SEXP vec) : NumericVector(vec) { setClass(); }
42
43 inline std::vector<Date> getDates() const {
44 size_t n = this->size();
45 std::vector<Date> v(n);
46 for (size_t i=0; i<n; i++)
47 v[i] = (*this)[i];
48 return v;
49 }
50
52 if (this != &rhs) {
54 }
55
56 return *this;
57 }
58
59 friend inline std::ostream &operator<<(std::ostream & s, const newDateVector d);
60
61 private:
62
63 void setClass() {
64 Shield<SEXP> dateclass(Rf_mkString("Date"));
65 Rf_setAttrib(*this, R_ClassSymbol, dateclass);
66 }
67 };
68
69 inline std::ostream &operator<<(std::ostream & os, const newDateVector d) {
70 size_t n = d.size();
71 for (size_t i=0; i<n; i++) {
72 os << Date(d[i]).format() << " ";
73 if ((i+1) % 8 == 0) os << "\n";
74 }
75 return os;
76 }
77}
78
79#endif
std::string format(const char *fmt="%Y-%m-%d") const
Definition Date.h:107
R_xlen_t size() const
Definition Vector.h:274
Vector & operator=(const Vector &rhs)
Definition Vector.h:68
newDateVector(const VectorBase< RTYPE, NA, VEC > &vec)
newDateVector & operator=(const newDateVector &rhs)
std::vector< Date > getDates() const
friend std::ostream & operator<<(std::ostream &s, const newDateVector d)
Rcpp API.
Definition algo.h:28
Vector< REALSXP > NumericVector
std::ostream & operator<<(std::ostream &os, const Date d)
Definition Date.h:172