1 #ifndef LOG_ARCHIVE_HPP 2 #define LOG_ARCHIVE_HPP 3 4 // MS compatible compilers support #pragma once 5 #if defined(_MSC_VER) 6 # pragma once 7 #endif 8 9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 10 // log_archive.hpp 11 12 // (C) Copyright 2010 Robert Ramey - http://www.rrsd.com . 13 // Use, modification and distribution is subject to the Boost Software 14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 15 // http://www.boost.org/LICENSE_1_0.txt) 16 17 // See http://www.boost.org for updates, documentation, and revision history. 18 19 #include <boost/archive/xml_oarchive.hpp> 20 21 namespace boost { 22 namespace archive { 23 namespace detail { 24 template<class Archive> class interface_oarchive; 25 } // namespace detail 26 } // namespace archive 27 } // boost 28 29 ///////////////////////////////////////////////////////////////////////// 30 // log data to an output stream. This illustrates a simpler implemenation 31 // of text output which is useful for getting a formatted display of 32 // any serializable class. Intended to be useful as a debugging aid. 33 class log_archive : 34 /* protected ? */ 35 public boost::archive::xml_oarchive_impl<log_archive> 36 { 37 typedef boost::archive::xml_oarchive_impl<log_archive> base; 38 // give serialization implementation access to this clas 39 friend class boost::archive::detail::interface_oarchive<log_archive>; 40 friend class boost::archive::basic_xml_oarchive<log_archive>; 41 friend class boost::archive::save_access; 42 43 ///////////////////////////////////////////////////////////////////// 44 // Override functions defined in basic_xml_oarchive 45 46 // Anything not an attribute and not a name-value pair is an 47 // error and should be trapped here. 48 template<class T> save_override(T & t)49 void save_override(T & t){ 50 // make it a name-value pair and pass it on. 51 // this permits this to be used even with data types which 52 // are not wrapped with the name 53 base::save_override(boost::serialization::make_nvp(NULL, t)); 54 } 55 template<class T> save_override(const boost::serialization::nvp<T> & t)56 void save_override(const boost::serialization::nvp< T > & t){ 57 // this is here to remove the "const" requirement. Since 58 // this class is to be used only for output, it's not required. 59 base::save_override(t); 60 } 61 // specific overrides for attributes - not name value pairs so we 62 // want to trap them before the above "fall through" 63 // since we don't want to see these in the output - make them no-ops. save_override(const boost::archive::object_id_type & t)64 void save_override(const boost::archive::object_id_type & t){} save_override(const boost::archive::object_reference_type & t)65 void save_override(const boost::archive::object_reference_type & t){} save_override(const boost::archive::version_type & t)66 void save_override(const boost::archive::version_type & t){} save_override(const boost::archive::class_id_type & t)67 void save_override(const boost::archive::class_id_type & t){} save_override(const boost::archive::class_id_optional_type & t)68 void save_override(const boost::archive::class_id_optional_type & t){} save_override(const boost::archive::class_id_reference_type & t)69 void save_override(const boost::archive::class_id_reference_type & t){} save_override(const boost::archive::class_name_type & t)70 void save_override(const boost::archive::class_name_type & t){} save_override(const boost::archive::tracking_type & t)71 void save_override(const boost::archive::tracking_type & t){} 72 public: log_archive(std::ostream & os,unsigned int flags=0)73 log_archive(std::ostream & os, unsigned int flags = 0) : 74 boost::archive::xml_oarchive_impl<log_archive>( 75 os, 76 flags | boost::archive::no_header 77 ) 78 {} 79 }; 80 81 #endif // LOG_ARCHIVE_HPP 82