uint.hpp 2.2 KB

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