uint.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Copyright (c) 2011 Bryce Lelbach
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_SPIRIT_TEST_QI_UINT_HPP)
  9. #define BOOST_SPIRIT_TEST_QI_UINT_HPP
  10. #include <climits>
  11. #include <boost/detail/lightweight_test.hpp>
  12. #include <boost/spirit/include/qi_numeric.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/spirit/include/phoenix_core.hpp>
  17. #include <boost/spirit/include/phoenix_operator.hpp>
  18. #include "test.hpp"
  19. #include <cstring>
  20. ///////////////////////////////////////////////////////////////////////////////
  21. //
  22. // *** BEWARE PLATFORM DEPENDENT!!! ***
  23. // *** The following assumes 32 bit integers and 64 bit long longs.
  24. // *** Modify these constant strings when appropriate.
  25. //
  26. ///////////////////////////////////////////////////////////////////////////////
  27. char const* max_unsigned = "4294967295";
  28. char const* unsigned_overflow = "4294967296";
  29. char const* max_int = "2147483647";
  30. char const* int_overflow = "2147483648";
  31. char const* min_int = "-2147483648";
  32. char const* int_underflow = "-2147483649";
  33. char const* max_binary = "11111111111111111111111111111111";
  34. char const* binary_overflow = "100000000000000000000000000000000";
  35. char const* max_octal = "37777777777";
  36. char const* octal_overflow = "100000000000";
  37. char const* max_hex = "FFFFFFFF";
  38. char const* hex_overflow = "100000000";
  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. #endif