log_archive.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef LOG_ARCHIVE_HPP
  2. #define LOG_ARCHIVE_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. // log_archive.hpp
  9. // (C) Copyright 2010 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 <boost/archive/xml_oarchive.hpp>
  15. namespace boost {
  16. namespace archive {
  17. namespace detail {
  18. template<class Archive> class interface_oarchive;
  19. } // namespace detail
  20. } // namespace archive
  21. } // boost
  22. /////////////////////////////////////////////////////////////////////////
  23. // log data to an output stream. This illustrates a simpler implemenation
  24. // of text output which is useful for getting a formatted display of
  25. // any serializable class. Intended to be useful as a debugging aid.
  26. class log_archive :
  27. /* protected ? */
  28. public boost::archive::xml_oarchive_impl<log_archive>
  29. {
  30. typedef boost::archive::xml_oarchive_impl<log_archive> base;
  31. // give serialization implementation access to this clas
  32. friend class boost::archive::detail::interface_oarchive<log_archive>;
  33. friend class boost::archive::basic_xml_oarchive<log_archive>;
  34. friend class boost::archive::save_access;
  35. /////////////////////////////////////////////////////////////////////
  36. // Override functions defined in basic_xml_oarchive
  37. // Anything not an attribute and not a name-value pair is an
  38. // error and should be trapped here.
  39. template<class T>
  40. void save_override(T & t){
  41. // make it a name-value pair and pass it on.
  42. // this permits this to be used even with data types which
  43. // are not wrapped with the name
  44. base::save_override(boost::serialization::make_nvp(NULL, t));
  45. }
  46. template<class T>
  47. void save_override(const boost::serialization::nvp< T > & t){
  48. // this is here to remove the "const" requirement. Since
  49. // this class is to be used only for output, it's not required.
  50. base::save_override(t);
  51. }
  52. // specific overrides for attributes - not name value pairs so we
  53. // want to trap them before the above "fall through"
  54. // since we don't want to see these in the output - make them no-ops.
  55. void save_override(const boost::archive::object_id_type & t){}
  56. void save_override(const boost::archive::object_reference_type & t){}
  57. void save_override(const boost::archive::version_type & t){}
  58. void save_override(const boost::archive::class_id_type & t){}
  59. void save_override(const boost::archive::class_id_optional_type & t){}
  60. void save_override(const boost::archive::class_id_reference_type & t){}
  61. void save_override(const boost::archive::class_name_type & t){}
  62. void save_override(const boost::archive::tracking_type & t){}
  63. public:
  64. log_archive(std::ostream & os, unsigned int flags = 0) :
  65. boost::archive::xml_oarchive_impl<log_archive>(
  66. os,
  67. flags | boost::archive::no_header
  68. )
  69. {}
  70. };
  71. #endif // LOG_ARCHIVE_HPP