|
RInside Version 0.2.10
|
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 - 2012 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_m; 00033 00034 bool verbose_m; // switch toggled by constructor, or setter 00035 bool interactive_m; // switch set by constructor only 00036 00037 void init_tempdir(void); 00038 void init_rand(void); 00039 void autoloads(void); 00040 00041 void initialize(const int argc, const char* const argv[], 00042 const bool loadRcpp, const bool verbose, const bool interactive); 00043 00044 static RInside* instance_m ; 00045 00046 #ifdef RINSIDE_CALLBACKS 00047 Callbacks* callbacks ; 00048 friend void RInside_ShowMessage( const char* message); 00049 friend void RInside_WriteConsoleEx( const char* message, int len, int oType ); 00050 friend int RInside_ReadConsole(const char *prompt, unsigned char *buf, int len, int addtohistory); 00051 friend void RInside_ResetConsole(); 00052 friend void RInside_FlushConsole(); 00053 friend void RInside_ClearerrConsole(); 00054 friend void RInside_Busy(int which); 00055 #endif 00056 00057 public: 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 int parseEval(const std::string &line, SEXP &ans); // parse line, return in ans; error code rc 00072 void parseEvalQ(const std::string &line); // parse line, no return (throws on error) 00073 void parseEvalQNT(const std::string &line); // parse line, no return (no throw) 00074 Proxy parseEval(const std::string &line); // parse line, return SEXP (throws on error) 00075 Proxy parseEvalNT(const std::string &line); // parse line, return SEXP (no throw) 00076 00077 template <typename T> 00078 void assign(const T& object, const std::string& nam) { 00079 global_env_m.assign( nam, object ) ; 00080 } 00081 00082 RInside() ; 00083 RInside(const int argc, const char* const argv[], 00084 const bool loadRcpp=false, const bool verbose=false, const bool interactive=false); 00085 ~RInside(); 00086 00087 void setVerbose(const bool verbose) { verbose_m = verbose; } 00088 00089 Rcpp::Environment::Binding operator[]( const std::string& name ); 00090 00091 static RInside& instance(); 00092 static RInside* instancePtr(); 00093 00094 #ifdef RINSIDE_CALLBACKS 00095 void set_callbacks(Callbacks* callbacks_) ; 00096 void repl() ; 00097 #endif 00098 00099 }; 00100 00101 #endif