RInside Version 0.2.16
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 - 2017 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  void repl();
96 
97 #ifdef RINSIDE_CALLBACKS
98  void set_callbacks(Callbacks* callbacks_) ;
99 #endif
100 
101 };
102 
103 #endif
RInside()
Definition: RInside.cpp:56
void autoloads(void)
Definition: RInside.cpp:239
void setVerbose(const bool verbose)
Definition: RInside.h:88
bool interactive_m
Definition: RInside.h:35
~RInside()
Definition: RInside.cpp:43
Rcpp::Environment::Binding operator[](const std::string &name)
Definition: RInside.cpp:412
MemBuf mb_m
Definition: RInside.h:31
void repl()
Definition: RInside.cpp:424
Definition: MemBuf.h:23
bool verbose_m
Definition: RInside.h:34
void parseEvalQ(const std::string &line)
Definition: RInside.cpp:384
static RInside * instancePtr()
Definition: RInside.cpp:420
static RInside * instance_m
Definition: RInside.h:44
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:326
Proxy parseEvalNT(const std::string &line)
Definition: RInside.cpp:406
void parseEvalQNT(const std::string &line)
Definition: RInside.cpp:392
void initialize(const int argc, const char *const argv[], const bool loadRcpp, const bool verbose, const bool interactive)
Definition: RInside.cpp:108
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:416
void init_rand(void)
Definition: RInside.cpp:230
Proxy(SEXP xx)
Definition: RInside.h:61
void init_tempdir(void)
Definition: RInside.cpp:212
Rcpp::RObject x
Definition: RInside.h:68