Rcpp Version 1.0.0
macros.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 // macros.h: Rcpp R/C++ interface class library -- Rcpp macros
4 //
5 // Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef Rcpp_macros_macros_h
23 #define Rcpp_macros_macros_h
24 
25 #define RCPP_DECORATE(__FUN__) __FUN__##__rcpp__wrapper__
26 #define RCPP_GET_NAMES(x) Rf_getAttrib(x, R_NamesSymbol)
27 #define RCPP_GET_CLASS(x) Rf_getAttrib(x, R_ClassSymbol)
28 
29 #ifndef BEGIN_RCPP
30 #define BEGIN_RCPP \
31  int rcpp_output_type = 0 ; \
32  (void)rcpp_output_type; \
33  SEXP rcpp_output_condition = R_NilValue ; \
34  (void)rcpp_output_condition; \
35  try {
36 #endif
37 
38 #ifndef VOID_END_RCPP
39 #define VOID_END_RCPP \
40  } \
41  catch( Rcpp::internal::InterruptedException &__ex__) { \
42  rcpp_output_type = 1 ; \
43  } \
44  catch (Rcpp::LongjumpException& __ex__) { \
45  rcpp_output_type = 3 ; \
46  rcpp_output_condition = __ex__.token; \
47  } \
48  catch(Rcpp::exception& __ex__) { \
49  rcpp_output_type = 2 ; \
50  rcpp_output_condition = PROTECT(rcpp_exception_to_r_condition(__ex__)) ; \
51  } \
52  catch( std::exception& __ex__ ){ \
53  rcpp_output_type = 2 ; \
54  rcpp_output_condition = PROTECT(exception_to_r_condition(__ex__)) ; \
55  } \
56  catch( ... ){ \
57  rcpp_output_type = 2 ; \
58  rcpp_output_condition = PROTECT(string_to_try_error("c++ exception (unknown reason)")) ; \
59  } \
60  if( rcpp_output_type == 1 ){ \
61  Rf_onintr() ; \
62  } \
63  if( rcpp_output_type == 2 ){ \
64  SEXP stop_sym = Rf_install( "stop" ) ; \
65  SEXP expr = PROTECT( Rf_lang2( stop_sym , rcpp_output_condition ) ) ; \
66  Rf_eval( expr, R_GlobalEnv ) ; \
67  } \
68  if (rcpp_output_type == 3) { \
69  Rcpp::internal::resumeJump(rcpp_output_condition); \
70  }
71 #endif
72 
73 #ifndef END_RCPP
74 #define END_RCPP VOID_END_RCPP return R_NilValue;
75 #endif
76 
77 
78 // There is no return in case of a longjump exception
79 
80 #ifndef END_RCPP_RETURN_ERROR
81 #define END_RCPP_RETURN_ERROR \
82  } \
83  catch (Rcpp::internal::InterruptedException &__ex__) { \
84  return Rcpp::internal::interruptedError(); \
85  } \
86  catch (Rcpp::LongjumpException& __ex__) { \
87  return Rcpp::internal::longjumpSentinel(__ex__.token); \
88  } \
89  catch (std::exception &__ex__) { \
90  return exception_to_try_error(__ex__); \
91  } \
92  catch (...) { \
93  return string_to_try_error("c++ exception (unknown reason)"); \
94  } \
95  return R_NilValue;
96 #endif
97 
98 #define Rcpp_error(MESSAGE) throw Rcpp::exception(MESSAGE, __FILE__, __LINE__)
99 
100 #include <Rcpp/macros/debug.h>
101 #include <Rcpp/macros/unroll.h>
102 #include <Rcpp/macros/dispatch.h>
103 #include <Rcpp/macros/xp.h>
104 #include <Rcpp/macros/traits.h>
105 #include <Rcpp/macros/config.hpp>
106 #include <Rcpp/macros/cat.hpp>
107 #include <Rcpp/macros/module.h>
108 #include <Rcpp/macros/interface.h>
109 
110 #endif