ephemeral.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef BOOST_SERIALIZATION_EPHEMERAL_HPP
  2. #define BOOST_SERIALIZATION_EPHEMERAL_HPP
  3. // MS compatible compilers support
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // ephemeral_object.hpp: interface for serialization system.
  9. // (C) Copyright 2007 Matthias Troyer.
  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 <utility>
  15. #include <boost/config.hpp>
  16. #include <boost/detail/workaround.hpp>
  17. #include <boost/mpl/integral_c.hpp>
  18. #include <boost/mpl/integral_c_tag.hpp>
  19. #include <boost/serialization/level.hpp>
  20. #include <boost/serialization/tracking.hpp>
  21. #include <boost/serialization/split_member.hpp>
  22. #include <boost/serialization/base_object.hpp>
  23. #include <boost/serialization/traits.hpp>
  24. #include <boost/serialization/wrapper.hpp>
  25. namespace boost {
  26. namespace serialization {
  27. template<class T>
  28. struct ephemeral_object :
  29. public wrapper_traits<ephemeral_object<T> >
  30. {
  31. explicit ephemeral_object(T& t) :
  32. val(t)
  33. {}
  34. T & value() const {
  35. return val;
  36. }
  37. const T & const_value() const {
  38. return val;
  39. }
  40. template<class Archive>
  41. void serialize(Archive &ar, const unsigned int) const
  42. {
  43. ar & val;
  44. }
  45. private:
  46. T & val;
  47. };
  48. template<class T>
  49. inline
  50. const ephemeral_object<T> ephemeral(const char * name, T & t){
  51. return ephemeral_object<T>(name, t);
  52. }
  53. } // seralization
  54. } // boost
  55. #endif // BOOST_SERIALIZATION_EPHEMERAL_HPP