RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RInside.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
2 //
3 // RInside.h: R/C++ interface class library -- Easier R embedding into C++
4 //
5 // Copyright (C) 2009 Dirk Eddelbuettel
6 // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
7 //
8 // This file is part of RInside.
9 //
10 // RInside is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 2 of the License, or
13 // (at your option) any later version.
14 //
15 // RInside is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with RInside. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef RINSIDE_RINSIDE_H
24 #define RINSIDE_RINSIDE_H
25 
26 #include <RInsideCommon.h>
27 #include <Callbacks.h>
28 
29 class RInside {
30 private:
32  Rcpp::Environment* global_env_m;
33 
34  bool verbose_m; // switch toggled by constructor, or setter
35  bool interactive_m; // switch set by constructor only
36 
37  void init_tempdir(void);
38  void init_rand(void);
39  void autoloads(void);
40 
41  void initialize(const int argc, const char* const argv[],
42  const bool loadRcpp, const bool verbose, const bool interactive);
43 
44  static RInside* instance_m ;
45 
46 #ifdef RINSIDE_CALLBACKS
47  Callbacks* callbacks ;
48  friend void RInside_ShowMessage( const char* message);
49  friend void RInside_WriteConsoleEx( const char* message, int len, int oType );
50  friend int RInside_ReadConsole(const char *prompt, unsigned char *buf, int len, int addtohistory);
51  friend void RInside_ResetConsole();
52  friend void RInside_FlushConsole();
53  friend void RInside_ClearerrConsole();
54  friend void RInside_Busy(int which);
55 #endif
56 
57 public:
58 
59  class Proxy {
60  public:
61  Proxy(SEXP xx): x(xx) { };
62 
63  template <typename T>
64  operator T() {
65  return ::Rcpp::as<T>(x);
66  }
67  private:
68  Rcpp::RObject x;
69  };
70 
71  int parseEval(const std::string &line, SEXP &ans); // parse line, return in ans; error code rc
72  void parseEvalQ(const std::string &line); // parse line, no return (throws on error)
73  void parseEvalQNT(const std::string &line); // parse line, no return (no throw)
74  Proxy parseEval(const std::string &line); // parse line, return SEXP (throws on error)
75  Proxy parseEvalNT(const std::string &line); // parse line, return SEXP (no throw)
76 
77  template <typename T>
78  void assign(const T& object, const std::string& nam) {
79  global_env_m->assign( nam, object ) ;
80  }
81 
82  RInside() ;
83  RInside(const int argc, const char* const argv[],
84  const bool loadRcpp=true, // overridden in code, cannot be set to false
85  const bool verbose=false, const bool interactive=false);
86  ~RInside();
87 
88  void setVerbose(const bool verbose) { verbose_m = verbose; }
89 
90  Rcpp::Environment::Binding operator[]( const std::string& name );
91 
92  static RInside& instance();
93  static RInside* instancePtr();
94 
95 #ifdef RINSIDE_CALLBACKS
96  void set_callbacks(Callbacks* callbacks_) ;
97  void repl() ;
98 #endif
99 
100 };
101 
102 #endif
RInside()
Definition: RInside.cpp:49
void autoloads(void)
Definition: RInside.cpp:221
void setVerbose(const bool verbose)
Definition: RInside.h:88
bool interactive_m
Definition: RInside.h:35
~RInside()
Definition: RInside.cpp:36
Rcpp::Environment::Binding operator[](const std::string &name)
Definition: RInside.cpp:394
MemBuf mb_m
Definition: RInside.h:31
Definition: MemBuf.h:23
bool verbose_m
Definition: RInside.h:34
void parseEvalQ(const std::string &line)
Definition: RInside.cpp:366
static RInside * instancePtr()
Definition: RInside.cpp:402
static RInside * instance_m
Definition: RInside.h:44
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308
Proxy parseEvalNT(const std::string &line)
Definition: RInside.cpp:388
void parseEvalQNT(const std::string &line)
Definition: RInside.cpp:374
void initialize(const int argc, const char *const argv[], const bool loadRcpp, const bool verbose, const bool interactive)
Definition: RInside.cpp:101
Rcpp::Environment * global_env_m
Definition: RInside.h:32
void assign(const T &object, const std::string &nam)
Definition: RInside.h:78
bool verbose
static RInside & instance()
Definition: RInside.cpp:398
void init_rand(void)
Definition: RInside.cpp:212
Proxy(SEXP xx)
Definition: RInside.h:61
void init_tempdir(void)
Definition: RInside.cpp:194
Rcpp::RObject x
Definition: RInside.h:68