|
Rcpp Version 0.9.10
|
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 // 00003 // RcppCommon.h: Rcpp R/C++ interface class library -- common include and defines statements 00004 // 00005 // Copyright (C) 2008 - 2009 Dirk Eddelbuettel 00006 // Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois 00007 // 00008 // This file is part of Rcpp. 00009 // 00010 // Rcpp is free software: you can redistribute it and/or modify it 00011 // under the terms of the GNU General Public License as published by 00012 // the Free Software Foundation, either version 2 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // Rcpp is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU General Public License 00021 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>. 00022 00023 #ifndef RcppCommon_h 00024 #define RcppCommon_h 00025 00026 #undef GOOD_COMPILER_FOR_RCPP 00027 #ifdef __GNUC__ 00028 #define GOOD_COMPILER_FOR_RCPP 00029 #endif 00030 #ifdef __SUNPRO_CC 00031 #define GOOD_COMPILER_FOR_RCPP 00032 #endif 00033 #ifdef __clang__ 00034 #define GOOD_COMPILER_FOR_RCPP 00035 #endif 00036 #ifdef __INTEL_COMPILER 00037 #define GOOD_COMPILER_FOR_RCPP 00038 #endif 00039 00040 #ifndef GOOD_COMPILER_FOR_RCPP 00041 # error "This compiler is not supported" 00042 #endif 00043 00044 #include <Rcpp/config.h> 00045 #include <Rcpp/macros/unroll.h> 00046 00047 void logTxtFunction(const char* file, const int line, const char* expression ) ; 00048 00052 namespace Rcpp{ 00053 00057 namespace traits{ 00058 } // traits 00059 00063 namespace internal{ 00064 } // internal 00065 } // Rcpp 00066 00067 #ifdef __GNUC__ 00068 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 00069 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00070 #define HAS_CXX0X 00071 #if GCC_VERSION >= 40300 00072 #define HAS_VARIADIC_TEMPLATES 00073 #endif 00074 #if GCC_VERSION >= 40400 00075 #define HAS_INIT_LISTS 00076 #endif 00077 #endif 00078 // FIXME: [romain] I did not actually check, tr1::unordered_map was 00079 // probably introduced before GCC 4.2.1 00080 #if GCC_VERSION >= 40201 00081 #define HAS_TR1 00082 #define HAS_TR1_UNORDERED_MAP 00083 #define HAS_TR1_UNORDERED_SET 00084 #endif 00085 // g++ 4.5 does not seem to like some of the fast indexing 00086 #if GCC_VERSION >= 40500 00087 #define IS_GCC_450_OR_LATER 00088 #endif 00089 // g++ 4.6 no longer has exception_defines.h so need a flag for that 00090 #if GCC_VERSION < 40600 00091 #define IS_EARLIER_THAN_GCC_460 00092 #endif 00093 #endif 00094 00095 #ifdef __INTEL_COMPILER 00096 // This is based on an email by Alexey Stukalov who tested 00097 // Intel Compiler 12.0 and states that is does support Cxx0x 00098 // or even TR1 (by default; maybe there are options?) 00099 #undef HAS_VARIADIC_TEMPLATES 00100 #undef HAS_TR1 00101 #undef HAS_TR1_UNORDERED_MAP 00102 #undef HAS_TR1_UNORDERED_SET 00103 #endif 00104 00105 00106 #include <iterator> 00107 #include <exception> 00108 #include <iostream> 00109 #include <sstream> 00110 #include <string> 00111 #include <list> 00112 #include <map> 00113 #include <set> 00114 #include <stdexcept> 00115 #include <vector> 00116 #include <deque> 00117 #include <functional> 00118 #include <numeric> 00119 #include <algorithm> 00120 #include <complex> 00121 #include <limits.h> 00122 #include <typeinfo> 00123 #include <Rcpp/sprintf.h> 00124 00125 #ifdef HAS_INIT_LISTS 00126 #include <initializer_list> 00127 #endif 00128 00129 #ifdef HAS_TR1_UNORDERED_MAP 00130 #include <tr1/unordered_map> 00131 #endif 00132 00133 #ifdef HAS_TR1_UNORDERED_SET 00134 #include <tr1/unordered_set> 00135 #endif 00136 00137 std::string demangle( const std::string& name) ; 00138 #define DEMANGLE(__TYPE__) demangle( typeid(__TYPE__).name() ).c_str() 00139 00140 // include R headers, but set R_NO_REMAP and access everything via Rf_ prefixes 00141 #define R_NO_REMAP 00142 #include <R.h> 00143 #include <Rinternals.h> 00144 #include <R_ext/Callbacks.h> 00145 #include <R_ext/Complex.h> 00146 #include <R_ext/Parse.h> 00147 #include <R_ext/Rdynload.h> 00148 #include <Rversion.h> 00149 #define RCPP_GET_NAMES(x) Rf_getAttrib(x, R_NamesSymbol) 00150 00151 inline SEXP Rcpp_lcons(SEXP car, SEXP cdr){ 00152 PROTECT(car) ; 00153 car = Rf_lcons( car, cdr ) ; 00154 UNPROTECT(1) ; 00155 return car ; 00156 } 00157 #include <Rcpp/lang.h> 00158 00159 #include <Rcpp/complex.h> 00160 00161 #include <Rcpp/barrier.h> 00162 00163 #define RcppExport extern "C" 00164 00165 #include <Rcpp/internal/posixt.h> 00166 00167 RcppExport void init_Rcpp_routines(DllInfo*) ; 00168 00169 namespace Rcpp{ 00170 namespace internal{ 00171 template <typename T> int rcpp_call_test(T t){ 00172 return T::r_type::value ; 00173 } 00174 int rcpp_call_test_(SEXP) ; 00175 } 00176 } 00177 00178 extern "C" SEXP rcpp_call_test(SEXP x) ; 00179 00180 /* in exceptions.cpp */ 00181 void forward_uncaught_exceptions_to_r() ; 00182 void forward_exception_to_r( const std::exception& ) ; 00183 RcppExport SEXP initUncaughtExceptionHandler() ; 00184 00185 /* just testing variadic templates */ 00186 #ifdef HAS_VARIADIC_TEMPLATES 00187 template<typename... Args> 00188 int variadic_length( const Args&... args) { return sizeof...(Args) ; } 00189 #endif 00190 00191 #ifdef HAS_VARIADIC_TEMPLATES 00192 RcppExport inline SEXP canUseCXX0X(){ return Rf_ScalarLogical( TRUE ); } 00193 #else 00194 RcppExport inline SEXP canUseCXX0X(){ return Rf_ScalarLogical( FALSE ); } 00195 #endif 00196 00197 RcppExport SEXP test_named() ; 00198 RcppExport SEXP capabilities() ; 00199 00200 const char * sexp_to_name(int sexp_type); 00201 00202 #include <Rcpp/exceptions.h> 00203 00204 namespace Rcpp{ 00205 /* internal namespace for things not intended to be used by the user */ 00206 namespace internal{ 00207 00208 /* defined in Evaluator.cpp */ 00209 SEXP convert_using_rfunction(SEXP x, const char* const fun); 00210 00211 SEXP try_catch( SEXP expr, SEXP env ); 00212 SEXP try_catch( SEXP expr ); 00213 00214 } // namespace internal 00215 00216 inline bool Rboolean_to_bool( int x){ return x == TRUE ; } 00217 inline bool int_to_bool(int x){ return x != 0 ; } 00218 inline bool double_to_bool(double x){ return x != 0.0 ; } 00219 inline bool Rbyte_to_bool(Rbyte x){ return x != static_cast<Rbyte>(0) ; } 00220 00221 } // namespace Rcpp 00222 00223 // simple logging help 00224 #define RCPP_DEBUG_LEVEL 0 00225 00226 #ifndef logTxt 00227 #if RCPP_DEBUG_LEVEL > 0 00228 #define logTxt(x) ::logTxtFunction(__FILE__, __LINE__, x); 00229 #else 00230 #define logTxt(x) 00231 #endif 00232 #endif 00233 00234 #if RCPP_DEBUG_LEVEL > 0 00235 #define RCPP_DEBUG( MSG ) Rprintf( "%s:%d %s\n" , __FILE__, __LINE__, MSG ) ; 00236 #define RCPP_DEBUG_1( fmt, MSG ) Rprintf( "%s:%d " fmt "\n" , __FILE__, __LINE__, MSG ) ; 00237 #define RCPP_DEBUG_2( fmt, M1, M2 ) Rprintf( "%s:%d" fmt "\n" , __FILE__, __LINE__, M1, M2 ) ; 00238 #define RCPP_DEBUG_3( fmt, M1, M2, M3 ) Rprintf( "%s:%d" fmt "\n" , __FILE__, __LINE__, M1, M2, M3) ; 00239 #else 00240 #define RCPP_DEBUG( MSG ) 00241 #define RCPP_DEBUG_1( fmt, MSG ) 00242 #define RCPP_DEBUG_2( fmt, M1, M2 ) 00243 #define RCPP_DEBUG_3( fmt, M1, M2, M3 ) 00244 #endif 00245 00246 SEXP stack_trace( const char *file, int line) ; 00247 #define GET_STACKTRACE() stack_trace( __FILE__, __LINE__ ) 00248 #define Rcpp_error(MESSAGE) throw new Rcpp::exception( MESSAGE, __FILE__, __LINE__ ) 00249 00250 #if RCPP_DEBUG_LEVEL > 0 00251 #include <typeinfo> 00252 #endif 00253 00254 #ifdef __GNUC__ 00255 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00256 #ifdef LONG_LONG_MAX 00257 __extension__ typedef long long int rcpp_long_long_type; 00258 __extension__ typedef unsigned long long int rcpp_ulong_long_type; 00259 #define RCPP_HAS_LONG_LONG_TYPES 00260 #endif 00261 #endif 00262 #endif 00263 00264 // DO NOT CHANGE THE ORDER OF THESE INCLUDES 00265 #include <Rcpp/traits/integral_constant.h> 00266 #include <Rcpp/traits/same_type.h> 00267 #include <Rcpp/traits/named_object.h> 00268 #include <Rcpp/Named.h> 00269 #include <Rcpp/traits/is_convertible.h> 00270 #include <Rcpp/traits/has_iterator.h> 00271 #include <Rcpp/traits/expands_to_logical.h> 00272 #include <Rcpp/traits/matrix_interface.h> 00273 #include <Rcpp/traits/is_sugar_expression.h> 00274 #include <Rcpp/traits/is_eigen_base.h> 00275 #include <Rcpp/traits/has_na.h> 00276 #include <Rcpp/traits/storage_type.h> 00277 #include <Rcpp/traits/r_sexptype_traits.h> 00278 #include <Rcpp/traits/storage_type.h> 00279 #include <Rcpp/traits/r_type_traits.h> 00280 #include <Rcpp/traits/wrap_type_traits.h> 00281 #include <Rcpp/traits/is_na.h> 00282 #include <Rcpp/traits/if_.h> 00283 #include <Rcpp/traits/get_na.h> 00284 #include <Rcpp/traits/is_trivial.h> 00285 #include <Rcpp/traits/init_type.h> 00286 00287 #include <Rcpp/traits/is_const.h> 00288 #include <Rcpp/traits/is_reference.h> 00289 #include <Rcpp/traits/remove_const.h> 00290 #include <Rcpp/traits/remove_reference.h> 00291 #include <Rcpp/traits/remove_const_and_reference.h> 00292 #include <Rcpp/traits/result_of.h> 00293 00294 #include <Rcpp/Generator.h> 00295 00296 #include <Rcpp/internal/caster.h> 00297 #include <Rcpp/internal/r_vector.h> 00298 #include <Rcpp/r_cast.h> 00299 00300 #include <Rcpp/internal/wrap_forward.h> 00301 00302 #include <Rcpp/Date_forward.h> 00303 #include <Rcpp/Datetime_forward.h> 00304 00305 #include <Rcpp/internal/export.h> 00306 #include <Rcpp/traits/Exporter.h> 00307 #include <Rcpp/internal/r_coerce.h> 00308 #include <Rcpp/as.h> 00309 00310 #include <Rcpp/vector/VectorBase.h> 00311 #include <Rcpp/vector/MatrixBase.h> 00312 00313 #include <Rcpp/internal/wrap.h> 00314 00315 #include <Rcpp/internal/ListInitialization.h> 00316 #include <Rcpp/internal/Proxy_Iterator.h> 00317 00318 RcppExport SEXP RcppXPtrExample_create_external_pointer() ; 00319 RcppExport SEXP RcppXPtrExample_get_external_pointer(SEXP ); 00320 00321 #include <Rcpp/preprocessor.h> 00322 #include <Rcpp/algo.h> 00323 00324 #include <Rcpp/sugar/sugar_forward.h> 00325 00326 #include <Rcpp/routines.h> 00327 #include <Rcpp/cache.h> 00328 00329 // "Rcout" iostream class contributed by Jelmer Ypma 00330 #include <Rcpp/iostream/Rstreambuf.h> 00331 #include <Rcpp/iostream/Rostream.h> 00332 00333 #endif