[Rinside-commits] r143 - pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 30 21:00:12 CEST 2010


Author: romain
Date: 2010-03-30 21:00:12 +0200 (Tue, 30 Mar 2010)
New Revision: 143

Modified:
   pkg/src/RInside.cpp
   pkg/src/RInside.h
Log:
need to access the singleton RInside instance (for callbacks)

Modified: pkg/src/RInside.cpp
===================================================================
--- pkg/src/RInside.cpp	2010-03-26 04:47:13 UTC (rev 142)
+++ pkg/src/RInside.cpp	2010-03-30 19:00:12 UTC (rev 143)
@@ -43,10 +43,11 @@
     //#endif
     Rf_endEmbeddedR(0);
     logTxt("RInside::dtor END", verbose);
+    instance_ = 0 ;
 }
 
 RInside::RInside() {
-    initialize( 0, 0 );
+	initialize( 0, 0 );
 }
 
 RInside::RInside(const int argc, const char* const argv[]) {
@@ -57,6 +58,12 @@
 void RInside::initialize(const int argc, const char* const argv[]){
     logTxt("RInside::ctor BEGIN", verbose);
 
+    if( instance_ ){
+    	throw std::runtime_error( "can only have one RInside instance" ) ;
+    } else {
+    	instance_ = *this ;	
+    }
+    
     verbose_m = false; 		// Default is false
 
     // generated as littler.h via from svn/littler/littler.R

Modified: pkg/src/RInside.h
===================================================================
--- pkg/src/RInside.h	2010-03-26 04:47:13 UTC (rev 142)
+++ pkg/src/RInside.h	2010-03-30 19:00:12 UTC (rev 143)
@@ -48,6 +48,8 @@
     
     void initialize(const int argc, const char* const argv[] ) ;
 
+    static RInside* instance_ ;
+    
 public:
     int  parseEval(const std::string & line, SEXP &ans); // parse line, return in ans; error code rc
     void parseEvalQ(const std::string & line);		 // parse line, no return (throws on error)
@@ -77,8 +79,11 @@
     
     Rcpp::Environment::Binding operator[]( const std::string& name ) ;
     
+    static RInside& instance() ;
 };
 
+RInside* RInside::instance_ = 0 ;
+
 // simple logging help
 inline void logTxtFunction(const char* file, const int line, const char* expression, const bool verbose) {
     if (verbose) {
@@ -90,4 +95,4 @@
 #undef logTxt
 #endif
 //#define logTxt(x, b) logTxtFunction(__FILE__, __LINE__, x, b);
-#define logTxt(x, b) 
+#define logTxt(x, b)



More information about the Rinside-commits mailing list