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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jan 3 05:22:48 CET 2011


Author: edd
Date: 2011-01-03 05:22:47 +0100 (Mon, 03 Jan 2011)
New Revision: 2823

Modified:
   pkg/RcppBDT/ChangeLog
   pkg/RcppBDT/demo/RcppBDT.R
   pkg/RcppBDT/inst/include/RcppBDT.h
   pkg/RcppBDT/src/Makevars
   pkg/RcppBDT/src/RcppBDT.cpp
Log:
now purely templated by not using string conversion libraries


Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog	2011-01-03 03:49:51 UTC (rev 2822)
+++ pkg/RcppBDT/ChangeLog	2011-01-03 04:22:47 UTC (rev 2823)
@@ -1,10 +1,17 @@
 2011-01-02  Dirk Eddelbuettel  <edd at debian.org>
 
-	* R/RcppBDT.Rcpp: Modified modules wrapper name to make it clearer
+	* src/RcppBDT.cpp: Modified modules wrapper name to make it clearer
 	which function set and which functions get or convert data
 
 	* tests/RcppBDT.R: Define simplest test of just calling demo()
 
+	* inst/include/RcppBDT.h: Defined compile-time variable to allow use
+	of string functions; when not defined we use only pure C++ template
+	and do not need to link against the C++ library from Boost Date.Time
+	* src/RcppBDT.cpp: Make parts of code depend upon new compile variable
+	* src/Makevars: No longer link with -lboost_date_time
+	* demo/RcppBDT.R: Comment-out two string-using functions
+
 2011-01-01  Dirk Eddelbuettel  <edd at debian.org>
 
 	* demo/RcppBDT.R: Added RcppBDT demo showing a few functions

Modified: pkg/RcppBDT/demo/RcppBDT.R
===================================================================
--- pkg/RcppBDT/demo/RcppBDT.R	2011-01-03 03:49:51 UTC (rev 2822)
+++ pkg/RcppBDT/demo/RcppBDT.R	2011-01-03 04:22:47 UTC (rev 2823)
@@ -9,19 +9,19 @@
 
     cat("Demo of setters\n");
     ## first init a base objects for uses for the functions below
-    bd <- new(BDTDate, 2010, 10, 1);    cat("From 2010, 10, 1 : ", format(bd$getString()), "\n")
+    bd <- new(BDTDate, 2010, 10, 1);    cat("From 2010, 10, 1 : ", format(bd$getDate()), "\n")
     ## then assign new values to the base object
-    bd$fromString("2010-10-02"); 	cat("From 2010-10-02  : ", format(bd$getString()), "\n")
-    bd$fromUndelString("20101003");     cat("From 20101003    : ", format(bd$getString()), "\n")
-    bd$setFromUTC(); 			cat("From curr. UTC   : ", format(bd$getString()), "\n")
-    bd$setFromLocalClock();		cat("From curr. local : ", format(bd$getString()), "\n")
-    bd$setEndOfMonth(); 		cat("end of month     : ", format(bd$getString()), "\n")
-    bd$setFirstOfNextMonth(); 		cat("1st of next Month: ", format(bd$getString()), "\n")
-    bd$addDays(4);                      cat("plus four days   : ", format(bd$getString()), "\n")
-    bd$subtractDays(3);                 cat("minus three  s   : ", format(bd$getString()), "\n")
+    #bd$fromString("2010-10-02"); 	cat("From 2010-10-02  : ", format(bd$getDate()), "\n")
+    #bd$fromUndelString("20101003");     cat("From 20101003    : ", format(bd$getDate()), "\n")
+    bd$setFromUTC(); 			cat("From curr. UTC   : ", format(bd$getDate()), "\n")
+    bd$setFromLocalClock();		cat("From curr. local : ", format(bd$getDate()), "\n")
+    bd$setEndOfMonth(); 		cat("end of month     : ", format(bd$getDate()), "\n")
+    bd$setFirstOfNextMonth(); 		cat("1st of next Month: ", format(bd$getDate()), "\n")
+    bd$addDays(4);                      cat("plus four days   : ", format(bd$getDate()), "\n")
+    bd$subtractDays(3);                 cat("minus three  s   : ", format(bd$getDate()), "\n")
 
-    bd$setIMMDate(12, 2010); 		cat("IMM Date Dec 2010: ", format(bd$getString()), "\n")
-    bd$setEndOfBizWeek();  		cat("end of biz week  : ", format(bd$getString()), "\n")
+    bd$setIMMDate(12, 2010); 		cat("IMM Date Dec 2010: ", format(bd$getDate()), "\n")
+    bd$setEndOfBizWeek();  		cat("end of biz week  : ", format(bd$getDate()), "\n")
 
     cat("\nDemo of getters\n")
     ## now just functions that return values to R

Modified: pkg/RcppBDT/inst/include/RcppBDT.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDT.h	2011-01-03 03:49:51 UTC (rev 2822)
+++ pkg/RcppBDT/inst/include/RcppBDT.h	2011-01-03 04:22:47 UTC (rev 2823)
@@ -24,9 +24,17 @@
 
 #include <RcppCommon.h>
 
+// this variable governs whether we need to link against 
+#define UseWithStrings 0
+
 //#include <boost/date_time.hpp>
-#include <boost/date_time/gregorian/gregorian.hpp> 	// Gregorian calendar types, including I/O
 
+#if UseWithString
+  #include <boost/date_time/gregorian/gregorian.hpp> 	// Gregorian calendar types, including I/O
+#else
+  #include <boost/date_time/gregorian/gregorian_types.hpp> 	// Gregorian calendar types, no I/O
+#endif
+
 namespace Rcpp {
     // non-intrusive extension via template specialisation
     template <> boost::gregorian::date as( SEXP dt ) throw(not_compatible);

Modified: pkg/RcppBDT/src/Makevars
===================================================================
--- pkg/RcppBDT/src/Makevars	2011-01-03 03:49:51 UTC (rev 2822)
+++ pkg/RcppBDT/src/Makevars	2011-01-03 04:22:47 UTC (rev 2823)
@@ -1,3 +1,4 @@
 ## Use the R_HOME indirection to support installations of multiple R version
-PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` -lboost_date_time
+#PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` -lboost_date_time
+PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` 
 PKG_CPPFLAGS += -I../inst/include/

Modified: pkg/RcppBDT/src/RcppBDT.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDT.cpp	2011-01-03 03:49:51 UTC (rev 2822)
+++ pkg/RcppBDT/src/RcppBDT.cpp	2011-01-03 04:22:47 UTC (rev 2823)
@@ -34,6 +34,7 @@
     }
 }
 
+#if UseWithStrings
 void date_print(boost::gregorian::date *d) {
     std::cout << *d << std::endl;
 }
@@ -52,6 +53,7 @@
 Rcpp::Date Date_fromUndelString(boost::gregorian::date *d, std::string s) { 
     return Rcpp::wrap(boost::gregorian::date(boost::gregorian::from_undelimited_string(s))); 
 }
+#endif
 
 // these set the date from the clock, in local or universal time
 void date_localDay(boost::gregorian::date *d) { *d = boost::gregorian::date(boost::gregorian::day_clock::local_day()); }
@@ -66,10 +68,12 @@
 int date_dayofweek(boost::gregorian::date *d) { return static_cast<int>( d->day_of_week() ); }
 int date_dayofyear(boost::gregorian::date *d) { return static_cast<int>( d->day_of_year() ); }
 
+#if UseWithStrings
 // these extract the requested date portion or representation as an integer
 std::string date_toString(boost::gregorian::date *d) { return boost::gregorian::to_simple_string(*d); }
 std::string date_toIsoString(boost::gregorian::date *d) { return boost::gregorian::to_iso_string(*d); }
 std::string date_toExtIsoString(boost::gregorian::date *d) { return boost::gregorian::to_iso_extended_string(*d); }
+#endif
 
 //Date date_toDate(date *d) { // earlier form before wrap()
 //    date::ymd_type ymd = d->year_month_day();
@@ -118,11 +122,13 @@
     .constructor("default constructor")
     .constructor<int, int, int>("constructor from year, month, day")
 
+#if UseWithStrings
     // free functions defined above with date* as first argument
     .method("fromString", &date_fromString, "create a date from a delimited string")
     .method("fromUndelString", &date_fromUndelString, "create a date from an un delimited string")
     .method("getDateFromString", &Date_fromString, "return a date from a delimited string")
     .method("getDateFromUndelString", &Date_fromUndelString, "return a date from an un delimited string")
+#endif
 
     .method("setFromLocalClock", &date_localDay, "create a date from current local clock")
     .method("setFromUTC", &date_utcDay, "create a date from current universal clock")
@@ -137,9 +143,11 @@
     .method("getDayOfWeek", &date_dayofweek, "returns the day of the week")
     .method("getDayOfYear", &date_dayofyear, "returns the day of the year")
 
+#if UseWithStrings
     .method("getString", &date_toString, "returns a string representation")
     .method("getIsoString", &date_toIsoString, "returns an ISO string representation")
     .method("getExtIsoString", &date_toExtIsoString, "returns an extended ISO string representation")
+#endif
 
     .method("getDate", &date_toDate, "returns an R Date object")
 



More information about the Rcpp-commits mailing list