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 <boost/spirit/include/qi_int.hpp> |
13 | #include <boost/spirit/include/qi_char.hpp> |
14 | #include <boost/spirit/include/qi_action.hpp> |
15 | #include <boost/spirit/include/support_argument.hpp> |
16 | #include <boost/phoenix/core.hpp> |
17 | #include <boost/phoenix/operator.hpp> |
18 | #include <climits> |
19 | |
20 | #include "test.hpp" |
21 | |
22 | /////////////////////////////////////////////////////////////////////////////// |
23 | // |
24 | // *** BEWARE PLATFORM DEPENDENT!!! *** |
25 | // *** The following assumes 32 bit or 64 bit integers and 64 bit long longs. |
26 | // *** Modify these constant strings when appropriate. |
27 | // |
28 | /////////////////////////////////////////////////////////////////////////////// |
29 | #ifdef BOOST_HAS_LONG_LONG |
30 | // Some compilers have long long, but don't define the |
31 | // LONG_LONG_MIN and LONG_LONG_MAX macros in limits.h. This |
32 | // assumes that long long is 64 bits. |
33 | |
34 | BOOST_STATIC_ASSERT(sizeof(boost::long_long_type) == 8); |
35 | |
36 | #if !defined(LONG_LONG_MIN) && !defined(LONG_LONG_MAX) |
37 | # define LONG_LONG_MAX 0x7fffffffffffffffLL |
38 | # define LONG_LONG_MIN (-LONG_LONG_MAX - 1) |
39 | #endif |
40 | |
41 | #endif // BOOST_HAS_LONG_LONG |
42 | |
43 | #if INT_MAX != LLONG_MAX |
44 | BOOST_STATIC_ASSERT(sizeof(int) == 4); |
45 | char const* max_int = "2147483647" ; |
46 | char const* int_overflow = "2147483648" ; |
47 | char const* min_int = "-2147483648" ; |
48 | char const* int_underflow = "-2147483649" ; |
49 | #else |
50 | BOOST_STATIC_ASSERT(sizeof(int) == 8); |
51 | char const* max_int = "9223372036854775807" ; |
52 | char const* int_overflow = "9223372036854775808" ; |
53 | char const* min_int = "-9223372036854775808" ; |
54 | char const* int_underflow = "-9223372036854775809" ; |
55 | #endif |
56 | |
57 | #ifdef BOOST_HAS_LONG_LONG |
58 | char const* max_long_long = "9223372036854775807" ; |
59 | char const* long_long_overflow = "9223372036854775808" ; |
60 | char const* min_long_long = "-9223372036854775808" ; |
61 | char const* long_long_underflow = "-9223372036854775809" ; |
62 | #endif |
63 | |
64 | /////////////////////////////////////////////////////////////////////////////// |
65 | // A custom int type |
66 | struct custom_int |
67 | { |
68 | int n; |
69 | custom_int() : n(0) {} |
70 | explicit custom_int(int n_) : n(n_) {} |
71 | custom_int& operator=(int n_) { n = n_; return *this; } |
72 | friend bool operator==(custom_int a, custom_int b) { return a.n == b.n; } |
73 | friend bool operator==(custom_int a, int b) { return a.n == b; } |
74 | friend custom_int operator*(custom_int a, custom_int b) { return custom_int(a.n * b.n); } |
75 | friend custom_int operator+(custom_int a, custom_int b) { return custom_int(a.n + b.n); } |
76 | friend custom_int operator-(custom_int a, custom_int b) { return custom_int(a.n - b.n); } |
77 | }; |
78 | |
79 | #endif |
80 | |