#ifndef GREGORIAN_SERIALIZE_HPP___ #define GREGORIAN_SERIALIZE_HPP___ /* Copyright (c) 2004 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0) * Author: Jeff Garland * $Date: 2003/11/25 03:51:20 $ */ #include "boost/date_time/gregorian/gregorian_types.hpp" #include "boost/date_time/gregorian/parsers.hpp" #include "boost/archive/basic_archive.hpp" #include "boost/serialization/split_free.hpp" #include "boost/serialization/string.hpp" //If this macro is used it must be outside the namespace... //expanded version is below // BOOST_SERIALIZATION_SPLIT_FREE(::boost::gregorian::date) namespace boost { namespace serialization { /*! Method that does serialization for gregorian::date -- splits to load/save */ template inline void serialize(Archive & ar, ::boost::gregorian::date & d, const unsigned int file_version) { split_free(ar, d, file_version); } //! Function to save gregorian::date objects using serialization lib /*! Dates are serialized into a string for transport and storage. * While it would be more efficient to store the internal * integer used to manipulate the dates, it is an unstable solution. */ template void save(Archive & ar, const ::boost::gregorian::date & d, unsigned int version) { std::string ds = to_iso_string(d); ar & ds; } template void load(Archive & ar, ::boost::gregorian::date & d, unsigned int version) { std::string ds; ar >> ds; d = ::boost::gregorian::from_undelimited_string(ds); } //!override needed b/c no default constructor template inline void load_construct_data(Archive & ar, ::boost::gregorian::date* dp, const unsigned int file_version) { // retrieve data from archive required to construct new // invoke inplace constructor to initialize instance of date ::new(dp) ::boost::gregorian::date(::boost::gregorian::not_a_date_time); } } // namespace serialization } // namespace boost #endif