interface_iarchive.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef BOOST_ARCHIVE_DETAIL_INTERFACE_IARCHIVE_HPP
  2. #define BOOST_ARCHIVE_DETAIL_INTERFACE_IARCHIVE_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. // interface_iarchive.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/iserializer.hpp>
  19. #include <boost/serialization/singleton.hpp>
  20. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  21. namespace boost {
  22. namespace archive {
  23. namespace detail {
  24. class BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) basic_pointer_iserializer;
  25. template<class Archive>
  26. class interface_iarchive
  27. {
  28. protected:
  29. interface_iarchive(){};
  30. public:
  31. /////////////////////////////////////////////////////////
  32. // archive public interface
  33. typedef mpl::bool_<true> is_loading;
  34. typedef mpl::bool_<false> 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_iserializer *
  41. register_type(T * = NULL){
  42. const basic_pointer_iserializer & bpis =
  43. boost::serialization::singleton<
  44. pointer_iserializer<Archive, T>
  45. >::get_const_instance();
  46. this->This()->register_basic_serializer(bpis.get_basic_serializer());
  47. return & bpis;
  48. }
  49. template<class T>
  50. Archive & operator>>(T & t){
  51. this->This()->load_override(t, 0);
  52. return * this->This();
  53. }
  54. // the & operator
  55. template<class T>
  56. Archive & operator&(T & t){
  57. return *(this->This()) >> t;
  58. }
  59. };
  60. } // namespace detail
  61. } // namespace archive
  62. } // namespace boost
  63. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  64. #endif // BOOST_ARCHIVE_DETAIL_INTERFACE_IARCHIVE_HPP