Rcpp Version 1.0.0
routines.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // Copyright (C) 2013 Romain Francois
4 // Copyright (C) 2015 Dirk Eddelbuettel
5 //
6 // This file is part of Rcpp.
7 //
8 // Rcpp is free software: you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // Rcpp is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
20 
21 #ifndef RCPP_ROUTINE_H
22 #define RCPP_ROUTINE_H
23 
24 #if defined(COMPILING_RCPP)
25 
26 // the idea is that this file should be generated automatically by Rcpp::register
27 
28 namespace Rcpp{
29  const char* type2name(SEXP x);
30 
31  namespace internal{
32  unsigned long enterRNGScope();
33  unsigned long exitRNGScope();
34  unsigned long beginSuspendRNGSynchronization();
35  unsigned long endSuspendRNGSynchronization();
36  char* get_string_buffer();
37  SEXP get_Rcpp_namespace();
38  }
39  double mktime00(struct tm &);
40  struct tm * gmtime_(const time_t * const);
41 }
42 
44 SEXP rcpp_set_stack_trace(SEXP);
45 std::string demangle(const std::string& name);
46 const char* short_file_name(const char* );
47 int* get_cache(int n);
48 SEXP stack_trace( const char *file = "", int line = -1);
49 SEXP get_string_elt(SEXP s, R_xlen_t i);
50 const char* char_get_string_elt(SEXP s, R_xlen_t i);
51 void set_string_elt(SEXP s, R_xlen_t i, SEXP v);
52 void char_set_string_elt(SEXP s, R_xlen_t i, const char* v);
53 SEXP* get_string_ptr(SEXP s);
54 SEXP get_vector_elt(SEXP v, R_xlen_t i);
55 void set_vector_elt(SEXP v, R_xlen_t i, SEXP x);
56 SEXP* get_vector_ptr(SEXP v);
57 const char* char_nocheck(SEXP x);
58 void* dataptr(SEXP x);
60 void setCurrentScope( Rcpp::Module* mod );
61 SEXP reset_current_error();
62 int error_occured();
64 // void print(SEXP s);
65 
66 #else
67 
68 namespace Rcpp {
69 
70  #define GET_CALLABLE(__FUN__) (Fun) R_GetCCallable( "Rcpp", __FUN__ )
71 
72  inline attribute_hidden const char* type2name(SEXP x){
73  typedef const char* (*Fun)(SEXP);
74  static Fun fun = GET_CALLABLE("type2name");
75  return fun(x);
76  }
77 
78  namespace internal{
79  inline attribute_hidden unsigned long enterRNGScope(){
80  typedef unsigned long (*Fun)(void);
81  static Fun fun = GET_CALLABLE("enterRNGScope");
82  return fun();
83  }
84 
85  inline attribute_hidden unsigned long exitRNGScope(){
86  typedef unsigned long (*Fun)(void);
87  static Fun fun = GET_CALLABLE("exitRNGScope");
88  return fun();
89  }
90 
91  inline attribute_hidden unsigned long beginSuspendRNGSynchronization(){
92  typedef unsigned long (*Fun)(void);
93  static Fun fun = GET_CALLABLE("beginSuspendRNGSynchronization");
94  return fun();
95  }
96 
97  inline attribute_hidden unsigned long endSuspendRNGSynchronization(){
98  typedef unsigned long (*Fun)(void);
99  static Fun fun = GET_CALLABLE("endSuspendRNGSynchronization");
100  return fun();
101  }
102 
103  inline attribute_hidden char* get_string_buffer(){
104  typedef char* (*Fun)(void);
105  static Fun fun = GET_CALLABLE("get_string_buffer");
106  return fun();
107  }
108 
109  inline attribute_hidden SEXP get_Rcpp_namespace() {
110  typedef SEXP (*Fun)(void);
111  static Fun fun = GET_CALLABLE("get_Rcpp_namespace");
112  return fun();
113  }
114 
115  }
116 
117 
118  inline attribute_hidden double mktime00(struct tm &tm){
119  typedef double (*Fun)(struct tm&);
120  static Fun fun = GET_CALLABLE("mktime00");
121  return fun(tm);
122  }
123 
124  inline attribute_hidden struct tm * gmtime_(const time_t * const x){
125  typedef struct tm* (*Fun)(const time_t* const);
126  static Fun fun = GET_CALLABLE("gmtime_");
127  return fun(x);
128  }
129 
130 }
131 
132 // The 'attribute_hidden' used here is a simple precessor defined from
133 // ${R_HOME}/include/R_ext/Visibility.h -- it is empty when not supported
134 // by the compiler and otherwise '__attribute__ ((visibility ("hidden")))'
135 
136 inline attribute_hidden SEXP rcpp_get_stack_trace(){
137  typedef SEXP (*Fun)(void);
138  static Fun fun = GET_CALLABLE("rcpp_get_stack_trace");
139  return fun();
140 }
141 
142 inline attribute_hidden SEXP rcpp_set_stack_trace(SEXP e){
143  typedef SEXP (*Fun)(SEXP);
144  static Fun fun = GET_CALLABLE("rcpp_set_stack_trace");
145  return fun(e);
146 }
147 
148 inline attribute_hidden std::string demangle( const std::string& name){
149  typedef std::string (*Fun)( const std::string& );
150  static Fun fun = GET_CALLABLE("demangle");
151  return fun(name);
152 }
153 
154 inline attribute_hidden const char* short_file_name(const char* file) {
155  typedef const char* (*Fun)(const char*);
156  static Fun fun = GET_CALLABLE("short_file_name");
157  return fun(file);
158 }
159 
160 inline attribute_hidden SEXP stack_trace( const char *file = "", int line = -1){
161  typedef SEXP (*Fun)(const char*, int);
162  static Fun fun = GET_CALLABLE("stack_trace");
163  return fun(file, line);
164 }
165 
166 inline attribute_hidden SEXP get_string_elt(SEXP s, R_xlen_t i){
167  typedef SEXP (*Fun)(SEXP, R_xlen_t);
168  static Fun fun = GET_CALLABLE("get_string_elt");
169  return fun(s, i);
170 }
171 
172 inline attribute_hidden const char* char_get_string_elt(SEXP s, R_xlen_t i){
173  typedef const char* (*Fun)(SEXP, R_xlen_t);
174  static Fun fun = GET_CALLABLE("char_get_string_elt");
175  return fun(s, i);
176 }
177 
178 inline attribute_hidden void set_string_elt(SEXP s, R_xlen_t i, SEXP v){
179  typedef void (*Fun)(SEXP, R_xlen_t, SEXP);
180  static Fun fun = GET_CALLABLE("set_string_elt");
181  fun(s, i, v);
182 }
183 
184 inline attribute_hidden void char_set_string_elt(SEXP s, R_xlen_t i, const char* v){
185  typedef void (*Fun)(SEXP, R_xlen_t, const char*);
186  static Fun fun = GET_CALLABLE("char_set_string_elt");
187  fun(s, i, v );
188 }
189 
190 inline attribute_hidden SEXP* get_string_ptr(SEXP s){
191  typedef SEXP* (*Fun)(SEXP);
192  static Fun fun = GET_CALLABLE("get_string_ptr");
193  return fun(s);
194 }
195 
196 inline attribute_hidden SEXP get_vector_elt(SEXP v, R_xlen_t i){
197  typedef SEXP (*Fun)(SEXP, R_xlen_t);
198  static Fun fun = GET_CALLABLE("get_vector_elt");
199  return fun(v, i);
200 }
201 
202 inline attribute_hidden void set_vector_elt(SEXP v, R_xlen_t i, SEXP x){
203  typedef void (*Fun)(SEXP, R_xlen_t, SEXP);
204  static Fun fun = GET_CALLABLE("set_vector_elt");
205  fun(v, i, x);
206 }
207 
208 inline attribute_hidden SEXP* get_vector_ptr(SEXP v){
209  typedef SEXP* (*Fun)(SEXP);
210  static Fun fun = GET_CALLABLE("get_vector_ptr");
211  return fun(v);
212 }
213 
214 inline attribute_hidden const char* char_nocheck( SEXP x){
215  typedef const char* (*Fun)(SEXP);
216  static Fun fun = GET_CALLABLE("char_nocheck");
217  return fun(x);
218 }
219 
220 inline attribute_hidden void* dataptr(SEXP x){
221  typedef void* (*Fun)(SEXP);
222  static Fun fun = GET_CALLABLE("dataptr");
223  return fun(x);
224 }
225 
226 inline attribute_hidden Rcpp::Module* getCurrentScope(){
227  typedef Rcpp::Module* (*Fun)(void);
228  static Fun fun = GET_CALLABLE("getCurrentScope");
229  return fun();
230 }
231 
232 inline attribute_hidden void setCurrentScope( Rcpp::Module* mod ){
233  typedef void (*Fun)(Rcpp::Module*);
234  static Fun fun = GET_CALLABLE("setCurrentScope");
235  fun(mod);
236 }
237 
238 inline attribute_hidden int* get_cache( int n ){
239  typedef int* (*Fun)(int);
240  static Fun fun = GET_CALLABLE("get_cache");
241  return fun(n);
242 }
243 
244 inline attribute_hidden SEXP reset_current_error(){
245  typedef SEXP (*Fun)(void);
246  static Fun fun = GET_CALLABLE("reset_current_error");
247  return fun();
248 }
249 
250 inline attribute_hidden int error_occured(){
251  typedef int (*Fun)(void);
252  static Fun fun = GET_CALLABLE("error_occured");
253  return fun();
254 }
255 
256 inline attribute_hidden SEXP rcpp_get_current_error(){
257  typedef SEXP (*Fun)(void);
258  static Fun fun = GET_CALLABLE("rcpp_get_current_error");
259  return fun();
260 }
261 
262 // inline attribute_hidden void print(SEXP s) {
263 // typedef void (*Fun)(SEXP);
264 // static Fun fun = GET_CALLABLE("print");
265 // fun(s);
266 // }
267 
268 #endif
269 
270 
271 #endif
attribute_hidden void setCurrentScope(Rcpp::Module *mod)
Definition: routines.h:232
attribute_hidden SEXP * get_vector_ptr(SEXP v)
Definition: routines.h:208
attribute_hidden double mktime00(struct tm &tm)
Definition: routines.h:118
attribute_hidden SEXP stack_trace(const char *file="", int line=-1)
Definition: routines.h:160
attribute_hidden SEXP * get_string_ptr(SEXP s)
Definition: routines.h:190
attribute_hidden SEXP get_vector_elt(SEXP v, R_xlen_t i)
Definition: routines.h:196
attribute_hidden void set_string_elt(SEXP s, R_xlen_t i, SEXP v)
Definition: routines.h:178
attribute_hidden SEXP get_string_elt(SEXP s, R_xlen_t i)
Definition: routines.h:166
attribute_hidden std::string demangle(const std::string &name)
Definition: routines.h:148
attribute_hidden SEXP reset_current_error()
Definition: routines.h:244
attribute_hidden void set_vector_elt(SEXP v, R_xlen_t i, SEXP x)
Definition: routines.h:202
attribute_hidden void char_set_string_elt(SEXP s, R_xlen_t i, const char *v)
Definition: routines.h:184
attribute_hidden SEXP rcpp_get_current_error()
Definition: routines.h:256
#define GET_CALLABLE(__FUN__)
Definition: routines.h:70
attribute_hidden const char * char_nocheck(SEXP x)
Definition: routines.h:214
attribute_hidden unsigned long endSuspendRNGSynchronization()
Definition: routines.h:97
attribute_hidden unsigned long exitRNGScope()
Definition: routines.h:85
attribute_hidden SEXP rcpp_set_stack_trace(SEXP e)
Definition: routines.h:142
attribute_hidden const char * type2name(SEXP x)
Definition: routines.h:72
attribute_hidden void * dataptr(SEXP x)
Definition: routines.h:220
attribute_hidden int * get_cache(int n)
Definition: routines.h:238
attribute_hidden struct tm * gmtime_(const time_t *const x)
Definition: routines.h:124
attribute_hidden unsigned long beginSuspendRNGSynchronization()
Definition: routines.h:91
attribute_hidden Rcpp::Module * getCurrentScope()
Definition: routines.h:226
attribute_hidden int error_occured()
Definition: routines.h:250
attribute_hidden unsigned long enterRNGScope()
Definition: routines.h:79
attribute_hidden char * get_string_buffer()
Definition: routines.h:103
attribute_hidden SEXP rcpp_get_stack_trace()
Definition: routines.h:136
attribute_hidden SEXP get_Rcpp_namespace()
Definition: routines.h:109
Rcpp API.
Definition: algo.h:28
static struct tm tm
Definition: Date.cpp:437
attribute_hidden const char * short_file_name(const char *file)
Definition: routines.h:154
attribute_hidden const char * char_get_string_elt(SEXP s, R_xlen_t i)
Definition: routines.h:172