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