• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3     Copyright (c) 2001-2011 Hartmut Kaiser
4     Copyright (c) 2011      Bryce Lelbach
5 
6     Distributed under the Boost Software License, Version 1.0. (See accompanying
7     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_TEST_QI_INT_HPP)
10 #define BOOST_SPIRIT_TEST_QI_INT_HPP
11 
12 #include <climits>
13 #include <boost/detail/lightweight_test.hpp>
14 #include <boost/spirit/include/qi_numeric.hpp>
15 #include <boost/spirit/include/qi_char.hpp>
16 #include <boost/spirit/include/qi_action.hpp>
17 #include <boost/spirit/include/support_argument.hpp>
18 #include <boost/spirit/include/phoenix_core.hpp>
19 #include <boost/spirit/include/phoenix_operator.hpp>
20 
21 #include "test.hpp"
22 
23 ///////////////////////////////////////////////////////////////////////////////
24 //
25 //  *** BEWARE PLATFORM DEPENDENT!!! ***
26 //  *** The following assumes 32 bit or 64 bit integers and 64 bit long longs.
27 //  *** Modify these constant strings when appropriate.
28 //
29 ///////////////////////////////////////////////////////////////////////////////
30 #ifdef BOOST_HAS_LONG_LONG
31 // Some compilers have long long, but don't define the
32 // LONG_LONG_MIN and LONG_LONG_MAX macros in limits.h.  This
33 // assumes that long long is 64 bits.
34 
35 BOOST_STATIC_ASSERT(sizeof(boost::long_long_type) == 8);
36 
37 #if !defined(LONG_LONG_MIN) && !defined(LONG_LONG_MAX)
38 # define LONG_LONG_MAX 0x7fffffffffffffffLL
39 # define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
40 #endif
41 
42 #endif // BOOST_HAS_LONG_LONG
43 
44 #if INT_MAX != LLONG_MAX
45     BOOST_STATIC_ASSERT(sizeof(int) == 4);
46     char const* max_int = "2147483647";
47     char const* int_overflow = "2147483648";
48     char const* min_int = "-2147483648";
49     char const* int_underflow = "-2147483649";
50 #else
51     BOOST_STATIC_ASSERT(sizeof(int) == 8);
52     char const* max_int = "9223372036854775807";
53     char const* int_overflow = "9223372036854775808";
54     char const* min_int = "-9223372036854775808";
55     char const* int_underflow = "-9223372036854775809";
56 #endif
57 
58 #ifdef BOOST_HAS_LONG_LONG
59     char const* max_long_long = "9223372036854775807";
60     char const* long_long_overflow = "9223372036854775808";
61     char const* min_long_long = "-9223372036854775808";
62     char const* long_long_underflow = "-9223372036854775809";
63 #endif
64 
65 ///////////////////////////////////////////////////////////////////////////////
66 // A custom int type
67 struct custom_int
68 {
69     int n;
custom_intcustom_int70     custom_int() : n(0) {}
custom_intcustom_int71     explicit custom_int(int n_) : n(n_) {}
operator =custom_int72     custom_int& operator=(int n_) { n = n_; return *this; }
operator ==(custom_int a,custom_int b)73     friend bool operator==(custom_int a, custom_int b) { return a.n == b.n; }
operator ==(custom_int a,int b)74     friend bool operator==(custom_int a, int b) { return a.n == b; }
operator *(custom_int a,custom_int b)75     friend custom_int operator*(custom_int a, custom_int b) { return custom_int(a.n * b.n); }
operator +(custom_int a,custom_int b)76     friend custom_int operator+(custom_int a, custom_int b) { return custom_int(a.n + b.n); }
operator -(custom_int a,custom_int b)77     friend custom_int operator-(custom_int a, custom_int b) { return custom_int(a.n - b.n); }
78 };
79 
80 #endif
81