Advertisement
Guest User

Untitled

a guest
May 14th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.01 KB | None | 0 0
  1. //  boost cstdint.hpp header file  ------------------------------------------//
  2.  
  3. //  (C) Copyright Beman Dawes 1999.
  4. //  (C) Copyright Jens Mauer 2001
  5. //  (C) Copyright John Maddock 2001
  6. //  Distributed under the Boost
  7. //  Software License, Version 1.0. (See accompanying file
  8. //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9.  
  10. //  See http://www.boost.org/libs/integer for documentation.
  11.  
  12. //  Revision History
  13. //   31 Oct 01  use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
  14. //   16 Apr 01  check LONGLONG_MAX when looking for "long long" (Jens Maurer)
  15. //   23 Jan 01  prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
  16. //   12 Nov 00  Merged <boost/stdint.h> (Jens Maurer)
  17. //   23 Sep 00  Added INTXX_C macro support (John Maddock).
  18. //   22 Sep 00  Better 64-bit support (John Maddock)
  19. //   29 Jun 00  Reimplement to avoid including stdint.h within namespace boost
  20. //    8 Aug 99  Initial version (Beman Dawes)
  21.  
  22.  
  23. #ifndef BOOST_CSTDINT_HPP
  24. #define BOOST_CSTDINT_HPP
  25.  
  26. //
  27. // Since we always define the INT#_C macros as per C++0x,
  28. // define __STDC_CONSTANT_MACROS so that <stdint.h> does the right
  29. // thing if possible, and so that the user knows that the macros
  30. // are actually defined as per C99.
  31. //
  32. #ifndef __STDC_CONSTANT_MACROS
  33. #  define __STDC_CONSTANT_MACROS
  34. #endif
  35.  
  36. #include <boost/config.hpp>
  37.  
  38. //
  39. // Note that GLIBC is a bit inconsistent about whether int64_t is defined or not
  40. // depending upon what headers happen to have been included first...
  41. // so we disable use of stdint.h when GLIBC does not define __GLIBC_HAVE_LONG_LONG.
  42. // See https://svn.boost.org/trac/boost/ticket/3548 and http://sources.redhat.com/bugzilla/show_bug.cgi?id=10990
  43. //
  44. #if defined(BOOST_HAS_STDINT_H)                                 \
  45.   && (!defined(__GLIBC__)                                       \
  46.       || defined(__GLIBC_HAVE_LONG_LONG)                        \
  47.       || (defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 17)))))
  48.  
  49. // The following #include is an implementation artifact; not part of interface.
  50. # ifdef __hpux
  51. // HP-UX has a vaguely nice <stdint.h> in a non-standard location
  52. #   include <inttypes.h>
  53. #   ifdef __STDC_32_MODE__
  54.       // this is triggered with GCC, because it defines __cplusplus < 199707L
  55. #     define BOOST_NO_INT64_T
  56. #   endif
  57. # elif defined(__FreeBSD__) || defined(__IBMCPP__) || defined(_AIX)
  58. #   include <inttypes.h>
  59. # else
  60. #   include <stdint.h>
  61.  
  62. // There is a bug in Cygwin two _C macros
  63. #   if defined(__STDC_CONSTANT_MACROS) && defined(__CYGWIN__)
  64. #     undef INTMAX_C
  65. #     undef UINTMAX_C
  66. #     define INTMAX_C(c) c##LL
  67. #     define UINTMAX_C(c) c##ULL
  68. #   endif
  69.  
  70. # endif
  71.  
  72. #ifdef __QNX__
  73.  
  74. // QNX (Dinkumware stdlib) defines these as non-standard names.
  75. // Reflect to the standard names.
  76.  
  77. typedef ::intleast8_t int_least8_t;
  78. typedef ::intfast8_t int_fast8_t;
  79. typedef ::uintleast8_t uint_least8_t;
  80. typedef ::uintfast8_t uint_fast8_t;
  81.  
  82. typedef ::intleast16_t int_least16_t;
  83. typedef ::intfast16_t int_fast16_t;
  84. typedef ::uintleast16_t uint_least16_t;
  85. typedef ::uintfast16_t uint_fast16_t;
  86.  
  87. typedef ::intleast32_t int_least32_t;
  88. typedef ::intfast32_t int_fast32_t;
  89. typedef ::uintleast32_t uint_least32_t;
  90. typedef ::uintfast32_t uint_fast32_t;
  91.  
  92. # ifndef BOOST_NO_INT64_T
  93.  
  94. typedef ::intleast64_t int_least64_t;
  95. typedef ::intfast64_t int_fast64_t;
  96. typedef ::uintleast64_t uint_least64_t;
  97. typedef ::uintfast64_t uint_fast64_t;
  98.  
  99. # endif
  100.  
  101. #endif
  102.  
  103. namespace boost
  104. {
  105.  
  106.   using ::int8_t;
  107.   using ::int_least8_t;
  108.   using ::int_fast8_t;
  109.   using ::uint8_t;
  110.   using ::uint_least8_t;
  111.   using ::uint_fast8_t;
  112.  
  113.   using ::int16_t;
  114.   using ::int_least16_t;
  115.   using ::int_fast16_t;
  116.   using ::uint16_t;
  117.   using ::uint_least16_t;
  118.   using ::uint_fast16_t;
  119.  
  120.   using ::int32_t;
  121.   using ::int_least32_t;
  122.   using ::int_fast32_t;
  123.   using ::uint32_t;
  124.   using ::uint_least32_t;
  125.   using ::uint_fast32_t;
  126.  
  127. # ifndef BOOST_NO_INT64_T
  128.  
  129.   using ::int64_t;
  130.   using ::int_least64_t;
  131.   using ::int_fast64_t;
  132.   using ::uint64_t;
  133.   using ::uint_least64_t;
  134.   using ::uint_fast64_t;
  135.  
  136. # endif
  137.  
  138.   using ::intmax_t;
  139.   using ::uintmax_t;
  140.  
  141. } // namespace boost
  142.  
  143. #elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__) || defined(__VMS)
  144. // FreeBSD and Tru64 have an <inttypes.h> that contains much of what we need.
  145. # include <inttypes.h>
  146.  
  147. namespace boost {
  148.  
  149.   using ::int8_t;
  150.   typedef int8_t int_least8_t;
  151.   typedef int8_t int_fast8_t;
  152.   using ::uint8_t;
  153.   typedef uint8_t uint_least8_t;
  154.   typedef uint8_t uint_fast8_t;
  155.  
  156.   using ::int16_t;
  157.   typedef int16_t int_least16_t;
  158.   typedef int16_t int_fast16_t;
  159.   using ::uint16_t;
  160.   typedef uint16_t uint_least16_t;
  161.   typedef uint16_t uint_fast16_t;
  162.  
  163.   using ::int32_t;
  164.   typedef int32_t int_least32_t;
  165.   typedef int32_t int_fast32_t;
  166.   using ::uint32_t;
  167.   typedef uint32_t uint_least32_t;
  168.   typedef uint32_t uint_fast32_t;
  169.  
  170. # ifndef BOOST_NO_INT64_T
  171.  
  172.   using ::int64_t;
  173.   typedef int64_t int_least64_t;
  174.   typedef int64_t int_fast64_t;
  175.   using ::uint64_t;
  176.   typedef uint64_t uint_least64_t;
  177.   typedef uint64_t uint_fast64_t;
  178.  
  179.   typedef int64_t intmax_t;
  180.   typedef uint64_t uintmax_t;
  181.  
  182. # else
  183.  
  184.   typedef int32_t intmax_t;
  185.   typedef uint32_t uintmax_t;
  186.  
  187. # endif
  188.  
  189. } // namespace boost
  190.  
  191. #else  // BOOST_HAS_STDINT_H
  192.  
  193. # include <boost/limits.hpp> // implementation artifact; not part of interface
  194. # include <limits.h>         // needed for limits macros
  195.  
  196.  
  197. namespace boost
  198. {
  199.  
  200. //  These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
  201. //  platforms.  For other systems, they will have to be hand tailored.
  202. //
  203. //  Because the fast types are assumed to be the same as the undecorated types,
  204. //  it may be possible to hand tailor a more efficient implementation.  Such
  205. //  an optimization may be illusionary; on the Intel x86-family 386 on, for
  206. //  example, byte arithmetic and load/stores are as fast as "int" sized ones.
  207.  
  208. //  8-bit types  ------------------------------------------------------------//
  209.  
  210. # if UCHAR_MAX == 0xff
  211.      typedef signed char     int8_t;
  212.      typedef signed char     int_least8_t;
  213.      typedef signed char     int_fast8_t;
  214.      typedef unsigned char   uint8_t;
  215.      typedef unsigned char   uint_least8_t;
  216.      typedef unsigned char   uint_fast8_t;
  217. # else
  218. #    error defaults not correct; you must hand modify boost/cstdint.hpp
  219. # endif
  220.  
  221. //  16-bit types  -----------------------------------------------------------//
  222.  
  223. # if USHRT_MAX == 0xffff
  224. #  if defined(__crayx1)
  225.      // The Cray X1 has a 16-bit short, however it is not recommend
  226.      // for use in performance critical code.
  227.      typedef short           int16_t;
  228.      typedef short           int_least16_t;
  229.      typedef int             int_fast16_t;
  230.      typedef unsigned short  uint16_t;
  231.      typedef unsigned short  uint_least16_t;
  232.      typedef unsigned int    uint_fast16_t;
  233. #  else
  234.      typedef short           int16_t;
  235.      typedef short           int_least16_t;
  236.      typedef short           int_fast16_t;
  237.      typedef unsigned short  uint16_t;
  238.      typedef unsigned short  uint_least16_t;
  239.      typedef unsigned short  uint_fast16_t;
  240. #  endif
  241. # elif (USHRT_MAX == 0xffffffff) && defined(__MTA__)
  242.       // On MTA / XMT short is 32 bits unless the -short16 compiler flag is specified
  243.       // MTA / XMT does support the following non-standard integer types
  244.       typedef __short16           int16_t;
  245.       typedef __short16           int_least16_t;
  246.       typedef __short16           int_fast16_t;
  247.       typedef unsigned __short16  uint16_t;
  248.       typedef unsigned __short16  uint_least16_t;
  249.       typedef unsigned __short16  uint_fast16_t;
  250. # elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
  251.      // no 16-bit types on Cray:
  252.      typedef short           int_least16_t;
  253.      typedef short           int_fast16_t;
  254.      typedef unsigned short  uint_least16_t;
  255.      typedef unsigned short  uint_fast16_t;
  256. # else
  257. #    error defaults not correct; you must hand modify boost/cstdint.hpp
  258. # endif
  259.  
  260. //  32-bit types  -----------------------------------------------------------//
  261.  
  262. # if UINT_MAX == 0xffffffff
  263.      typedef int             int32_t;
  264.      typedef int             int_least32_t;
  265.      typedef int             int_fast32_t;
  266.      typedef unsigned int    uint32_t;
  267.      typedef unsigned int    uint_least32_t;
  268.      typedef unsigned int    uint_fast32_t;
  269. # elif (USHRT_MAX == 0xffffffff)
  270.      typedef short             int32_t;
  271.      typedef short             int_least32_t;
  272.      typedef short             int_fast32_t;
  273.      typedef unsigned short    uint32_t;
  274.      typedef unsigned short    uint_least32_t;
  275.      typedef unsigned short    uint_fast32_t;
  276. # elif ULONG_MAX == 0xffffffff
  277.      typedef long            int32_t;
  278.      typedef long            int_least32_t;
  279.      typedef long            int_fast32_t;
  280.      typedef unsigned long   uint32_t;
  281.      typedef unsigned long   uint_least32_t;
  282.      typedef unsigned long   uint_fast32_t;
  283. # elif (UINT_MAX == 0xffffffffffffffff) && defined(__MTA__)
  284.       // Integers are 64 bits on the MTA / XMT
  285.       typedef __int32           int32_t;
  286.       typedef __int32           int_least32_t;
  287.       typedef __int32           int_fast32_t;
  288.       typedef unsigned __int32  uint32_t;
  289.       typedef unsigned __int32  uint_least32_t;
  290.       typedef unsigned __int32  uint_fast32_t;
  291. # else
  292. #    error defaults not correct; you must hand modify boost/cstdint.hpp
  293. # endif
  294.  
  295. //  64-bit types + intmax_t and uintmax_t  ----------------------------------//
  296.  
  297. # if defined(BOOST_HAS_LONG_LONG) && \
  298.    !defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
  299.    (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
  300.    (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
  301. #    if defined(__hpux)
  302.      // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
  303. #    elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
  304.                                                                  // 2**64 - 1
  305. #    else
  306. #       error defaults not correct; you must hand modify boost/cstdint.hpp
  307. #    endif
  308.  
  309.      typedef  ::boost::long_long_type            intmax_t;
  310.      typedef  ::boost::ulong_long_type   uintmax_t;
  311.      typedef  ::boost::long_long_type            int64_t;
  312.      typedef  ::boost::long_long_type            int_least64_t;
  313.      typedef  ::boost::long_long_type            int_fast64_t;
  314.      typedef  ::boost::ulong_long_type   uint64_t;
  315.      typedef  ::boost::ulong_long_type   uint_least64_t;
  316.      typedef  ::boost::ulong_long_type   uint_fast64_t;
  317.  
  318. # elif ULONG_MAX != 0xffffffff
  319.  
  320. #    if ULONG_MAX == 18446744073709551615 // 2**64 - 1
  321.      typedef long                 intmax_t;
  322.      typedef unsigned long        uintmax_t;
  323.      typedef long                 int64_t;
  324.      typedef long                 int_least64_t;
  325.      typedef long                 int_fast64_t;
  326.      typedef unsigned long        uint64_t;
  327.      typedef unsigned long        uint_least64_t;
  328.      typedef unsigned long        uint_fast64_t;
  329. #    else
  330. #       error defaults not correct; you must hand modify boost/cstdint.hpp
  331. #    endif
  332. # elif defined(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
  333.      __extension__ typedef long long            intmax_t;
  334.      __extension__ typedef unsigned long long   uintmax_t;
  335.      __extension__ typedef long long            int64_t;
  336.      __extension__ typedef long long            int_least64_t;
  337.      __extension__ typedef long long            int_fast64_t;
  338.      __extension__ typedef unsigned long long   uint64_t;
  339.      __extension__ typedef unsigned long long   uint_least64_t;
  340.      __extension__ typedef unsigned long long   uint_fast64_t;
  341. # elif defined(BOOST_HAS_MS_INT64)
  342.      //
  343.      // we have Borland/Intel/Microsoft __int64:
  344.      //
  345.      typedef __int64             intmax_t;
  346.      typedef unsigned __int64    uintmax_t;
  347.      typedef __int64             int64_t;
  348.      typedef __int64             int_least64_t;
  349.      typedef __int64             int_fast64_t;
  350.      typedef unsigned __int64    uint64_t;
  351.      typedef unsigned __int64    uint_least64_t;
  352.      typedef unsigned __int64    uint_fast64_t;
  353. # else // assume no 64-bit integers
  354. #  define BOOST_NO_INT64_T
  355.      typedef int32_t              intmax_t;
  356.      typedef uint32_t             uintmax_t;
  357. # endif
  358.  
  359. } // namespace boost
  360.  
  361.  
  362. #endif // BOOST_HAS_STDINT_H
  363.  
  364. #endif // BOOST_CSTDINT_HPP
  365.  
  366.  
  367. /****************************************************
  368.  
  369. Macro definition section:
  370.  
  371. Added 23rd September 2000 (John Maddock).
  372. Modified 11th September 2001 to be excluded when
  373. BOOST_HAS_STDINT_H is defined (John Maddock).
  374. Modified 11th Dec 2009 to always define the
  375. INT#_C macros if they're not already defined (John Maddock).
  376.  
  377. ******************************************************/
  378.  
  379. #if !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && \
  380.    (!defined(INT8_C) || !defined(INT16_C) || !defined(INT32_C) || !defined(INT64_C))
  381. //
  382. // For the following code we get several warnings along the lines of:
  383. //
  384. // boost/cstdint.hpp:428:35: error: use of C99 long long integer constant
  385. //
  386. // So we declare this a system header to suppress these warnings.
  387. //
  388. #if defined(__GNUC__) && (__GNUC__ >= 4)
  389. #pragma GCC system_header
  390. #endif
  391.  
  392. #include <limits.h>
  393. # define BOOST__STDC_CONSTANT_MACROS_DEFINED
  394. # if defined(BOOST_HAS_MS_INT64)
  395. //
  396. // Borland/Intel/Microsoft compilers have width specific suffixes:
  397. //
  398. #ifndef INT8_C
  399. #  define INT8_C(value)     value##i8
  400. #endif
  401. #ifndef INT16_C
  402. #  define INT16_C(value)    value##i16
  403. #endif
  404. #ifndef INT32_C
  405. #  define INT32_C(value)    value##i32
  406. #endif
  407. #ifndef INT64_C
  408. #  define INT64_C(value)    value##i64
  409. #endif
  410. #  ifdef __BORLANDC__
  411.     // Borland bug: appending ui8 makes the type a signed char
  412. #   define UINT8_C(value)    static_cast<unsigned char>(value##u)
  413. #  else
  414. #   define UINT8_C(value)    value##ui8
  415. #  endif
  416. #ifndef UINT16_C
  417. #  define UINT16_C(value)   value##ui16
  418. #endif
  419. #ifndef UINT32_C
  420. #  define UINT32_C(value)   value##ui32
  421. #endif
  422. #ifndef UINT64_C
  423. #  define UINT64_C(value)   value##ui64
  424. #endif
  425. #ifndef INTMAX_C
  426. #  define INTMAX_C(value)   value##i64
  427. #  define UINTMAX_C(value)  value##ui64
  428. #endif
  429.  
  430. # else
  431. //  do it the old fashioned way:
  432.  
  433. //  8-bit types  ------------------------------------------------------------//
  434.  
  435. #  if (UCHAR_MAX == 0xff) && !defined(INT8_C)
  436. #   define INT8_C(value) static_cast<boost::int8_t>(value)
  437. #   define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
  438. #  endif
  439.  
  440. //  16-bit types  -----------------------------------------------------------//
  441.  
  442. #  if (USHRT_MAX == 0xffff) && !defined(INT16_C)
  443. #   define INT16_C(value) static_cast<boost::int16_t>(value)
  444. #   define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
  445. #  endif
  446.  
  447. //  32-bit types  -----------------------------------------------------------//
  448. #ifndef INT32_C
  449. #  if (UINT_MAX == 0xffffffff)
  450. #   define INT32_C(value) value
  451. #   define UINT32_C(value) value##u
  452. #  elif ULONG_MAX == 0xffffffff
  453. #   define INT32_C(value) value##L
  454. #   define UINT32_C(value) value##uL
  455. #  endif
  456. #endif
  457.  
  458. //  64-bit types + intmax_t and uintmax_t  ----------------------------------//
  459. #ifndef INT64_C
  460. #  if defined(BOOST_HAS_LONG_LONG) && \
  461.     (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX) || defined(_LLONG_MAX))
  462.  
  463. #    if defined(__hpux)
  464.         // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
  465. #       define INT64_C(value) value##LL
  466. #       define UINT64_C(value) value##uLL
  467. #    elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) ||  \
  468.         (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) ||  \
  469.         (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL) || \
  470.         (defined(_LLONG_MAX) && _LLONG_MAX == 18446744073709551615ULL)
  471.  
  472. #       define INT64_C(value) value##LL
  473. #       define UINT64_C(value) value##uLL
  474. #    else
  475. #       error defaults not correct; you must hand modify boost/cstdint.hpp
  476. #    endif
  477. #  elif ULONG_MAX != 0xffffffff
  478.  
  479. #    if ULONG_MAX == 18446744073709551615U // 2**64 - 1
  480. #       define INT64_C(value) value##L
  481. #       define UINT64_C(value) value##uL
  482. #    else
  483. #       error defaults not correct; you must hand modify boost/cstdint.hpp
  484. #    endif
  485. #  elif defined(BOOST_HAS_LONG_LONG)
  486.      // Usual macros not defined, work things out for ourselves:
  487. #    if(~0uLL == 18446744073709551615ULL)
  488. #       define INT64_C(value) value##LL
  489. #       define UINT64_C(value) value##uLL
  490. #    else
  491. #       error defaults not correct; you must hand modify boost/cstdint.hpp
  492. #    endif
  493. #  else
  494. #    error defaults not correct; you must hand modify boost/cstdint.hpp
  495. #  endif
  496.  
  497. #  ifdef BOOST_NO_INT64_T
  498. #   define INTMAX_C(value) INT32_C(value)
  499. #   define UINTMAX_C(value) UINT32_C(value)
  500. #  else
  501. #   define INTMAX_C(value) INT64_C(value)
  502. #   define UINTMAX_C(value) UINT64_C(value)
  503. #  endif
  504. #endif
  505. # endif // Borland/Microsoft specific width suffixes
  506.  
  507. #endif // INT#_C macros.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement