|
| 1 | +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*- |
| 2 | +// |
| 3 | +// longlong.h: Rcpp R/C++ interface class library -- long long support |
| 4 | +// |
| 5 | +// Copyright (C) 2013 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_LONG_LONG_H |
| 23 | +#define RCPP_LONG_LONG_H |
| 24 | + |
| 25 | +// long long and unssigned long long support. |
| 26 | +// |
| 27 | +// given the current restriction of what might go to CRAN |
| 28 | +// we can only use long long if we are running a gcc compatible (e.g. clang) |
| 29 | +// compiler and the type is actually available (hence the test for __LONG_LONG_MAX__) |
| 30 | +// even then, we cannot use long long as is, we first have to "hide" it |
| 31 | +// behind the __extension__ so that -pedantic stops giving warnings about |
| 32 | +// compliance with C++98 |
| 33 | +// |
| 34 | +// client code may use the facilities we provide for long long (wrap, etc ...) |
| 35 | +// but not using long long directly, because then it is not CRAN proof. |
| 36 | +// So client code must use the rcpp_long_long_type and rcpp_ulong_long_type |
| 37 | +// types |
| 38 | +// |
| 39 | +// e.g. code like this is not good: |
| 40 | +// |
| 41 | +// long long x = 2 ; |
| 42 | +// |
| 43 | +// but code like this is CRAN proof |
| 44 | +// |
| 45 | +// rcpp_long_long_type x = 2 ; |
| 46 | +// |
| 47 | +// Note that if you don't distribute your code to CRAN and you don't use the |
| 48 | +// -pedantic option, then you can use long long |
| 49 | +#if defined(__GNUC__) && defined(__LONG_LONG_MAX__) |
| 50 | + __extension__ typedef long long int rcpp_long_long_type; |
| 51 | + __extension__ typedef unsigned long long int rcpp_ulong_long_type; |
| 52 | + #define RCPP_HAS_LONG_LONG_TYPES |
| 53 | +#endif |
| 54 | + |
| 55 | +#if defined(RCPP_HAS_LONG_LONG_TYPES) |
| 56 | + |
| 57 | +namespace Rcpp{ |
| 58 | +namespace traits{ |
| 59 | + |
| 60 | + template<> struct r_sexptype_traits<rcpp_long_long_type>{ enum{ rtype = REALSXP } ; } ; |
| 61 | + template<> struct r_sexptype_traits<rcpp_ulong_long_type>{ enum{ rtype = REALSXP } ; } ; |
| 62 | + |
| 63 | + template<> struct r_type_traits<rcpp_long_long_type>{ typedef r_type_primitive_tag r_category ; } ; |
| 64 | + template<> struct r_type_traits< std::pair<const std::string,rcpp_long_long_type> >{ typedef r_type_primitive_tag r_category ; } ; |
| 65 | + template<> struct r_type_traits<rcpp_ulong_long_type>{ typedef r_type_primitive_tag r_category ; } ; |
| 66 | + template<> struct r_type_traits< std::pair<const std::string,rcpp_ulong_long_type> >{ typedef r_type_primitive_tag r_category ; } ; |
| 67 | + |
| 68 | + template <> struct wrap_type_traits<rcpp_long_long_type> { typedef wrap_type_primitive_tag wrap_category; } ; |
| 69 | + template <> struct wrap_type_traits<rcpp_ulong_long_type> { typedef wrap_type_primitive_tag wrap_category; } ; |
| 70 | +} |
| 71 | +} |
| 72 | +#endif |
| 73 | + |
| 74 | + |
| 75 | +#endif |
0 commit comments