[Rprotobuf-commits] r335 - pkg/inst/examples/HighFrequencyFinance
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jul 17 20:53:35 CEST 2010
Author: edd
Date: 2010-07-17 20:53:35 +0200 (Sat, 17 Jul 2010)
New Revision: 335
Modified:
pkg/inst/examples/HighFrequencyFinance/loadInR.r
pkg/inst/examples/HighFrequencyFinance/protoModule.cpp
Log:
modules update -- but not there yet
Modified: pkg/inst/examples/HighFrequencyFinance/loadInR.r
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/loadInR.r 2010-07-17 18:43:11 UTC (rev 334)
+++ pkg/inst/examples/HighFrequencyFinance/loadInR.r 2010-07-17 18:53:35 UTC (rev 335)
@@ -88,7 +88,7 @@
yada <- Module("yada", dll)
yada$init("trades.pb")
- print( yada$nbfills() )
+ print( yada$numberOfFills() )
invisible(NULL)
}
@@ -96,7 +96,7 @@
suppressMessages(library(RProtoBuf))
suppressMessages(library(rbenchmark))
-#moduled()
+moduled(); q()
dyn.load("protoLoadForR.so")
Modified: pkg/inst/examples/HighFrequencyFinance/protoModule.cpp
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/protoModule.cpp 2010-07-17 18:43:11 UTC (rev 334)
+++ pkg/inst/examples/HighFrequencyFinance/protoModule.cpp 2010-07-17 18:53:35 UTC (rev 335)
@@ -5,33 +5,33 @@
#include <Rcpp.h>
#include <fstream>
-static TradeData::Trades tr;
+class TradeModule : public TradeData::Trades
+{
+private:
+ TradeData::Trades tr;
+public:
+ int init(const char *pbfile) {
+ std::fstream fs(pbfile, std::ios::in | std::ios::binary);
-int init(const char *pbfile) {
- std::fstream fs(pbfile, std::ios::in | std::ios::binary);
+ if (!tr.ParseFromIstream(&fs)) {
+ std::cerr << "Trouble parsing..." << std::cout;
+ return -1;
+ }
+ return 0;
+ }
- if (!tr.ParseFromIstream(&fs)) {
- std::cerr << "Trouble parsing..." << std::cout;
- return -1;
+ int numberOfFills(void) {
+ return tr.fill_size();
}
- return 0;
-}
-
-int nbfills(void) {
- int n = tr.fill_size();
- return n;
-}
+};
RCPP_MODULE(yada){
using namespace Rcpp ;
- class_<TradeData::Trades>( "Trades" )
- .method( "fill_size", &TradeData::Trades::fill_size )
+ class_<TradeModule>( "Trades" )
+ .method( "init", &TradeModule::init )
+ .method( "numberOfFills", &TradeModule::numberOfFills )
;
- function( "init", &init);
- function( "nbfills", &nbfills);
-
- // Hmpf. So how do I return the data.frame via Modules?
}
More information about the Rprotobuf-commits
mailing list