|
RInside Version 0.2.6
|
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*- 00002 // 00003 // RInside.h: R/C++ interface class library -- Easier R embedding into C++ 00004 // 00005 // Copyright (C) 2009 Dirk Eddelbuettel 00006 // Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois 00007 // 00008 // This file is part of RInside. 00009 // 00010 // RInside is free software: you can redistribute it and/or modify it 00011 // under the terms of the GNU General Public License as published by 00012 // the Free Software Foundation, either version 2 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // RInside is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU General Public License 00021 // along with RInside. If not, see <http://www.gnu.org/licenses/>. 00022 00023 #ifndef RINSIDE_RINSIDE_H 00024 #define RINSIDE_RINSIDE_H 00025 00026 #include <RInsideCommon.h> 00027 #include <Callbacks.h> 00028 00029 class RInside { 00030 private: 00031 MemBuf mb_m; 00032 Rcpp::Environment global_env ; 00033 00034 bool verbose_m; // private switch 00035 00036 void init_tempdir(void); 00037 void init_rand(void); 00038 void autoloads(void); 00039 00040 void initialize(const int argc, const char* const argv[], const bool loadRcpp ) ; 00041 00042 static RInside* instance_ ; 00043 00044 #ifdef RINSIDE_CALLBACKS 00045 Callbacks* callbacks ; 00046 friend void RInside_ShowMessage( const char* message) ; 00047 friend void RInside_WriteConsoleEx( const char* message, int len, int oType ) ; 00048 friend int RInside_ReadConsole(const char *prompt, unsigned char *buf, int len, int addtohistory) ; 00049 friend void RInside_ResetConsole() ; 00050 friend void RInside_FlushConsole() ; 00051 friend void RInside_ClearerrConsole() ; 00052 friend void RInside_Busy(int which) ; 00053 #endif 00054 00055 public: 00056 int parseEval(const std::string & line, SEXP &ans); // parse line, return in ans; error code rc 00057 void parseEvalQ(const std::string & line); // parse line, no return (throws on error) 00058 00059 class Proxy { 00060 public: 00061 Proxy(SEXP xx): x(xx) { }; 00062 00063 template <typename T> 00064 operator T() { 00065 return ::Rcpp::as<T>(x); 00066 } 00067 private: 00068 Rcpp::RObject x; 00069 }; 00070 00071 Proxy parseEval(const std::string & line); // parse line, return SEXP (throws on error) 00072 00073 template <typename T> 00074 void assign(const T& object, const std::string& nam) { 00075 global_env.assign( nam, object ) ; 00076 } 00077 00078 RInside() ; 00079 RInside(const int argc, const char* const argv[], const bool loadRcpp=false); 00080 ~RInside(); 00081 00082 Rcpp::Environment::Binding operator[]( const std::string& name ) ; 00083 00084 static RInside& instance() ; 00085 00086 #ifdef RINSIDE_CALLBACKS 00087 void set_callbacks(Callbacks* callbacks_) ; 00088 void repl() ; 00089 #endif 00090 00091 }; 00092 00093 #endif