stack.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef BOOST_SERIALIZATION_STACK_HPP
  2. #define BOOST_SERIALIZATION_STACK_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. // stack.hpp
  9. // (C) Copyright 2014 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 <stack>
  15. #include <boost/config.hpp>
  16. #include <boost/mpl/eval_if.hpp>
  17. #include <boost/mpl/identity.hpp>
  18. // function specializations must be defined in the appropriate
  19. // namespace - boost::serialization
  20. #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
  21. #define STD _STLP_STD
  22. #else
  23. #define STD std
  24. #endif
  25. namespace boost {
  26. namespace serialization {
  27. namespace detail{
  28. template <typename U, typename C>
  29. struct stack_save : public STD::stack<U, C> {
  30. template<class Archive>
  31. void operator()(Archive & ar, const unsigned int file_version) const {
  32. save(ar, STD::stack<U, C>::c, file_version);
  33. }
  34. };
  35. template <typename U, typename C>
  36. struct stack_load : public STD::stack<U, C> {
  37. template<class Archive>
  38. void operator()(Archive & ar, const unsigned int file_version) {
  39. load(ar, STD::stack<U, C>::c, file_version);
  40. }
  41. };
  42. } // detail
  43. template<class Archive, class T, class C>
  44. inline void serialize(
  45. Archive & ar,
  46. std::stack< T, C> & t,
  47. const unsigned int file_version
  48. ){
  49. typedef typename mpl::eval_if<
  50. typename Archive::is_saving,
  51. mpl::identity<detail::stack_save<T, C> >,
  52. mpl::identity<detail::stack_load<T, C> >
  53. >::type typex;
  54. static_cast<typex &>(t)(ar, file_version);
  55. }
  56. } // namespace serialization
  57. } // namespace boost
  58. #include <boost/serialization/collection_traits.hpp>
  59. BOOST_SERIALIZATION_COLLECTION_TRAITS(STD::stack)
  60. #undef STD
  61. #endif // BOOST_SERIALIZATION_DEQUE_HPP