collection_traits.hpp 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef BOOST_SERIALIZATION_COLLECTION_TRAITS_HPP
  2. #define BOOST_SERIALIZATION_COLLECTION_TRAITS_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // collection_traits.hpp:
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. // This header assigns a level implemenation trait to a collection type
  15. // for all primitives. It is needed so that archives which are meant to be
  16. // portable don't write class information in the archive. Since, not all
  17. // compiles recognize the same set of primitive types, the possibility
  18. // exists for archives to be non-portable if class information for primitive
  19. // types is included. This is addressed by the following macros.
  20. #include <boost/config.hpp>
  21. #include <boost/mpl/integral_c.hpp>
  22. #include <boost/mpl/integral_c_tag.hpp>
  23. #include <boost/cstdint.hpp>
  24. #include <climits> // ULONG_MAX
  25. #include <boost/serialization/level.hpp>
  26. #define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(T, C) \
  27. template<> \
  28. struct implementation_level< C < T > > { \
  29. typedef mpl::integral_c_tag tag; \
  30. typedef mpl::int_<object_serializable> type; \
  31. BOOST_STATIC_CONSTANT(int, value = object_serializable); \
  32. }; \
  33. /**/
  34. #if defined(BOOST_NO_CWCHAR) || defined(BOOST_NO_INTRINSIC_WCHAR_T)
  35. #define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_WCHAR(C)
  36. #else
  37. #define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_WCHAR(C) \
  38. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(wchar_t, C) \
  39. /**/
  40. #endif
  41. // determine if its necessary to handle (u)int64_t specifically
  42. // i.e. that its not a synonym for (unsigned) long
  43. // if there is no 64 bit int or if its the same as a long
  44. // we shouldn't define separate functions for int64 data types.
  45. #if defined(BOOST_NO_INT64_T)
  46. #define BOOST_NO_INTRINSIC_INT64_T
  47. #else
  48. #if defined(ULLONG_MAX)
  49. #if(ULONG_MAX == 18446744073709551615ul) // 2**64 - 1
  50. #define BOOST_NO_INTRINSIC_INT64_T
  51. #endif
  52. #elif defined(ULONG_MAX)
  53. #if(ULONG_MAX != 0xffffffff && ULONG_MAX == 18446744073709551615ul) // 2**64 - 1
  54. #define BOOST_NO_INTRINSIC_INT64_T
  55. #endif
  56. #else
  57. #define BOOST_NO_INTRINSIC_INT64_T
  58. #endif
  59. #endif
  60. #if !defined(BOOST_NO_INTRINSIC_INT64_T)
  61. #define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_INT64(C) \
  62. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(boost::int64_t, C) \
  63. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(boost::uint64_t, C) \
  64. /**/
  65. #else
  66. #define BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_INT64(C)
  67. #endif
  68. #define BOOST_SERIALIZATION_COLLECTION_TRAITS(C) \
  69. namespace boost { namespace serialization { \
  70. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(bool, C) \
  71. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(char, C) \
  72. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(signed char, C) \
  73. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(unsigned char, C) \
  74. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(signed int, C) \
  75. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(unsigned int, C) \
  76. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(signed long, C) \
  77. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(unsigned long, C) \
  78. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(float, C) \
  79. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(double, C) \
  80. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(unsigned short, C) \
  81. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER(signed short, C) \
  82. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_INT64(C) \
  83. BOOST_SERIALIZATION_COLLECTION_TRAITS_HELPER_WCHAR(C) \
  84. } } \
  85. /**/
  86. #endif // BOOST_SERIALIZATION_COLLECTION_TRAITS