int.hpp 3.1 KB

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