interface_oarchive.hpp 2.4 KB

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