interface_oarchive.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef BOOST_ARCHIVE_DETAIL_INTERFACE_OARCHIVE_HPP
  2. #define BOOST_ARCHIVE_DETAIL_INTERFACE_OARCHIVE_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. // interface_oarchive.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. #include <cstddef> // NULL
  15. #include <boost/cstdint.hpp>
  16. #include <boost/mpl/bool.hpp>
  17. #include <boost/detail/workaround.hpp>
  18. #include <boost/archive/detail/auto_link_archive.hpp>
  19. #include <boost/archive/detail/oserializer.hpp>
  20. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  21. #include <boost/serialization/singleton.hpp>
  22. namespace boost {
  23. namespace archive {
  24. namespace detail {
  25. class basic_pointer_oserializer;
  26. template<class Archive>
  27. class interface_oarchive
  28. {
  29. protected:
  30. interface_oarchive() {}
  31. public:
  32. /////////////////////////////////////////////////////////
  33. // archive public interface
  34. typedef mpl::bool_<false> is_loading;
  35. typedef mpl::bool_<true> is_saving;
  36. // return a pointer to the most derived class
  37. Archive * This(){
  38. return static_cast<Archive*>(this);
  39. }
  40. template<class T>
  41. const basic_pointer_oserializer *
  42. register_type(const T * = NULL){
  43. const basic_pointer_oserializer & bpos =
  44. boost::serialization::singleton<
  45. pointer_oserializer<Archive, T>
  46. >::get_const_instance();
  47. this->This()->register_basic_serializer(bpos.get_basic_serializer());
  48. return & bpos;
  49. }
  50. template<class Helper>
  51. Helper &
  52. get_helper(void * const id = 0){
  53. helper_collection & hc = this->This()->get_helper_collection();
  54. return hc.template find_helper<Helper>(id);
  55. }
  56. template<class T>
  57. Archive & operator<<(const T & t){
  58. this->This()->save_override(t);
  59. return * this->This();
  60. }
  61. // the & operator
  62. template<class T>
  63. Archive & operator&(const T & t){
  64. return * this ->This() << t;
  65. }
  66. };
  67. } // namespace detail
  68. } // namespace archive
  69. } // namespace boost
  70. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  71. #endif // BOOST_ARCHIVE_DETAIL_INTERFACE_IARCHIVE_HPP