Rcpp Version 0.12.12
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::exception& __ex__) { \
45  rcpp_output_type = 2 ; \
46  rcpp_output_condition = PROTECT(rcpp_exception_to_r_condition(__ex__)) ; \
47  } \
48  catch( std::exception& __ex__ ){ \
49  rcpp_output_type = 2 ; \
50  rcpp_output_condition = PROTECT(exception_to_r_condition(__ex__)) ; \
51  } \
52  catch( ... ){ \
53  rcpp_output_type = 2 ; \
54  rcpp_output_condition = PROTECT(string_to_try_error("c++ exception (unknown reason)")) ; \
55  } \
56  if( rcpp_output_type == 1 ){ \
57  Rf_onintr() ; \
58  } \
59  if( rcpp_output_type == 2 ){ \
60  SEXP stop_sym = Rf_install( "stop" ) ; \
61  SEXP expr = PROTECT( Rf_lang2( stop_sym , rcpp_output_condition ) ) ; \
62  Rf_eval( expr, R_GlobalEnv ) ; \
63  }
64 #endif
65 
66 #ifndef END_RCPP
67 #define END_RCPP VOID_END_RCPP return R_NilValue;
68 #endif
69 
70 #ifndef END_RCPP_RETURN_ERROR
71 #define END_RCPP_RETURN_ERROR \
72  } \
73  catch (Rcpp::internal::InterruptedException &__ex__) { \
74  return Rcpp::internal::interruptedError(); \
75  } \
76  catch (std::exception &__ex__) { \
77  return exception_to_try_error(__ex__); \
78  } \
79  catch (...) { \
80  return string_to_try_error("c++ exception (unknown reason)"); \
81  } \
82  return R_NilValue;
83 #endif
84 
85 #define Rcpp_error(MESSAGE) throw Rcpp::exception(MESSAGE, __FILE__, __LINE__)
86 
87 #include <Rcpp/macros/debug.h>
88 #include <Rcpp/macros/unroll.h>
89 #include <Rcpp/macros/dispatch.h>
90 #include <Rcpp/macros/xp.h>
91 #include <Rcpp/macros/traits.h>
92 #include <Rcpp/macros/config.hpp>
93 #include <Rcpp/macros/cat.hpp>
94 #include <Rcpp/macros/module.h>
95 #include <Rcpp/macros/interface.h>
96 
97 #endif