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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 25 05:16:46 CEST 2012


Author: edd
Date: 2012-10-25 05:16:46 +0200 (Thu, 25 Oct 2012)
New Revision: 3837

Modified:
   pkg/RcppBDT/ChangeLog
   pkg/RcppBDT/R/zzz.R
   pkg/RcppBDT/inst/include/RcppBDTdt.h
   pkg/RcppBDT/inst/include/RcppBDTdu.h
   pkg/RcppBDT/src/RcppBDTdt.cpp
Log:
(some) Arithmetic for bdtDt


Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog	2012-10-25 02:53:00 UTC (rev 3836)
+++ pkg/RcppBDT/ChangeLog	2012-10-25 03:16:46 UTC (rev 3837)
@@ -5,7 +5,7 @@
 	on Rcpp::wrap() for conversion, rather than always directly converting
 	* src/RcppBDTdt.cpp: Idem
 
-	* src/RcppBDTdt.cpp: Comparison support for bdtDt type
+	* src/RcppBDTdt.cpp: Comparison and (some) Arithmetic support for bdtDt type
 
 	* man/bdtDu.Rd: Document new methods for Arithmetic and Comparison
 	* man/bdtPt.Rd: Idem

Modified: pkg/RcppBDT/R/zzz.R
===================================================================
--- pkg/RcppBDT/R/zzz.R	2012-10-25 02:53:00 UTC (rev 3836)
+++ pkg/RcppBDT/R/zzz.R	2012-10-25 03:16:46 UTC (rev 3837)
@@ -90,6 +90,10 @@
     setMethod("Compare", signature(e1 = "Rcpp_bdtDt", e2 = "Date"),
               function(e1, e2) compare_bdtDt_bdtDt(e1, new(bdtDt, e2), .Generic))
 #    setMethod("Compare", signature(e1 = "Date", e2 = "Rcpp_bdtDt"), ,
-#              function(e1, e2) compare_bdtDt_bdtDt(new(bdtDt, e1), e2, .Generic))
+#             function(e1, e2) compare_bdtDt_bdtDt(new(bdtDt, e1), e2, .Generic))
+    setMethod("Arith", signature(e1 = "Rcpp_bdtDt", e2 = "integer"),
+              function(e1, e2) arith_bdtDt_int(e1, e2, .Generic) )
+    setMethod("Arith", signature(e1 = "Rcpp_bdtDt", e2 = "numeric"),
+              function(e1, e2) arith_bdtDt_int(e1, as.integer(e2), .Generic) )
 
 })

Modified: pkg/RcppBDT/inst/include/RcppBDTdt.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTdt.h	2012-10-25 02:53:00 UTC (rev 3836)
+++ pkg/RcppBDT/inst/include/RcppBDTdt.h	2012-10-25 03:16:46 UTC (rev 3837)
@@ -77,6 +77,7 @@
 private:
     boost::gregorian::date m_dt; 			// private Boost date instance
 
+    friend bdtDt* arith_bdtDt_int(const bdtDt&, const int&, std::string);
     friend bool compare_bdtDt_bdtDt(const bdtDt&, const bdtDt&, std::string);
 };
 

Modified: pkg/RcppBDT/inst/include/RcppBDTdu.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTdu.h	2012-10-25 02:53:00 UTC (rev 3836)
+++ pkg/RcppBDT/inst/include/RcppBDTdu.h	2012-10-25 03:16:46 UTC (rev 3837)
@@ -56,11 +56,12 @@
 private:
     boost::posix_time::time_duration m_td;
 
-    friend bdtDu* arith_bdtDu_bdtDu(const bdtDu& , const bdtDu& , std::string);
-    friend bdtDu* arith_bdtDu_int(const bdtDu&, int, std::string);
+    friend bdtDu* arith_bdtDu_bdtDu(const bdtDu&, const bdtDu& , std::string);
+    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);
+    friend bdtDt* arith_bdtDt_int(const bdtDt&,   const int&, std::string);
 };
 
 #endif

Modified: pkg/RcppBDT/src/RcppBDTdt.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTdt.cpp	2012-10-25 02:53:00 UTC (rev 3836)
+++ pkg/RcppBDT/src/RcppBDTdt.cpp	2012-10-25 03:16:46 UTC (rev 3837)
@@ -68,6 +68,17 @@
 }
 
 
+bdtDt* arith_bdtDt_int( const bdtDt& e1, const int& e2, std::string op ){
+    if( ! op.compare("+") ){
+        return new bdtDt( e1.m_dt + boost::gregorian::date_duration(e2) );   
+    } else if( ! op.compare("-") ){
+        return new bdtDt( e1.m_dt - boost::gregorian::date_duration(e2) );
+    }
+    Rf_error( "operator not implemented" );
+    // not reached
+    return new bdtDt(0,0,0);
+}
+
 bool compare_bdtDt_bdtDt( const bdtDt& e1, const bdtDt& e2, std::string op ){
     if( !op.compare( "==" ) ){
         return e1.m_dt == e2.m_dt ;   
@@ -137,8 +148,8 @@
 
         ;
 
+    Rcpp::function("arith_bdtDt_int",         &arith_bdtDt_int); 
     Rcpp::function("compare_bdtDt_bdtDt",     &compare_bdtDt_bdtDt);
-
 }
 
 



More information about the Rcpp-commits mailing list