[Rcpp-commits] r3834 - in pkg/RcppBDT: R demo inst/include src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Oct 25 02:42:11 CEST 2012
Author: edd
Date: 2012-10-25 02:42:11 +0200 (Thu, 25 Oct 2012)
New Revision: 3834
Modified:
pkg/RcppBDT/R/zzz.R
pkg/RcppBDT/demo/RcppBDTdu.R
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/RcppBDTdu.cpp
pkg/RcppBDT/src/RcppBDTpt.cpp
Log:
add du + pt and a few other cleanups
Modified: pkg/RcppBDT/R/zzz.R
===================================================================
--- pkg/RcppBDT/R/zzz.R 2012-10-24 19:52:53 UTC (rev 3833)
+++ pkg/RcppBDT/R/zzz.R 2012-10-25 00:42:11 UTC (rev 3834)
@@ -70,16 +70,19 @@
setMethod("format", "Rcpp_bdtDu", .format_du)
setMethod("Arith", signature(e1 = "Rcpp_bdtDu", e2 = "Rcpp_bdtDu" ),
- function(e1, e2){ arith_bdtDu_bdtDu( e1, e2, .Generic )} )
+ function(e1, e2) arith_bdtDu_bdtDu( e1, e2, .Generic ) )
setMethod("Arith", signature(e1 = "Rcpp_bdtDu", e2 = "integer" ),
- function(e1, e2){arith_bdtDu_int( e1, e2, .Generic )} )
+ function(e1, e2) arith_bdtDu_int( e1, e2, .Generic ) )
setMethod("Arith", signature(e1 = "Rcpp_bdtDu", e2 = "numeric" ),
- function(e1, e2){ arith_bdtDu_int( e1, as.integer(e2), .Generic )} )
+ function(e1, e2) arith_bdtDu_int( e1, as.integer(e2), .Generic ) )
setMethod("Compare", signature(e1 = "Rcpp_bdtDu", e2 = "Rcpp_bdtDu" ),
function(e1, e2) {compare_bdtDu_bdtDu( e1, e2, .Generic )} )
setMethod("Arith", signature(e1 = "Rcpp_bdtPt", e2 = "Rcpp_bdtDu" ),
- function(e1, e2){ arith_bdtPt_bdtDu( e1, e2, .Generic )} )
+ function(e1, e2) arith_bdtPt_bdtDu(e1, e2, .Generic ))
+ setMethod("Arith", signature(e1 = "Rcpp_bdtDu", e2 = "Rcpp_bdtPt" ),
+ function(e1, e2) arith_bdtDu_bdtPt(e1, e2, .Generic ))
setMethod("Compare", signature(e1 = "Rcpp_bdtPt", e2 = "Rcpp_bdtPt"),
function(e1, e2) compare_bdtPt_bdtPt(e1, e2, .Generic))
+
})
Modified: pkg/RcppBDT/demo/RcppBDTdu.R
===================================================================
--- pkg/RcppBDT/demo/RcppBDTdu.R 2012-10-24 19:52:53 UTC (rev 3833)
+++ pkg/RcppBDT/demo/RcppBDTdu.R 2012-10-25 00:42:11 UTC (rev 3834)
@@ -1,25 +1,23 @@
-## demo / sketch for duration objects
+## demo for duration objects
require(utils, quiet=TRUE, warn=FALSE)
require(Rcpp, quiet=TRUE, warn=FALSE)
require(RcppBDT, quiet=TRUE, warn=FALSE)
## ctor with hour, minute, second, fractional seconds (all as ints)
-du <- new(bdtDu, 1, 2, 3, 456)
-print(du) ## not bad: converts to difftime
+du <- new(bdtDu, 0, 1, 2, 123456789)
+print(du) ## converts to difftime
-dn <- new(bdtDu, 0, 1, -3, 123456789) # negative int permitted too, make it negative sign for object
-print(dn) ## not bad: converts to difftime
+dn <- new(bdtDu, 0, 1, -2, 123456789) # negative int permitted too, make it negative sign for object
+print(dn) ## converts to difftime
-today <- Sys.Date() # base R
+today <- Sys.Date() # base R, provides Date
+## TODO fails: today + du
-## fails: today + du
-
now <- Sys.time() # base R
-
-## fails as well now + du, but
+## TODO fails as well now + du, but this works
print(du$getAddedPosixtime(now))
du$addSeconds(2.2)
@@ -33,3 +31,14 @@
# add 'du' to something and get a time object ?
# convert posix time (from Boost) to POSIXct ?
# more conversions ?
+
+print(du + hours(2) + minutes(3) + seconds(4) + nanoseconds(42))
+
+## use one of several bdtPt ctors
+pt <- new(bdtPt, ISOdatetime(2012,1,1,00,30,0,tz="UTC"))
+
+print(pt + du)
+print(du + pt)
+
+print(pt + hours(3) + minutes(4))
+
Modified: pkg/RcppBDT/inst/include/RcppBDT.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDT.h 2012-10-24 19:52:53 UTC (rev 3833)
+++ pkg/RcppBDT/inst/include/RcppBDT.h 2012-10-25 00:42:11 UTC (rev 3834)
@@ -24,7 +24,7 @@
#include <RcppCommon.h>
-/* forward declarations and helping module classes */
+// forward declarations and helping module classes
class bdtDu ;
class bdtPt ;
RCPP_EXPOSED_CLASS(bdtDu) ;
Modified: pkg/RcppBDT/inst/include/RcppBDTdu.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTdu.h 2012-10-24 19:52:53 UTC (rev 3833)
+++ pkg/RcppBDT/inst/include/RcppBDTdu.h 2012-10-25 00:42:11 UTC (rev 3834)
@@ -60,6 +60,8 @@
friend bdtDu* arith_bdtDu_int(const bdtDu&, int, std::string);
friend bool compare_bdtDu_bdtDu(const bdtDu&, const bdtDu&, std::string);
friend bdtPt* arith_bdtPt_bdtDu(const bdtPt&, const bdtDu&, std::string);
+ friend bdtPt* arith_bdtDu_bdtPt(const bdtDu&, const bdtPt&, std::string);
};
#endif
+
Modified: pkg/RcppBDT/inst/include/RcppBDTpt.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTpt.h 2012-10-24 19:52:53 UTC (rev 3833)
+++ pkg/RcppBDT/inst/include/RcppBDTpt.h 2012-10-25 00:42:11 UTC (rev 3834)
@@ -66,8 +66,9 @@
private:
boost::posix_time::ptime m_pt; // private ptime instace
- friend bdtPt* arith_bdtPt_bdtDu(const bdtPt& , const bdtDu&, std::string);
- friend bool compare_bdtPt_bdtPt(const bdtPt& , const bdtPt&, std::string);
+ friend bdtPt* arith_bdtPt_bdtDu(const bdtPt&, const bdtDu&, std::string);
+ friend bdtPt* arith_bdtDu_bdtPt(const bdtDu&, const bdtPt&, std::string);
+ friend bool compare_bdtPt_bdtPt(const bdtPt&, const bdtPt&, std::string);
};
#endif
Modified: pkg/RcppBDT/src/RcppBDTdt.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTdt.cpp 2012-10-24 19:52:53 UTC (rev 3833)
+++ pkg/RcppBDT/src/RcppBDTdt.cpp 2012-10-25 00:42:11 UTC (rev 3834)
@@ -40,7 +40,8 @@
}
Rcpp::Date getNthDayOfWeek(bdtDt *d, int nthday, int dow, int mon, int year) { // does not use bdtDt pointer, but need for RCPP_MODULE use
- boost::gregorian::nth_day_of_the_week_in_month ans_generator(static_cast<boost::date_time::nth_kday_of_month<boost::gregorian::date>::week_num>(nthday), dow, mon);
+ boost::gregorian::nth_day_of_the_week_in_month
+ ans_generator(static_cast<boost::date_time::nth_kday_of_month<boost::gregorian::date>::week_num>(nthday), dow, mon);
return Rcpp::wrap(ans_generator.get_date(year));
}
Modified: pkg/RcppBDT/src/RcppBDTdu.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTdu.cpp 2012-10-24 19:52:53 UTC (rev 3833)
+++ pkg/RcppBDT/src/RcppBDTdu.cpp 2012-10-25 00:42:11 UTC (rev 3834)
@@ -74,6 +74,7 @@
return R_NilValue ;
}
+
RCPP_MODULE(bdtDuMod) {
Rcpp::class_<bdtDu>("bdtDu")
@@ -108,7 +109,9 @@
Rcpp::function( "nanoseconds", &nanoseconds ) ;
Rcpp::function( "arith_bdtDu_bdtDu", &arith_bdtDu_bdtDu ) ;
- Rcpp::function( "arith_bdtDu_int", &arith_bdtDu_int ) ;
- Rcpp::function( "compare_bdtDu_bdtDu", &compare_bdtDu_bdtDu ) ;
+ Rcpp::function( "arith_bdtDu_int", &arith_bdtDu_int ) ;
+ Rcpp::function( "compare_bdtDu_bdtDu", &compare_bdtDu_bdtDu );
+
}
+
Modified: pkg/RcppBDT/src/RcppBDTpt.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTpt.cpp 2012-10-24 19:52:53 UTC (rev 3833)
+++ pkg/RcppBDT/src/RcppBDTpt.cpp 2012-10-25 00:42:11 UTC (rev 3834)
@@ -49,6 +49,16 @@
return new bdtPt();
}
+bdtPt* arith_bdtDu_bdtPt(const bdtDu& e1, const bdtPt& e2, std::string op) {
+ if( ! op.compare("+") ){
+ return new bdtPt( e2.m_pt + e1.m_td ) ;
+ }
+ // e1 - e2, ie duration - ptime, makes no sense
+ Rf_error( "operator not implemented" ) ;
+ // not reached
+ return new bdtPt();
+}
+
bool compare_bdtPt_bdtPt(const bdtPt& e1, const bdtPt& e2, std::string op) {
if( !op.compare( "==" ) ){
return e1.m_pt == e2.m_pt ;
@@ -96,5 +106,7 @@
;
Rcpp::function("arith_bdtPt_bdtDu", &arith_bdtPt_bdtDu);
+ Rcpp::function("arith_bdtDu_bdtPt", &arith_bdtDu_bdtPt);
Rcpp::function("compare_bdtPt_bdtPt", &compare_bdtPt_bdtPt);
}
+
More information about the Rcpp-commits
mailing list