binary_object.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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)
  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 <boost/assert.hpp>
  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. public wrapper_traits<nvp<const binary_object> >
  32. {
  33. void const * m_t;
  34. std::size_t m_size;
  35. template<class Archive>
  36. void save(Archive & ar, const unsigned int /* file_version */) const {
  37. ar.save_binary(m_t, m_size);
  38. }
  39. template<class Archive>
  40. void load(Archive & ar, const unsigned int /* file_version */) const {
  41. ar.load_binary(const_cast<void *>(m_t), m_size);
  42. }
  43. BOOST_SERIALIZATION_SPLIT_MEMBER()
  44. binary_object & operator=(const binary_object & rhs) {
  45. m_t = rhs.m_t;
  46. m_size = rhs.m_size;
  47. return *this;
  48. }
  49. binary_object(const void * const t, std::size_t size) :
  50. m_t(t),
  51. m_size(size)
  52. {}
  53. binary_object(const binary_object & rhs) :
  54. m_t(rhs.m_t),
  55. m_size(rhs.m_size)
  56. {}
  57. };
  58. // just a little helper to support the convention that all serialization
  59. // wrappers follow the naming convention make_xxxxx
  60. inline
  61. const binary_object
  62. make_binary_object(const void * t, std::size_t size){
  63. return binary_object(t, size);
  64. }
  65. } // namespace serialization
  66. } // boost
  67. #endif // BOOST_SERIALIZATION_BINARY_OBJECT_HPP