[Rcpp-commits] r3743 - in pkg/RcppBDT: . src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Aug 25 01:14:45 CEST 2012


Author: edd
Date: 2012-08-25 01:14:45 +0200 (Sat, 25 Aug 2012)
New Revision: 3743

Modified:
   pkg/RcppBDT/ChangeLog
   pkg/RcppBDT/src/RcppBDTtz.cpp
Log:
improved constructor using Rcpp::Language


Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog	2012-08-23 03:04:59 UTC (rev 3742)
+++ pkg/RcppBDT/ChangeLog	2012-08-24 23:14:45 UTC (rev 3743)
@@ -1,3 +1,8 @@
+2012-08-24  Dirk Eddelbuettel  <edd at dexter>
+
+	* src/RcppBDTtz.cpp: Use Language evaluation to get location of zone
+	db file, reducing constructor to single argument for region
+
 2012-08-22  Dirk Eddelbuettel  <edd at dexter>
 
 	* src/RcppBDTtz.cpp: Rewritten bdtTz to be based on small class

Modified: pkg/RcppBDT/src/RcppBDTtz.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTtz.cpp	2012-08-23 03:04:59 UTC (rev 3742)
+++ pkg/RcppBDT/src/RcppBDTtz.cpp	2012-08-24 23:14:45 UTC (rev 3743)
@@ -25,7 +25,15 @@
 
 public:
 
-    bdtTz(std::string zonefile, std::string region) {
+    bdtTz(std::string 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", "data", 
+					   "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
     }
@@ -62,11 +70,11 @@
 
     Rcpp::class_<bdtTz>("bdtTz")   
 	
-    .constructor<std::string,std::string>("constructor with zonefile and region")  
+    .constructor<std::string>("constructor with region string (eg \"Europe/London\")")  
 
     .method("getRegions",       &bdtTz::getRegions,       "get vector of TZ region names")
 
-    .method("getUtcOffset",     &bdtTz::getUtcTotalSec,   "get seconds from UTC")
+    .method("getUtcOffset",     &bdtTz::getUtcTotalSec,   "get UTC offset in seconds")
     .method("getDstOffset",     &bdtTz::getDstTotalSec  , "get DST offset in seconds")
 
     .method("getDstZoneAbbrev", &bdtTz::getDstZoneAbbrev, "get DST zone abbreviation")



More information about the Rcpp-commits mailing list