Skip to content

Commit b07f27b

Browse files
isolate handling of long long in a separate file. We might choose not to include this file by default
1 parent 0e745af commit b07f27b

File tree

7 files changed

+82
-50
lines changed

7 files changed

+82
-50
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2013-09-20 Romain Francois <romain@r-enthusiasts.com>
2+
3+
* include/Rcpp/longlong.h: isolate all handling of long long
4+
in a separate file which we might choose not to include by default
5+
16
2013-09-19 Romain Francois <romain@r-enthusiasts.com>
27

38
* include/Rcpp/traits/r_sexptype_traits.h : unsigned int wrapped as REALSXP

inst/include/Rcpp/longlong.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

inst/include/Rcpp/platform/compiler.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -177,34 +177,4 @@
177177
#define RCPP_HAS_DEMANGLING
178178
#endif
179179

180-
// long long and unssigned long long support.
181-
//
182-
// given the current restriction of what might go to CRAN
183-
// we can only use long long if we are running a gcc compatible (e.g. clang)
184-
// compiler and the type is actually available (hence the test for __LONG_LONG_MAX__)
185-
// even then, we cannot use long long as is, we first have to "hide" it
186-
// behind the __extension__ so that -pedantic stops giving warnings about
187-
// compliance with C++98
188-
//
189-
// client code may use the facilities we provide for long long (wrap, etc ...)
190-
// but not using long long directly, because then it is not CRAN proof.
191-
// So client code must use the rcpp_long_long_type and rcpp_ulong_long_type
192-
// types
193-
//
194-
// e.g. code like this is not good:
195-
//
196-
// long long x = 2 ;
197-
//
198-
// but code like this is CRAN proof
199-
//
200-
// rcpp_long_long_type x = 2 ;
201-
//
202-
// Note that if you don't distribute your code to CRAN and you don't use the
203-
// -pedantic option, then you can use long long
204-
#if defined(__GNUC__) && defined(__LONG_LONG_MAX__)
205-
__extension__ typedef long long int rcpp_long_long_type;
206-
__extension__ typedef unsigned long long int rcpp_ulong_long_type;
207-
#define RCPP_HAS_LONG_LONG_TYPES
208-
#endif
209-
210180
#endif

inst/include/Rcpp/traits/r_sexptype_traits.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,10 @@ template<> struct r_sexptype_traits<long double>{ enum{ rtype = REALSXP } ; } ;
5959
template<> struct r_sexptype_traits<short>{ enum{ rtype = INTSXP } ; } ;
6060
template<> struct r_sexptype_traits<unsigned short>{ enum{ rtype = INTSXP } ; } ;
6161

62-
/* long long int */
63-
#ifdef RCPP_HAS_LONG_LONG_TYPES
64-
template<> struct r_sexptype_traits<rcpp_long_long_type>{ enum{ rtype = REALSXP } ; } ;
65-
template<> struct r_sexptype_traits<rcpp_ulong_long_type>{ enum{ rtype = REALSXP } ; } ;
66-
#endif
67-
6862
/* std::complex */
6963
template<> struct r_sexptype_traits< std::complex<double> >{ enum{ rtype = CPLXSXP } ; } ;
7064
template<> struct r_sexptype_traits< std::complex<float> >{ enum{ rtype = CPLXSXP } ; } ;
7165

72-
7366
/**
7467
* Indicates if a primitive type needs a static_cast
7568
*/

inst/include/Rcpp/traits/r_type_traits.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,6 @@ template<> struct r_type_traits< std::pair<const std::string,std::complex<double
178178
template<> struct r_type_traits< std::complex<float> >{ typedef r_type_primitive_tag r_category ; } ;
179179
template<> struct r_type_traits< std::pair<const std::string,std::complex<float> > >{ typedef r_type_primitive_tag r_category ; } ;
180180

181-
/* long long int */
182-
#ifdef RCPP_HAS_LONG_LONG_TYPES
183-
template<> struct r_type_traits<rcpp_long_long_type>{ typedef r_type_primitive_tag r_category ; } ;
184-
template<> struct r_type_traits< std::pair<const std::string,rcpp_long_long_type> >{ typedef r_type_primitive_tag r_category ; } ;
185-
template<> struct r_type_traits<rcpp_ulong_long_type>{ typedef r_type_primitive_tag r_category ; } ;
186-
template<> struct r_type_traits< std::pair<const std::string,rcpp_ulong_long_type> >{ typedef r_type_primitive_tag r_category ; } ;
187-
#endif
188-
189181
} // traits
190182
} // Rcpp
191183

inst/include/Rcpp/traits/wrap_type_traits.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ template <> struct wrap_type_traits<long double> { typedef wrap_type_primitive_t
9191
template <> struct wrap_type_traits<short> { typedef wrap_type_primitive_tag wrap_category; } ;
9292
template <> struct wrap_type_traits<unsigned short> { typedef wrap_type_primitive_tag wrap_category; } ;
9393

94-
#ifdef RCPP_HAS_LONG_LONG_TYPES
95-
template <> struct wrap_type_traits<rcpp_long_long_type> { typedef wrap_type_primitive_tag wrap_category; } ;
96-
template <> struct wrap_type_traits<rcpp_ulong_long_type> { typedef wrap_type_primitive_tag wrap_category; } ;
97-
#endif
98-
9994
template <typename T> struct wrap_type_traits< Rcpp::object<T> > { typedef wrap_type_module_object_pointer_tag wrap_category; } ;
10095

10196

inst/include/RcppCommon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,6 @@ namespace Rcpp{
133133
#include <Rcpp/iostream/Rstreambuf.h>
134134
#include <Rcpp/iostream/Rostream.h>
135135

136+
#include <Rcpp/longlong.h>
137+
136138
#endif

0 commit comments

Comments
 (0)