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_UINT_HPP) |
10 | #define BOOST_SPIRIT_TEST_QI_UINT_HPP |
11 | |
12 | #include <boost/spirit/include/qi_uint.hpp> |
13 | |
14 | #include <boost/spirit/include/qi_char.hpp> |
15 | #include <boost/spirit/include/qi_action.hpp> |
16 | #include <boost/spirit/include/support_argument.hpp> |
17 | #include <boost/phoenix/core.hpp> |
18 | #include <boost/phoenix/operator.hpp> |
19 | |
20 | #include "test.hpp" |
21 | #include <climits> |
22 | #include <cstring> |
23 | |
24 | /////////////////////////////////////////////////////////////////////////////// |
25 | // |
26 | // *** BEWARE PLATFORM DEPENDENT!!! *** |
27 | // *** The following assumes 32 bit integers and 64 bit long longs. |
28 | // *** Modify these constant strings when appropriate. |
29 | // |
30 | /////////////////////////////////////////////////////////////////////////////// |
31 | |
32 | char const* max_unsigned = "4294967295" ; |
33 | char const* unsigned_overflow = "4294967296" ; |
34 | char const* max_int = "2147483647" ; |
35 | char const* int_overflow = "2147483648" ; |
36 | char const* min_int = "-2147483648" ; |
37 | char const* int_underflow = "-2147483649" ; |
38 | char const* max_binary = "11111111111111111111111111111111" ; |
39 | char const* binary_overflow = "100000000000000000000000000000000" ; |
40 | char const* max_octal = "37777777777" ; |
41 | char const* octal_overflow = "100000000000" ; |
42 | char const* max_hex = "FFFFFFFF" ; |
43 | char const* hex_overflow = "100000000" ; |
44 | |
45 | /////////////////////////////////////////////////////////////////////////////// |
46 | // A custom int type |
47 | struct custom_uint |
48 | { |
49 | unsigned n; |
50 | custom_uint() : n(0) {} |
51 | explicit custom_uint(unsigned n_) : n(n_) {} |
52 | custom_uint& operator=(unsigned n_) { n = n_; return *this; } |
53 | friend bool operator==(custom_uint a, custom_uint b) |
54 | { return a.n == b.n; } |
55 | friend bool operator==(custom_uint a, unsigned b) |
56 | { return a.n == b; } |
57 | friend custom_uint operator*(custom_uint a, custom_uint b) |
58 | { return custom_uint(a.n * b.n); } |
59 | friend custom_uint operator+(custom_uint a, custom_uint b) |
60 | { return custom_uint(a.n + b.n); } |
61 | }; |
62 | |
63 | #endif |
64 | |
65 | |