binary_object.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef BOOST_SERIALIZATION_BINARY_OBJECT_HPP
  2. #define BOOST_SERIALIZATION_BINARY_OBJECT_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. // nvp.hpp: interface for serialization system.
  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. #include <cassert>
  15. #include <cstddef> // std::size_t
  16. #include <boost/config.hpp>
  17. #if defined(BOOST_NO_STDC_NAMESPACE)
  18. namespace std{
  19. using ::size_t;
  20. } // namespace std
  21. #endif
  22. #include <boost/preprocessor/stringize.hpp>
  23. #include <boost/serialization/tracking.hpp>
  24. #include <boost/serialization/level.hpp>
  25. #include <boost/serialization/split_member.hpp>
  26. #include <boost/serialization/nvp.hpp>
  27. #include <boost/serialization/wrapper.hpp>
  28. namespace boost {
  29. namespace serialization {
  30. struct binary_object {
  31. /* const */ void * const m_t;
  32. const std::size_t m_size;
  33. template<class Archive>
  34. void save(Archive & ar, const unsigned int /* file_version */) const {
  35. ar.save_binary(m_t, m_size);
  36. }
  37. template<class Archive>
  38. void load(Archive & ar, const unsigned int /* file_version */) const {
  39. ar.load_binary(const_cast<void *>(m_t), m_size);
  40. }
  41. BOOST_SERIALIZATION_SPLIT_MEMBER()
  42. binary_object(/* const */ void * const t, std::size_t size) :
  43. m_t(t),
  44. m_size(size)
  45. {}
  46. binary_object(const binary_object & rhs) :
  47. m_t(rhs.m_t),
  48. m_size(rhs.m_size)
  49. {}
  50. };
  51. // just a little helper to support the convention that all serialization
  52. // wrappers follow the naming convention make_xxxxx
  53. inline
  54. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  55. const
  56. #endif
  57. binary_object
  58. make_binary_object(/* const */ void * t, std::size_t size){
  59. return binary_object(t, size);
  60. }
  61. // this is a wrapper
  62. template <>
  63. struct is_wrapper<binary_object>
  64. : public mpl::true_
  65. {};
  66. } // namespace serialization
  67. } // boost
  68. // don't need versioning info for this type
  69. BOOST_CLASS_IMPLEMENTATION(
  70. binary_object,
  71. boost::serialization::object_serializable
  72. )
  73. // don't track binary objects - usually they will be created on the stack
  74. // and tracking algorithm (which uses the object address) might get
  75. // confused. note that these address will likely be members of some
  76. // other structure which itself is tracked, so as a practical matter
  77. // suppressing tracking shouldn't cause any redundancy.
  78. BOOST_CLASS_TRACKING(binary_object, boost::serialization::track_never)
  79. #endif // BOOST_SERIALIZATION_BINARY_OBJECT_HPP