[Rcpp-commits] r3810 - in pkg/RcppBDT: . inst/include src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 23 04:47:04 CEST 2012


Author: edd
Date: 2012-10-23 04:47:04 +0200 (Tue, 23 Oct 2012)
New Revision: 3810

Added:
   pkg/RcppBDT/inst/include/RcppBDTdu.h
   pkg/RcppBDT/inst/include/RcppBDTpt.h
Modified:
   pkg/RcppBDT/ChangeLog
   pkg/RcppBDT/inst/include/RcppBDT.h
   pkg/RcppBDT/src/RcppBDTdu.cpp
Log:
split duration and posix time class definitions off into their own header


Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog	2012-10-23 00:56:15 UTC (rev 3809)
+++ pkg/RcppBDT/ChangeLog	2012-10-23 02:47:04 UTC (rev 3810)
@@ -3,6 +3,9 @@
 	* 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
+
 2012-10-22  Romain Francois  <romain at r-enthusiasts.com>
 
 	* src/RcppBDTdu.cpp: implementing functions hours, minutes, ... and operators

Modified: pkg/RcppBDT/inst/include/RcppBDT.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDT.h	2012-10-23 00:56:15 UTC (rev 3809)
+++ pkg/RcppBDT/inst/include/RcppBDT.h	2012-10-23 02:47:04 UTC (rev 3810)
@@ -65,99 +65,12 @@
     //
     // non-intrusive extension via template specialisation
     template <> SEXP wrap(const boost::posix_time::ptime &dt);
+
 }
 
 #include <Rcpp.h>
 
+#include <RcppBDTpt.h>
+#include <RcppBDTdu.h>
 
-class bdtDu;
-
-class bdtPt {
-
-public:
-    bdtPt() 				  { setFromLocalTimeInMicroSeconds(); }  	// default empty constructor 
-    bdtPt(SEXP dt) 			  { setFromDatetime(dt); }     			// constructor from R's / Rcpp's Datetime
-    bdtPt(double dt) 			  { setFromDouble(dt); }     			// constructor from double using Rcpp's Datetime
-    bdtPt(int year, int month, int day, 			// constructor from date and duration
-          int hours, int minutes, int seconds, 
-          int fractionalseconds) : m_pt(boost::gregorian::date(year, month, day), 
-                                        boost::posix_time::time_duration(hours, minutes, seconds, fractionalseconds)) { }
-    bdtPt(boost::posix_time::ptime pt) : m_pt(pt) {} 
-    bdtPt(const bdtPt& other) : m_pt(other.m_pt ) {}
-    
-    void setFromLocalTimeInSeconds()      { m_pt = boost::posix_time::second_clock::local_time(); }
-    void setFromUTCInSeconds()            { m_pt = boost::posix_time::second_clock::universal_time(); }
-    void setFromLocalTimeInMicroSeconds() { m_pt = boost::posix_time::microsec_clock::local_time(); }
-    void setFromUTCInMicroSeconds()       { m_pt = boost::posix_time::microsec_clock::universal_time(); }
-                                    
-    void setFromTimeT(const time_t t)     { m_pt = boost::posix_time::from_time_t(t); }
-
-    void setFromDatetime(const SEXP dt)   { m_pt = Rcpp::as<boost::posix_time::ptime>(dt); }
-    void setFromDouble(const double d)   { 
-        Rcpp::Datetime dt(d);
-        m_pt = boost::posix_time::ptime(boost::gregorian::date(dt.getYear(), dt.getMonth(), dt.getDay()), 
-                                        boost::posix_time::time_duration(dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMicroSeconds()/1000.0));
-    }
-
-    Rcpp::Datetime getDatetime() 	  { return Rcpp::wrap(m_pt); }
-
-    Rcpp::Date getDate() { 
-        boost::gregorian::date::ymd_type ymd = m_pt.date().year_month_day();     // convert to date and then to y/m/d struct
-        return Rcpp::Date( ymd.year, ymd.month, ymd.day );
-    }
-
-    void addHours(int h)        	  { m_pt += boost::posix_time::time_duration(h, 0, 0, 0); }
-    void addMinutes(int m)        	  { m_pt += boost::posix_time::time_duration(0, m, 0, 0); }
-    void addSeconds(int s)        	  { m_pt += boost::posix_time::time_duration(0, 0, s, 0); }
-    void addFractionalSeconds(int fs)     { m_pt += boost::posix_time::time_duration(0, 0, 0, fs); }
-
-private:
-    boost::posix_time::ptime m_pt; 		// private ptime instace
-
-    friend Rcpp::object<bdtPt> arith_bdtPt_bdtDu(Rcpp::object<bdtPt>, Rcpp::object<bdtDu>, std::string);
-    friend bool compare_bdtPt_bdtPt(Rcpp::object<bdtPt>, Rcpp::object<bdtPt>, std::string);
-};
-
-class bdtDu {
-
-public:
-
-    bdtDu(int hours, int minutes, int seconds, int fractionalseconds) : m_td(hours, minutes, seconds, fractionalseconds) { }
-    bdtDu(boost::posix_time::time_duration td) : m_td(td) {} 
-    bdtDu(const bdtDu& other) : m_td(other.m_td ){}
-    
-    long getHours()             { return(m_td.hours()); }
-    long getMinutes()           { return(m_td.minutes()); }
-    long getSeconds()           { return(m_td.seconds()); }
-    long getTotalSeconds()      { return(m_td.total_seconds()); }
-    long getTotalMilliSeconds() { return(m_td.total_milliseconds()); }
-    long getTotalMicroSeconds() { return(m_td.total_microseconds()); }
-    long getTotalNanoSeconds()  { return(m_td.total_nanoseconds()); }
-    long getFractionalSeconds() { return(m_td.fractional_seconds()); }
-    unsigned short getNumFractionalDigits() { return(m_td.num_fractional_digits()); }
-    long getTicksPerSecond()    { return(m_td.ticks_per_second()); }
-
-    void addHours(int h)        { m_td += boost::posix_time::hours(h); }
-    void addMinutes(int m)      { m_td += boost::posix_time::minutes(m); }
-    void addSeconds(int s)      { m_td += boost::posix_time::seconds(s); }
-    void addMilliSeconds(int s) { m_td += boost::posix_time::milliseconds(s); }
-    void addMicroSeconds(int s) { m_td += boost::posix_time::microseconds(s); }
-    void addNanoSeconds(int s)  { m_td += boost::posix_time::nanoseconds(s); }
-    Rcpp::Datetime getAddedPosixtime(SEXP ptsexp)  { 
-        boost::posix_time::ptime pt(Rcpp::as<boost::posix_time::ptime>(ptsexp)); 
-        pt += m_td;
-        return Rcpp::wrap(pt); 
-    }
-
-private:
-    boost::posix_time::time_duration m_td;
-
-    friend Rcpp::object<bdtDu> arith_bdtDu_bdtDu(Rcpp::object<bdtDu>, Rcpp::object<bdtDu>, std::string);
-    friend Rcpp::object<bdtDu> arith_bdtDu_int(Rcpp::object<bdtDu>, int, std::string);
-    friend bool compare_bdtDu_bdtDu(Rcpp::object<bdtDu>, Rcpp::object<bdtDu>, std::string);
-
-    friend Rcpp::object<bdtPt> arith_bdtPt_bdtDu(Rcpp::object<bdtPt>, Rcpp::object<bdtDu>, std::string);
-};
-
-
 #endif

Added: pkg/RcppBDT/inst/include/RcppBDTdu.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTdu.h	                        (rev 0)
+++ pkg/RcppBDT/inst/include/RcppBDTdu.h	2012-10-23 02:47:04 UTC (rev 3810)
@@ -0,0 +1,66 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// RcppBDTdu.h: Rcpp and Boost Date_Time duration 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__RCPPBDTDU_H
+#define RCPPBDT__RCPPBDTDU_H
+
+class bdtDu {
+
+public:
+
+    bdtDu(int hours, int minutes, int seconds, int fractionalseconds) : m_td(hours, minutes, seconds, fractionalseconds) { }
+    bdtDu(boost::posix_time::time_duration td) : m_td(td) {} 
+    bdtDu(const bdtDu& other) : m_td(other.m_td ){}
+    
+    long getHours()             { return(m_td.hours()); }
+    long getMinutes()           { return(m_td.minutes()); }
+    long getSeconds()           { return(m_td.seconds()); }
+    long getTotalSeconds()      { return(m_td.total_seconds()); }
+    long getTotalMilliSeconds() { return(m_td.total_milliseconds()); }
+    long getTotalMicroSeconds() { return(m_td.total_microseconds()); }
+    long getTotalNanoSeconds()  { return(m_td.total_nanoseconds()); }
+    long getFractionalSeconds() { return(m_td.fractional_seconds()); }
+    unsigned short getNumFractionalDigits() { return(m_td.num_fractional_digits()); }
+    long getTicksPerSecond()    { return(m_td.ticks_per_second()); }
+
+    void addHours(int h)        { m_td += boost::posix_time::hours(h); }
+    void addMinutes(int m)      { m_td += boost::posix_time::minutes(m); }
+    void addSeconds(int s)      { m_td += boost::posix_time::seconds(s); }
+    void addMilliSeconds(int s) { m_td += boost::posix_time::milliseconds(s); }
+    void addMicroSeconds(int s) { m_td += boost::posix_time::microseconds(s); }
+    void addNanoSeconds(int s)  { m_td += boost::posix_time::nanoseconds(s); }
+    Rcpp::Datetime getAddedPosixtime(SEXP ptsexp)  { 
+        boost::posix_time::ptime pt(Rcpp::as<boost::posix_time::ptime>(ptsexp)); 
+        pt += m_td;
+        return Rcpp::wrap(pt); 
+    }
+
+private:
+    boost::posix_time::time_duration m_td;
+
+    friend Rcpp::object<bdtDu> arith_bdtDu_bdtDu(Rcpp::object<bdtDu>, Rcpp::object<bdtDu>, std::string);
+    friend Rcpp::object<bdtDu> arith_bdtDu_int(Rcpp::object<bdtDu>, int, std::string);
+    friend bool compare_bdtDu_bdtDu(Rcpp::object<bdtDu>, Rcpp::object<bdtDu>, std::string);
+
+    friend Rcpp::object<bdtPt> arith_bdtPt_bdtDu(Rcpp::object<bdtPt>, Rcpp::object<bdtDu>, std::string);
+};
+
+#endif

Added: pkg/RcppBDT/inst/include/RcppBDTpt.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTpt.h	                        (rev 0)
+++ pkg/RcppBDT/inst/include/RcppBDTpt.h	2012-10-23 02:47:04 UTC (rev 3810)
@@ -0,0 +1,73 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// RcppBDTdu.h: Rcpp and Boost Date_Time posix time 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__RCPPBDTPT_H
+#define RCPPBDT__RCPPBDTPT_H
+
+class bdtDu;
+
+class bdtPt {
+
+public:
+    bdtPt() 				  { setFromLocalTimeInMicroSeconds(); }  	// default empty constructor 
+    bdtPt(SEXP dt) 			  { setFromDatetime(dt); }     			// constructor from R's / Rcpp's Datetime
+    bdtPt(double dt) 			  { setFromDouble(dt); }     			// constructor from double using Rcpp's Datetime
+    bdtPt(int year, int month, int day, 			// constructor from date and duration
+          int hours, int minutes, int seconds, 
+          int fractionalseconds) : m_pt(boost::gregorian::date(year, month, day), 
+                                        boost::posix_time::time_duration(hours, minutes, seconds, fractionalseconds)) { }
+    bdtPt(boost::posix_time::ptime pt) : m_pt(pt) {} 
+    bdtPt(const bdtPt& other) : m_pt(other.m_pt ) {}
+    
+    void setFromLocalTimeInSeconds()      { m_pt = boost::posix_time::second_clock::local_time(); }
+    void setFromUTCInSeconds()            { m_pt = boost::posix_time::second_clock::universal_time(); }
+    void setFromLocalTimeInMicroSeconds() { m_pt = boost::posix_time::microsec_clock::local_time(); }
+    void setFromUTCInMicroSeconds()       { m_pt = boost::posix_time::microsec_clock::universal_time(); }
+                                    
+    void setFromTimeT(const time_t t)     { m_pt = boost::posix_time::from_time_t(t); }
+
+    void setFromDatetime(const SEXP dt)   { m_pt = Rcpp::as<boost::posix_time::ptime>(dt); }
+    void setFromDouble(const double d)   { 
+        Rcpp::Datetime dt(d);
+        m_pt = boost::posix_time::ptime(boost::gregorian::date(dt.getYear(), dt.getMonth(), dt.getDay()), 
+                                        boost::posix_time::time_duration(dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMicroSeconds()/1000.0));
+    }
+
+    Rcpp::Datetime getDatetime() 	  { return Rcpp::wrap(m_pt); }
+
+    Rcpp::Date getDate() { 
+        boost::gregorian::date::ymd_type ymd = m_pt.date().year_month_day();     // convert to date and then to y/m/d struct
+        return Rcpp::Date( ymd.year, ymd.month, ymd.day );
+    }
+
+    void addHours(int h)        	  { m_pt += boost::posix_time::time_duration(h, 0, 0, 0); }
+    void addMinutes(int m)        	  { m_pt += boost::posix_time::time_duration(0, m, 0, 0); }
+    void addSeconds(int s)        	  { m_pt += boost::posix_time::time_duration(0, 0, s, 0); }
+    void addFractionalSeconds(int fs)     { m_pt += boost::posix_time::time_duration(0, 0, 0, fs); }
+
+private:
+    boost::posix_time::ptime m_pt; 		// private ptime instace
+
+    friend Rcpp::object<bdtPt> arith_bdtPt_bdtDu(Rcpp::object<bdtPt>, Rcpp::object<bdtDu>, std::string);
+    friend bool compare_bdtPt_bdtPt(Rcpp::object<bdtPt>, Rcpp::object<bdtPt>, std::string);
+};
+
+#endif

Modified: pkg/RcppBDT/src/RcppBDTdu.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTdu.cpp	2012-10-23 00:56:15 UTC (rev 3809)
+++ pkg/RcppBDT/src/RcppBDTdu.cpp	2012-10-23 02:47:04 UTC (rev 3810)
@@ -21,8 +21,6 @@
 
 #include <RcppBDT.h>
 
-//using namespace Rcpp ;
-
 Rcpp::object<bdtDu> hours(int h)		{ return new bdtDu( boost::posix_time::hours(h) ); }
 Rcpp::object<bdtDu> minutes(int m)		{ return new bdtDu( boost::posix_time::minutes(m) ); }
 Rcpp::object<bdtDu> seconds(int s)		{ return new bdtDu( boost::posix_time::seconds(s) ); }



More information about the Rcpp-commits mailing list