[Rcpp-commits] r3811 - in pkg/RcppBDT: . inst/include src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Oct 23 05:01:13 CEST 2012
Author: edd
Date: 2012-10-23 05:01:13 +0200 (Tue, 23 Oct 2012)
New Revision: 3811
Added:
pkg/RcppBDT/inst/include/RcppBDTdt.h
pkg/RcppBDT/inst/include/RcppBDTtz.h
Modified:
pkg/RcppBDT/ChangeLog
pkg/RcppBDT/inst/include/RcppBDT.h
pkg/RcppBDT/inst/include/RcppBDTdu.h
pkg/RcppBDT/inst/include/RcppBDTpt.h
pkg/RcppBDT/src/RcppBDTdt.cpp
pkg/RcppBDT/src/RcppBDTtz.cpp
Log:
more header file rearrangements
Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog 2012-10-23 02:47:04 UTC (rev 3810)
+++ pkg/RcppBDT/ChangeLog 2012-10-23 03:01:13 UTC (rev 3811)
@@ -1,15 +1,19 @@
2012-10-22 Dirk Eddelbuettel <edd at debian.org>
+ * inst/include/RcppBDTdt.h:
+
* src/RcppBDTpt.cpp: Comparison and arithmethic support for posix time
* R/zzz.R: associated S4 methods
- * inst/include/RcppBDTpt.h: Put declaration for posix time class here
- * inst/include/RcppBDTdu.h: Put declaration for duration class here
+ * inst/include/RcppBDTdt.h: New file for declaration of time zone class
+ * inst/include/RcppBDTpt.h: New file for declaration of posix time class
+ * inst/include/RcppBDTdu.h: New file for declaration of duration class
+ * inst/include/RcppBDTtz.h: New file for declaration of time zone class
2012-10-22 Romain Francois <romain at r-enthusiasts.com>
- * src/RcppBDTdu.cpp: implementing functions hours, minutes, ... and operators
- +,-(du, du) *,/(du,int)
+ * src/RcppBDTdu.cpp: implementing functions hours, minutes, ... and
+ operators +,-(du, du) *,/(du,int)
* R/zzz.R: associated S4 methods
2012-10-21 Dirk Eddelbuettel <edd at debian.org>
Modified: pkg/RcppBDT/inst/include/RcppBDT.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDT.h 2012-10-23 02:47:04 UTC (rev 3810)
+++ pkg/RcppBDT/inst/include/RcppBDT.h 2012-10-23 03:01:13 UTC (rev 3811)
@@ -70,7 +70,9 @@
#include <Rcpp.h>
+#include <RcppBDTdt.h>
#include <RcppBDTpt.h>
#include <RcppBDTdu.h>
+#include <RcppBDTtz.h>
#endif
Added: pkg/RcppBDT/inst/include/RcppBDTdt.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTdt.h (rev 0)
+++ pkg/RcppBDT/inst/include/RcppBDTdt.h 2012-10-23 03:01:13 UTC (rev 3811)
@@ -0,0 +1,82 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// RcppBDTdt.h: Rcpp and Boost Date_Time date class
+//
+// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of RcppBDT.
+//
+// RcppBDT 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.
+//
+// RcppBDT 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 RcppBDT. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef RCPPBDT__RCPPBDTDT_H
+#define RCPPBDT__RCPPBDTDT_H
+
+class bdtDt {
+
+public:
+ bdtDt() { setFromLocalClock(); } // default empty constructor, using epoch
+ bdtDt(SEXP dt) { setDate(dt); } // constructor from SEXP using R Date
+ bdtDt(int year, int month, int day) : m_dt(year, month, day) { } // constructor using year, month, day
+
+ // these set the date from the clock, in local or universal time
+ void setFromLocalClock() { m_dt = boost::gregorian::date(boost::gregorian::day_clock::local_day()); }
+ void setFromUTCClock() { m_dt = boost::gregorian::date(boost::gregorian::day_clock::universal_day()); }
+ Rcpp::Date getLocalDay() { return Rcpp::wrap(boost::gregorian::date(boost::gregorian::day_clock::local_day())); }
+ Rcpp::Date getUTCDay() { return Rcpp::wrap(boost::gregorian::date(boost::gregorian::day_clock::universal_day())); }
+
+ // these extract the requested date portion or representation as an integer
+ int getYear() { return static_cast<int>( m_dt.year() ); }
+ int getMonth() { return static_cast<int>( m_dt.month() ); }
+ int getDay() { return static_cast<int>( m_dt.day() ); }
+ int getDayOfWeek() { return static_cast<int>( m_dt.day_of_week() ); }
+ int getDayOfYear() { return static_cast<int>( m_dt.day_of_year() ); }
+
+ void setDate(SEXP dt) { m_dt = Rcpp::as<boost::gregorian::date>(dt); }
+ void fromDate(SEXP dt) { m_dt = Rcpp::as<boost::gregorian::date>(dt); Rf_warning("'fromDate' is deprecated, use 'setDate'"); }
+ Rcpp::Date getDate() { return Rcpp::wrap(m_dt); }
+
+ int getWeekNumber() { return m_dt.week_number(); }
+ long getModJulian() { return m_dt.week_number(); }
+ long getJulian() { return m_dt.week_number(); }
+
+ // construct end-of-month and first-of-next-monthm returning a boost::gregorian::date object
+ void setEndOfMonth() { m_dt = m_dt.end_of_month(); }
+ boost::gregorian::date getEndOfMonth() {
+ return m_dt.end_of_month(); }
+ void setFirstOfNextMonth() { m_dt = m_dt.end_of_month() + boost::gregorian::days(1); }
+ boost::gregorian::date getFirstOfNextMonth() {
+ return m_dt.end_of_month() + boost::gregorian::days(1); }
+
+ void setEndOfBizWeek() {
+ m_dt += boost::gregorian::days_until_weekday(m_dt, boost::gregorian::greg_weekday(boost::gregorian::Friday));
+ }
+ Rcpp::Date getEndOfBizWeek() {
+ return Rcpp::wrap( m_dt += boost::gregorian::days_until_weekday(m_dt, boost::gregorian::greg_weekday(boost::gregorian::Friday) ));
+ }
+
+ void addDays(unsigned int len) { m_dt += boost::gregorian::date_duration(len); }
+ void subtractDays(unsigned int len) { m_dt -= boost::gregorian::date_duration(len); }
+
+ // with thanks to Whit Armstong for doing this in his rboostdatetime
+ void setIMMDate(int mon, int year) {
+ m_dt = boost::gregorian::nth_day_of_the_week_in_month(boost::gregorian::nth_day_of_the_week_in_month::third,
+ boost::gregorian::Wednesday, mon).get_date(year);
+ }
+
+private:
+ boost::gregorian::date m_dt; // private Boost date instance
+
+};
+
+#endif
Modified: pkg/RcppBDT/inst/include/RcppBDTdu.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTdu.h 2012-10-23 02:47:04 UTC (rev 3810)
+++ pkg/RcppBDT/inst/include/RcppBDTdu.h 2012-10-23 03:01:13 UTC (rev 3811)
@@ -2,7 +2,7 @@
//
// RcppBDTdu.h: Rcpp and Boost Date_Time duration class
//
-// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
//
// This file is part of RcppBDT.
//
Modified: pkg/RcppBDT/inst/include/RcppBDTpt.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTpt.h 2012-10-23 02:47:04 UTC (rev 3810)
+++ pkg/RcppBDT/inst/include/RcppBDTpt.h 2012-10-23 03:01:13 UTC (rev 3811)
@@ -2,7 +2,7 @@
//
// RcppBDTdu.h: Rcpp and Boost Date_Time posix time class
//
-// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
//
// This file is part of RcppBDT.
//
Added: pkg/RcppBDT/inst/include/RcppBDTtz.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTtz.h (rev 0)
+++ pkg/RcppBDT/inst/include/RcppBDTtz.h 2012-10-23 03:01:13 UTC (rev 3811)
@@ -0,0 +1,97 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// RcppBDTtz.h: Rcpp and Boost Date_Time time zone class
+//
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of RcppBDT.
+//
+// RcppBDT 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.
+//
+// RcppBDT 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 RcppBDT. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef RCPPBDT__RCPPBDTTZ_H
+#define RCPPBDT__RCPPBDTTZ_H
+
+class bdtTz {
+
+public:
+
+ bdtTz(std::string region) : m_tzone(region) {
+ // nice little trick: evaluate a Language() object corresponding to the R call
+ // system.file("data", "date_time_zonespec.csv", package="RcppBDT")
+ // but from C++
+ Rcpp::Language ll = Rcpp::Language("system.file", "extdata", "date_time_zonespec.csv",
+ Rcpp::Named("package","RcppBDT"));
+ std::string zonefile = Rcpp::as<std::string>(ll.eval(R_GlobalEnv));
+ m_tz.load_from_file(zonefile); // load db from csv zonefile
+ m_tzp = m_tz.time_zone_from_region(region); // init with given region
+ if (m_tzp == NULL)
+ ::Rf_error("Unknown region supplied, no tz object created");
+ }
+
+ std::vector<std::string> getAllRegions() { return( m_tz.region_list() ); }
+
+ long getUtcTotalSec() {
+ boost::posix_time::time_duration tdt = m_tzp->base_utc_offset();
+ return(tdt.total_seconds());
+ }
+
+ long getDstTotalSec() {
+ boost::posix_time::time_duration tdt = m_tzp->dst_offset();
+ return(tdt.total_seconds());
+ }
+
+ std::string getDstZoneAbbrev() { return(m_tzp->dst_zone_abbrev()); }
+ std::string getStdZoneAbbrev() { return(m_tzp->std_zone_abbrev()); }
+ std::string getDstZoneName() { return(m_tzp->dst_zone_name()); }
+ std::string getStdZoneName() { return(m_tzp->std_zone_name()); }
+ std::string getRegion() { return(m_tzone); }
+ bool hasDst() { return(m_tzp->has_dst()); }
+ std::string getPosixString() { return(m_tzp->to_posix_string()); }
+
+ // we (currently ?) cannot return Rcpp::Datetime with a tzone attribute, though returning a SEXP works
+ // SEXP getDstStart(const int year) {
+ // boost::posix_time::ptime t = m_tzp->dst_local_start_time(year);
+ // boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
+ // boost::posix_time::time_duration::sec_type x = // need to correct difference to epoch by UTC offset
+ // (t - epoch - m_tzp->base_utc_offset()).total_seconds();
+ // Rcpp::RObject dt = Rcpp::wrap(Rcpp::Datetime(x));
+ // dt.attr("tzone") = m_tzone;
+ // return dt;
+ // }
+ Rcpp::Datetime getDstLocalStart(const int year) {
+ return Rcpp::wrap( m_tzp->dst_local_start_time(year) ); // uses posix_time::ptime wrap()
+ }
+ // SEXP getDstEnd(const int year) {
+ // boost::posix_time::ptime t = m_tzp->dst_local_end_time(year);
+ // boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
+ // boost::posix_time::time_duration::sec_type x = // need to correct difference to epoch by UTC offset
+ // (t - epoch - m_tzp->base_utc_offset()).total_seconds();
+ // Rcpp::RObject dt = Rcpp::wrap(Rcpp::Datetime(x));
+ // dt.attr("tzone") = m_tzone;
+ // return dt;
+ // }
+ Rcpp::Datetime getDstLocalEnd(const int year) {
+ return Rcpp::wrap(m_tzp->dst_local_end_time(year)); // uses posix_time::ptime wrap()
+ }
+
+private:
+
+ bdtTz() {}; // hide default constructor
+ std::string m_tzone;
+
+ boost::local_time::tz_database m_tz;
+ boost::local_time::time_zone_ptr m_tzp;
+};
+
+#endif
Modified: pkg/RcppBDT/src/RcppBDTdt.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTdt.cpp 2012-10-23 02:47:04 UTC (rev 3810)
+++ pkg/RcppBDT/src/RcppBDTdt.cpp 2012-10-23 03:01:13 UTC (rev 3811)
@@ -34,63 +34,6 @@
}
}
-class bdtDt {
-
-public:
- bdtDt() { setFromLocalClock(); } // default empty constructor, using epoch
- bdtDt(SEXP dt) { setDate(dt); } // constructor from SEXP using R Date
- bdtDt(int year, int month, int day) : m_dt(year, month, day) { } // constructor using year, month, day
-
- // these set the date from the clock, in local or universal time
- void setFromLocalClock() { m_dt = boost::gregorian::date(boost::gregorian::day_clock::local_day()); }
- void setFromUTCClock() { m_dt = boost::gregorian::date(boost::gregorian::day_clock::universal_day()); }
- Rcpp::Date getLocalDay() { return Rcpp::wrap(boost::gregorian::date(boost::gregorian::day_clock::local_day())); }
- Rcpp::Date getUTCDay() { return Rcpp::wrap(boost::gregorian::date(boost::gregorian::day_clock::universal_day())); }
-
- // these extract the requested date portion or representation as an integer
- int getYear() { return static_cast<int>( m_dt.year() ); }
- int getMonth() { return static_cast<int>( m_dt.month() ); }
- int getDay() { return static_cast<int>( m_dt.day() ); }
- int getDayOfWeek() { return static_cast<int>( m_dt.day_of_week() ); }
- int getDayOfYear() { return static_cast<int>( m_dt.day_of_year() ); }
-
- void setDate(SEXP dt) { m_dt = Rcpp::as<boost::gregorian::date>(dt); }
- void fromDate(SEXP dt) { m_dt = Rcpp::as<boost::gregorian::date>(dt); Rf_warning("'fromDate' is deprecated, use 'setDate'"); }
- Rcpp::Date getDate() { return Rcpp::wrap(m_dt); }
-
- int getWeekNumber() { return m_dt.week_number(); }
- long getModJulian() { return m_dt.week_number(); }
- long getJulian() { return m_dt.week_number(); }
-
- // construct end-of-month and first-of-next-monthm returning a boost::gregorian::date object
- void setEndOfMonth() { m_dt = m_dt.end_of_month(); }
- boost::gregorian::date getEndOfMonth() {
- return m_dt.end_of_month(); }
- void setFirstOfNextMonth() { m_dt = m_dt.end_of_month() + boost::gregorian::days(1); }
- boost::gregorian::date getFirstOfNextMonth() {
- return m_dt.end_of_month() + boost::gregorian::days(1); }
-
- void setEndOfBizWeek() {
- m_dt += boost::gregorian::days_until_weekday(m_dt, boost::gregorian::greg_weekday(boost::gregorian::Friday));
- }
- Rcpp::Date getEndOfBizWeek() {
- return Rcpp::wrap( m_dt += boost::gregorian::days_until_weekday(m_dt, boost::gregorian::greg_weekday(boost::gregorian::Friday) ));
- }
-
- void addDays(unsigned int len) { m_dt += boost::gregorian::date_duration(len); }
- void subtractDays(unsigned int len) { m_dt -= boost::gregorian::date_duration(len); }
-
- // with thanks to Whit Armstong for doing this in his rboostdatetime
- void setIMMDate(int mon, int year) {
- m_dt = boost::gregorian::nth_day_of_the_week_in_month(boost::gregorian::nth_day_of_the_week_in_month::third,
- boost::gregorian::Wednesday, mon).get_date(year);
- }
-
-private:
- boost::gregorian::date m_dt; // private Boost date instance
-
-};
-
Rcpp::Date getIMMDate(bdtDt *d, int mon, int year) { // does not use bdtDt pointer, but need for RCPP_MODULE use
return Rcpp::wrap( boost::gregorian::nth_day_of_the_week_in_month(boost::gregorian::nth_day_of_the_week_in_month::third,
boost::gregorian::Wednesday, mon).get_date(year) );
Modified: pkg/RcppBDT/src/RcppBDTtz.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTtz.cpp 2012-10-23 02:47:04 UTC (rev 3810)
+++ pkg/RcppBDT/src/RcppBDTtz.cpp 2012-10-23 03:01:13 UTC (rev 3811)
@@ -21,79 +21,6 @@
#include <RcppBDT.h>
-class bdtTz {
-
-public:
-
- bdtTz(std::string region) : m_tzone(region) {
- // nice little trick: evaluate a Language() object corresponding to the R call
- // system.file("data", "date_time_zonespec.csv", package="RcppBDT")
- // but from C++
- Rcpp::Language ll = Rcpp::Language("system.file", "extdata", "date_time_zonespec.csv",
- Rcpp::Named("package","RcppBDT"));
- std::string zonefile = Rcpp::as<std::string>(ll.eval(R_GlobalEnv));
- m_tz.load_from_file(zonefile); // load db from csv zonefile
- m_tzp = m_tz.time_zone_from_region(region); // init with given region
- if (m_tzp == NULL)
- ::Rf_error("Unknown region supplied, no tz object created");
- }
-
- std::vector<std::string> getAllRegions() { return( m_tz.region_list() ); }
-
- long getUtcTotalSec() {
- boost::posix_time::time_duration tdt = m_tzp->base_utc_offset();
- return(tdt.total_seconds());
- }
-
- long getDstTotalSec() {
- boost::posix_time::time_duration tdt = m_tzp->dst_offset();
- return(tdt.total_seconds());
- }
-
- std::string getDstZoneAbbrev() { return(m_tzp->dst_zone_abbrev()); }
- std::string getStdZoneAbbrev() { return(m_tzp->std_zone_abbrev()); }
- std::string getDstZoneName() { return(m_tzp->dst_zone_name()); }
- std::string getStdZoneName() { return(m_tzp->std_zone_name()); }
- std::string getRegion() { return(m_tzone); }
- bool hasDst() { return(m_tzp->has_dst()); }
- std::string getPosixString() { return(m_tzp->to_posix_string()); }
-
- // we (currently ?) cannot return Rcpp::Datetime with a tzone attribute, though returning a SEXP works
- // SEXP getDstStart(const int year) {
- // boost::posix_time::ptime t = m_tzp->dst_local_start_time(year);
- // boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
- // boost::posix_time::time_duration::sec_type x = // need to correct difference to epoch by UTC offset
- // (t - epoch - m_tzp->base_utc_offset()).total_seconds();
- // Rcpp::RObject dt = Rcpp::wrap(Rcpp::Datetime(x));
- // dt.attr("tzone") = m_tzone;
- // return dt;
- // }
- Rcpp::Datetime getDstLocalStart(const int year) {
- return Rcpp::wrap( m_tzp->dst_local_start_time(year) ); // uses posix_time::ptime wrap()
- }
- // SEXP getDstEnd(const int year) {
- // boost::posix_time::ptime t = m_tzp->dst_local_end_time(year);
- // boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
- // boost::posix_time::time_duration::sec_type x = // need to correct difference to epoch by UTC offset
- // (t - epoch - m_tzp->base_utc_offset()).total_seconds();
- // Rcpp::RObject dt = Rcpp::wrap(Rcpp::Datetime(x));
- // dt.attr("tzone") = m_tzone;
- // return dt;
- // }
- Rcpp::Datetime getDstLocalEnd(const int year) {
- return Rcpp::wrap(m_tzp->dst_local_end_time(year)); // uses posix_time::ptime wrap()
- }
-
-private:
-
- bdtTz() {}; // hide default constructor
- std::string m_tzone;
-
- boost::local_time::tz_database m_tz;
- boost::local_time::time_zone_ptr m_tzp;
-};
-
-
RCPP_MODULE(bdtTzMod) {
Rcpp::class_<bdtTz>("bdtTz")
More information about the Rcpp-commits
mailing list