interface_iarchive.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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)
  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/archive/detail/helper_collection.hpp>
  20. #include <boost/serialization/singleton.hpp>
  21. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  22. namespace boost {
  23. namespace archive {
  24. namespace detail {
  25. class basic_pointer_iserializer;
  26. template<class Archive>
  27. class interface_iarchive
  28. {
  29. protected:
  30. interface_iarchive(){};
  31. public:
  32. /////////////////////////////////////////////////////////
  33. // archive public interface
  34. typedef mpl::bool_<true> is_loading;
  35. typedef mpl::bool_<false> 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_iserializer *
  42. register_type(T * = NULL){
  43. const basic_pointer_iserializer & bpis =
  44. boost::serialization::singleton<
  45. pointer_iserializer<Archive, T>
  46. >::get_const_instance();
  47. this->This()->register_basic_serializer(bpis.get_basic_serializer());
  48. return & bpis;
  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>>(T & t){
  58. this->This()->load_override(t);
  59. return * this->This();
  60. }
  61. // the & operator
  62. template<class T>
  63. Archive & operator&(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