diff options
Diffstat (limited to 'boost/archive')
40 files changed, 458 insertions, 533 deletions
diff --git a/boost/archive/add_facet.hpp b/boost/archive/add_facet.hpp deleted file mode 100644 index 242bdd9001..0000000000 --- a/boost/archive/add_facet.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef BOOST_ARCHIVE_ADD_FACET_HPP -#define BOOST_ARCHIVE_ADD_FACET_HPP - -// MS compatible compilers support #pragma once -#if defined(_MSC_VER) -# pragma once -#endif - -/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -// add_facet.hpp - -// (C) Copyright 2003 Robert Ramey - http://www.rrsd.com . -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org for updates, documentation, and revision history. - -#include <locale> -#include <boost/config.hpp> -#include <boost/detail/workaround.hpp> - -// does STLport uses native STL for locales? -#if (defined(__SGI_STL_PORT)&& defined(_STLP_NO_OWN_IOSTREAMS)) -// and this native STL lib is old Dinkumware (has not defined _CPPLIB_VER) -# if (defined(_YVALS) && !defined(__IBMCPP__)) || !defined(_CPPLIB_VER) -# define BOOST_ARCHIVE_OLD_DINKUMWARE_BENEATH_STLPORT -# endif -#endif - -namespace boost { -namespace archive { - -template<class Facet> -inline std::locale * -add_facet(const std::locale &l, Facet * f){ - return - #if defined BOOST_ARCHIVE_OLD_DINKUMWARE_BENEATH_STLPORT - // std namespace used for native locale - new std::locale(std::_Addfac(l, f)); - #elif BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) // old Dinkumwar - // std namespace used for native locale - new std::locale(std::_Addfac(l, f)); - #else - // standard compatible - new std::locale(l, f); - #endif -} - -} // namespace archive -} // namespace boost - -#undef BOOST_ARCHIVE_OLD_DINKUMWARE_BENEATH_STLPORT - -#endif // BOOST_ARCHIVE_ADD_FACET_HPP diff --git a/boost/archive/basic_binary_iprimitive.hpp b/boost/archive/basic_binary_iprimitive.hpp index 5e826310d7..40f45d9c2f 100644 --- a/boost/archive/basic_binary_iprimitive.hpp +++ b/boost/archive/basic_binary_iprimitive.hpp @@ -44,16 +44,16 @@ namespace std{ #endif #include <boost/cstdint.hpp> -#include <boost/scoped_ptr.hpp> #include <boost/serialization/throw_exception.hpp> #include <boost/integer.hpp> #include <boost/integer_traits.hpp> -#include <boost/mpl/placeholders.hpp> +//#include <boost/mpl/placeholders.hpp> #include <boost/serialization/is_bitwise_serializable.hpp> #include <boost/serialization/array.hpp> #include <boost/archive/basic_streambuf_locale_saver.hpp> +#include <boost/archive/codecvt_null.hpp> #include <boost/archive/archive_exception.hpp> #include <boost/archive/detail/auto_link_archive.hpp> #include <boost/archive/detail/abi_prefix.hpp> // must be the last header @@ -61,9 +61,6 @@ namespace std{ namespace boost { namespace archive { -template<class Ch> -class codecvt_null; - ///////////////////////////////////////////////////////////////////////////// // class binary_iarchive - read serialized objects from a input binary stream template<class Archive, class Elem, class Tr> @@ -81,9 +78,16 @@ public: } #ifndef BOOST_NO_STD_LOCALE - boost::scoped_ptr<codecvt_null<Elem> > codecvt_facet; - boost::scoped_ptr<std::locale> archive_locale; + // note order! - if you change this, libstd++ will fail! + // a) create new locale with new codecvt facet + // b) save current locale + // c) change locale to new one + // d) use stream buffer + // e) change locale back to original + // f) destroy new codecvt facet + boost::archive::codecvt_null<Elem> codecvt_null_facet; basic_streambuf_locale_saver<Elem, Tr> locale_saver; + std::locale archive_locale; #endif // main template for serilization of primitive types @@ -139,7 +143,7 @@ public: // the optimized load_array dispatches to load_binary template <class ValueType> - void load_array(serialization::array<ValueType>& a, unsigned int) + void load_array(serialization::array_wrapper<ValueType>& a, unsigned int) { load_binary(a.address(),a.count()*sizeof(ValueType)); } diff --git a/boost/archive/basic_binary_oprimitive.hpp b/boost/archive/basic_binary_oprimitive.hpp index f2ea6aa3ea..4b7f454b25 100644 --- a/boost/archive/basic_binary_oprimitive.hpp +++ b/boost/archive/basic_binary_oprimitive.hpp @@ -43,20 +43,19 @@ namespace std{ #include <boost/scoped_ptr.hpp> #include <boost/serialization/throw_exception.hpp> -#include <boost/archive/basic_streambuf_locale_saver.hpp> -#include <boost/archive/archive_exception.hpp> +//#include <boost/mpl/placeholders.hpp> #include <boost/serialization/is_bitwise_serializable.hpp> -#include <boost/mpl/placeholders.hpp> #include <boost/serialization/array.hpp> + +#include <boost/archive/basic_streambuf_locale_saver.hpp> +#include <boost/archive/codecvt_null.hpp> +#include <boost/archive/archive_exception.hpp> #include <boost/archive/detail/auto_link_archive.hpp> #include <boost/archive/detail/abi_prefix.hpp> // must be the last header namespace boost { namespace archive { -template<class Ch> -class codecvt_null; - ///////////////////////////////////////////////////////////////////////// // class basic_binary_oprimitive - binary output of prmitives @@ -74,9 +73,16 @@ public: return static_cast<Archive *>(this); } #ifndef BOOST_NO_STD_LOCALE - boost::scoped_ptr<codecvt_null<Elem> > codecvt_facet; - boost::scoped_ptr<std::locale> archive_locale; + // note order! - if you change this, libstd++ will fail! + // a) create new locale with new codecvt facet + // b) save current locale + // c) change locale to new one + // d) use stream buffer + // e) change locale back to original + // f) destroy new codecvt facet + boost::archive::codecvt_null<Elem> codecvt_null_facet; basic_streambuf_locale_saver<Elem, Tr> locale_saver; + std::locale archive_locale; #endif // default saving of primitives. template<class T> @@ -131,11 +137,10 @@ public: struct apply : public boost::serialization::is_bitwise_serializable< T > {}; #endif }; - // the optimized save_array dispatches to save_binary template <class ValueType> - void save_array(boost::serialization::array<ValueType> const& a, unsigned int) + void save_array(boost::serialization::array_wrapper<ValueType> const& a, unsigned int) { save_binary(a.address(),a.count()*sizeof(ValueType)); } diff --git a/boost/archive/basic_streambuf_locale_saver.hpp b/boost/archive/basic_streambuf_locale_saver.hpp index 64c8e5d314..5cd4b36f08 100644 --- a/boost/archive/basic_streambuf_locale_saver.hpp +++ b/boost/archive/basic_streambuf_locale_saver.hpp @@ -27,6 +27,7 @@ #ifndef BOOST_NO_STD_LOCALE #include <locale> // for std::locale +#include <ios> #include <streambuf> // for std::basic_streambuf #include <boost/config.hpp> @@ -45,25 +46,57 @@ class basic_streambuf_locale_saver : private boost::noncopyable { public: - typedef ::std::basic_streambuf<Ch, Tr> state_type; - typedef ::std::locale aspect_type; - explicit basic_streambuf_locale_saver( state_type &s ) - : s_save_( s ), a_save_( s.getloc() ) - {} - explicit basic_streambuf_locale_saver( state_type &s, aspect_type const &a ) - : s_save_( s ), a_save_( s.pubimbue(a) ) - {} - ~basic_streambuf_locale_saver() - { this->restore(); } - void restore(){ - s_save_.pubsync(); - s_save_.pubimbue( a_save_ ); + explicit basic_streambuf_locale_saver(std::basic_streambuf<Ch, Tr> &s) : + m_streambuf(s), + m_locale(s.getloc()) + {} + ~basic_streambuf_locale_saver(){ + m_streambuf.pubsync(); + m_streambuf.pubimbue(m_locale); } private: - state_type & s_save_; - aspect_type const a_save_; + std::basic_streambuf<Ch, Tr> & m_streambuf; + std::locale const m_locale; }; +template < typename Ch, class Tr > +class basic_istream_locale_saver : + private boost::noncopyable +{ +public: + explicit basic_istream_locale_saver(std::basic_istream<Ch, Tr> &s) : + m_istream(s), + m_locale(s.getloc()) + {} + ~basic_istream_locale_saver(){ + // libstdc++ crashes without this + m_istream.sync(); + m_istream.imbue(m_locale); + } +private: + std::basic_istream<Ch, Tr> & m_istream; + std::locale const m_locale; +}; + +template < typename Ch, class Tr > +class basic_ostream_locale_saver : + private boost::noncopyable +{ +public: + explicit basic_ostream_locale_saver(std::basic_ostream<Ch, Tr> &s) : + m_ostream(s), + m_locale(s.getloc()) + {} + ~basic_ostream_locale_saver(){ + m_ostream.flush(); + m_ostream.imbue(m_locale); + } +private: + std::basic_ostream<Ch, Tr> & m_ostream; + std::locale const m_locale; +}; + + } // archive } // boost diff --git a/boost/archive/basic_text_iprimitive.hpp b/boost/archive/basic_text_iprimitive.hpp index 08da95c36e..bf936b5554 100644 --- a/boost/archive/basic_text_iprimitive.hpp +++ b/boost/archive/basic_text_iprimitive.hpp @@ -24,7 +24,6 @@ // in such cases. So we can't use basic_ostream<IStream::char_type> but rather // use two template parameters -#include <boost/assert.hpp> #include <locale> #include <cstddef> // size_t @@ -38,17 +37,15 @@ namespace std{ } // namespace std #endif +#include <boost/io/ios_state.hpp> +#include <boost/static_assert.hpp> + #include <boost/detail/workaround.hpp> #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) #include <boost/archive/dinkumware.hpp> #endif - -#include <boost/limits.hpp> -#include <boost/io/ios_state.hpp> -#include <boost/scoped_ptr.hpp> -#include <boost/static_assert.hpp> - #include <boost/serialization/throw_exception.hpp> +#include <boost/archive/codecvt_null.hpp> #include <boost/archive/archive_exception.hpp> #include <boost/archive/basic_streambuf_locale_saver.hpp> #include <boost/archive/detail/abi_prefix.hpp> // must be the last header @@ -71,9 +68,17 @@ protected: io::ios_precision_saver precision_saver; #ifndef BOOST_NO_STD_LOCALE - boost::scoped_ptr<std::locale> archive_locale; - basic_streambuf_locale_saver< - typename IStream::char_type, + // note order! - if you change this, libstd++ will fail! + // a) create new locale with new codecvt facet + // b) save current locale + // c) change locale to new one + // d) use stream buffer + // e) change locale back to original + // f) destroy new codecvt facet + boost::archive::codecvt_null<typename IStream::char_type> codecvt_null_facet; + std::locale archive_locale; + basic_istream_locale_saver< + typename IStream::char_type, typename IStream::traits_type > locale_saver; #endif diff --git a/boost/archive/basic_text_oprimitive.hpp b/boost/archive/basic_text_oprimitive.hpp index 86330921d2..c9f8c59160 100644 --- a/boost/archive/basic_text_oprimitive.hpp +++ b/boost/archive/basic_text_oprimitive.hpp @@ -26,14 +26,13 @@ #include <iomanip> #include <locale> -#include <boost/assert.hpp> #include <cstddef> // size_t #include <boost/config.hpp> #include <boost/static_assert.hpp> -#include <boost/detail/workaround.hpp> #include <boost/io/ios_state.hpp> +#include <boost/detail/workaround.hpp> #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) #include <boost/archive/dinkumware.hpp> #endif @@ -52,10 +51,10 @@ namespace std{ #include <boost/limits.hpp> #include <boost/integer.hpp> #include <boost/io/ios_state.hpp> -#include <boost/scoped_ptr.hpp> #include <boost/serialization/throw_exception.hpp> -#include <boost/archive/archive_exception.hpp> #include <boost/archive/basic_streambuf_locale_saver.hpp> +#include <boost/archive/codecvt_null.hpp> +#include <boost/archive/archive_exception.hpp> #include <boost/archive/detail/abi_prefix.hpp> // must be the last header namespace boost { @@ -72,9 +71,17 @@ protected: io::ios_precision_saver precision_saver; #ifndef BOOST_NO_STD_LOCALE - boost::scoped_ptr<std::locale> archive_locale; - basic_streambuf_locale_saver< - typename OStream::char_type, + // note order! - if you change this, libstd++ will fail! + // a) create new locale with new codecvt facet + // b) save current locale + // c) change locale to new one + // d) use stream buffer + // e) change locale back to original + // f) destroy new codecvt facet + boost::archive::codecvt_null<typename OStream::char_type> codecvt_null_facet; + std::locale archive_locale; + basic_ostream_locale_saver< + typename OStream::char_type, typename OStream::traits_type > locale_saver; #endif diff --git a/boost/archive/basic_xml_iarchive.hpp b/boost/archive/basic_xml_iarchive.hpp index 7834d8a100..a882df5615 100644 --- a/boost/archive/basic_xml_iarchive.hpp +++ b/boost/archive/basic_xml_iarchive.hpp @@ -17,15 +17,12 @@ // See http://www.boost.org for updates, documentation, and revision history. #include <boost/config.hpp> -#include <boost/detail/workaround.hpp> +#include <boost/mpl/assert.hpp> #include <boost/archive/detail/common_iarchive.hpp> - #include <boost/serialization/nvp.hpp> #include <boost/serialization/string.hpp> -#include <boost/mpl/assert.hpp> - #include <boost/archive/detail/abi_prefix.hpp> // must be the last header #ifdef BOOST_MSVC @@ -41,24 +38,18 @@ namespace detail { } // namespace detail ///////////////////////////////////////////////////////////////////////// -// class xml_iarchive - read serialized objects from a input text stream +// class basic_xml_iarchive - read serialized objects from a input text stream template<class Archive> class BOOST_SYMBOL_VISIBLE basic_xml_iarchive : public detail::common_iarchive<Archive> { + unsigned int depth; #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else protected: - #if BOOST_WORKAROUND(BOOST_MSVC, < 1500) - // for some inexplicable reason insertion of "class" generates compile erro - // on msvc 7.1 - friend detail::interface_iarchive<Archive>; - #else - friend class detail::interface_iarchive<Archive>; - #endif + friend class detail::interface_iarchive<Archive>; #endif - unsigned int depth; BOOST_ARCHIVE_OR_WARCHIVE_DECL void load_start(const char *name); BOOST_ARCHIVE_OR_WARCHIVE_DECL void @@ -96,14 +87,15 @@ protected: // an xml archive. So we can skip it here. Note: we MUST override // it otherwise it will be loaded as a normal primitive w/o tag and // leaving the archive in an undetermined state - void load_override(class_id_optional_type & /* t */){} + BOOST_ARCHIVE_OR_WARCHIVE_DECL void + load_override(class_id_type & t); + BOOST_ARCHIVE_OR_WARCHIVE_DECL void + load_override(class_id_optional_type & /* t */){} BOOST_ARCHIVE_OR_WARCHIVE_DECL void load_override(object_id_type & t); BOOST_ARCHIVE_OR_WARCHIVE_DECL void load_override(version_type & t); BOOST_ARCHIVE_OR_WARCHIVE_DECL void - load_override(class_id_type & t); - BOOST_ARCHIVE_OR_WARCHIVE_DECL void load_override(tracking_type & t); // class_name_type can't be handled here as it depends upon the // char type used by the stream. So require the derived implementation diff --git a/boost/archive/basic_xml_oarchive.hpp b/boost/archive/basic_xml_oarchive.hpp index 0325eee653..107fca4ec6 100644 --- a/boost/archive/basic_xml_oarchive.hpp +++ b/boost/archive/basic_xml_oarchive.hpp @@ -18,15 +18,11 @@ #include <boost/config.hpp> #include <boost/mpl/assert.hpp> -#include <boost/detail/workaround.hpp> #include <boost/archive/detail/common_oarchive.hpp> - #include <boost/serialization/nvp.hpp> -#include <boost/serialization/tracking.hpp> #include <boost/serialization/string.hpp> - #include <boost/archive/detail/abi_prefix.hpp> // must be the last header #ifdef BOOST_MSVC @@ -47,28 +43,23 @@ template<class Archive> class BOOST_SYMBOL_VISIBLE basic_xml_oarchive : public detail::common_oarchive<Archive> { + // special stuff for xml output + unsigned int depth; + bool pending_preamble; #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else protected: -#endif -#if BOOST_WORKAROUND(BOOST_MSVC, < 1500) - // for some inexplicable reason insertion of "class" generates compile erro - // on msvc 7.1 - friend detail::interface_oarchive<Archive>; -#else friend class detail::interface_oarchive<Archive>; #endif - friend class save_access; - // special stuff for xml output - unsigned int depth; bool indent_next; - bool pending_preamble; BOOST_ARCHIVE_OR_WARCHIVE_DECL void indent(); BOOST_ARCHIVE_OR_WARCHIVE_DECL void init(); BOOST_ARCHIVE_OR_WARCHIVE_DECL void + windup(); + BOOST_ARCHIVE_OR_WARCHIVE_DECL void write_attribute( const char *attribute_name, int t, @@ -113,18 +104,18 @@ protected: // specific overrides for attributes - not name value pairs so we // want to trap them before the above "fall through" BOOST_ARCHIVE_OR_WARCHIVE_DECL void - save_override(const object_id_type & t); - BOOST_ARCHIVE_OR_WARCHIVE_DECL void - save_override(const object_reference_type & t); - BOOST_ARCHIVE_OR_WARCHIVE_DECL void - save_override(const version_type & t); - BOOST_ARCHIVE_OR_WARCHIVE_DECL void save_override(const class_id_type & t); BOOST_ARCHIVE_OR_WARCHIVE_DECL void save_override(const class_id_optional_type & t); BOOST_ARCHIVE_OR_WARCHIVE_DECL void save_override(const class_id_reference_type & t); BOOST_ARCHIVE_OR_WARCHIVE_DECL void + save_override(const object_id_type & t); + BOOST_ARCHIVE_OR_WARCHIVE_DECL void + save_override(const object_reference_type & t); + BOOST_ARCHIVE_OR_WARCHIVE_DECL void + save_override(const version_type & t); + BOOST_ARCHIVE_OR_WARCHIVE_DECL void save_override(const class_name_type & t); BOOST_ARCHIVE_OR_WARCHIVE_DECL void save_override(const tracking_type & t); diff --git a/boost/archive/binary_iarchive_impl.hpp b/boost/archive/binary_iarchive_impl.hpp index 3ff994ad83..b4747c98ec 100644 --- a/boost/archive/binary_iarchive_impl.hpp +++ b/boost/archive/binary_iarchive_impl.hpp @@ -33,7 +33,7 @@ namespace detail { } // namespace detail template<class Archive, class Elem, class Tr> -class binary_iarchive_impl : +class BOOST_SYMBOL_VISIBLE binary_iarchive_impl : public basic_binary_iprimitive<Archive, Elem, Tr>, public basic_binary_iarchive<Archive> { @@ -58,8 +58,9 @@ protected: this->basic_binary_iarchive<Archive>::load_override(t); } void init(unsigned int flags){ - if(0 != (flags & no_header)) + if(0 != (flags & no_header)){ return; + } #if ! defined(__MWERKS__) this->basic_binary_iarchive<Archive>::init(); this->basic_binary_iprimitive<Archive, Elem, Tr>::init(); diff --git a/boost/archive/binary_oarchive_impl.hpp b/boost/archive/binary_oarchive_impl.hpp index 76e3a6565b..6b4d018a56 100644 --- a/boost/archive/binary_oarchive_impl.hpp +++ b/boost/archive/binary_oarchive_impl.hpp @@ -34,7 +34,7 @@ namespace detail { } // namespace detail template<class Archive, class Elem, class Tr> -class binary_oarchive_impl : +class BOOST_SYMBOL_VISIBLE binary_oarchive_impl : public basic_binary_oprimitive<Archive, Elem, Tr>, public basic_binary_oarchive<Archive> { @@ -59,8 +59,9 @@ protected: this->basic_binary_oarchive<Archive>::save_override(t); } void init(unsigned int flags) { - if(0 != (flags & no_header)) + if(0 != (flags & no_header)){ return; + } #if ! defined(__MWERKS__) this->basic_binary_oarchive<Archive>::init(); this->basic_binary_oprimitive<Archive, Elem, Tr>::init(); diff --git a/boost/archive/codecvt_null.hpp b/boost/archive/codecvt_null.hpp index 324122b78a..9cc9e5729d 100644 --- a/boost/archive/codecvt_null.hpp +++ b/boost/archive/codecvt_null.hpp @@ -56,10 +56,11 @@ public: explicit codecvt_null(std::size_t no_locale_manage = 0) : std::codecvt<char, char, std::mbstate_t>(no_locale_manage) {} + virtual ~codecvt_null(){}; }; template<> -class codecvt_null<wchar_t> : public std::codecvt<wchar_t, char, std::mbstate_t> +class BOOST_SYMBOL_VISIBLE codecvt_null<wchar_t> : public std::codecvt<wchar_t, char, std::mbstate_t> { virtual BOOST_WARCHIVE_DECL std::codecvt_base::result do_out( @@ -91,6 +92,7 @@ public: explicit codecvt_null(std::size_t no_locale_manage = 0) : std::codecvt<wchar_t, char, std::mbstate_t>(no_locale_manage) {} + virtual ~codecvt_null(){}; }; } // namespace archive diff --git a/boost/archive/detail/basic_serializer.hpp b/boost/archive/detail/basic_serializer.hpp index c7d3b4befc..f9c4203f86 100644 --- a/boost/archive/detail/basic_serializer.hpp +++ b/boost/archive/detail/basic_serializer.hpp @@ -41,9 +41,7 @@ protected: const boost::serialization::extended_type_info & eti ) : m_eti(& eti) - { - BOOST_ASSERT(NULL != & eti); - } + {} public: inline bool operator<(const basic_serializer & rhs) const { diff --git a/boost/archive/detail/common_iarchive.hpp b/boost/archive/detail/common_iarchive.hpp index b4c44d2767..82304f1e5a 100644 --- a/boost/archive/detail/common_iarchive.hpp +++ b/boost/archive/detail/common_iarchive.hpp @@ -35,7 +35,7 @@ class extended_type_info; // note: referred to as Curiously Recurring Template Patter (CRTP) template<class Archive> -class common_iarchive : +class BOOST_SYMBOL_VISIBLE common_iarchive : public basic_iarchive, public interface_iarchive<Archive> { diff --git a/boost/archive/detail/common_oarchive.hpp b/boost/archive/detail/common_oarchive.hpp index 13c71bc5a8..ee42bbe597 100644 --- a/boost/archive/detail/common_oarchive.hpp +++ b/boost/archive/detail/common_oarchive.hpp @@ -32,7 +32,8 @@ namespace detail { // note: referred to as Curiously Recurring Template Patter (CRTP) template<class Archive> -class common_oarchive : + +class BOOST_SYMBOL_VISIBLE common_oarchive : public basic_oarchive, public interface_oarchive<Archive> { diff --git a/boost/archive/detail/decl.hpp b/boost/archive/detail/decl.hpp index bb386d86f8..4f731cded3 100644 --- a/boost/archive/detail/decl.hpp +++ b/boost/archive/detail/decl.hpp @@ -29,14 +29,12 @@ #else #define BOOST_ARCHIVE_DECL BOOST_SYMBOL_IMPORT #endif + #if defined(BOOST_WARCHIVE_SOURCE) #define BOOST_WARCHIVE_DECL BOOST_SYMBOL_EXPORT #else #define BOOST_WARCHIVE_DECL BOOST_SYMBOL_IMPORT #endif - #if !defined(BOOST_WARCHIVE_SOURCE) && !defined(BOOST_ARCHIVE_SOURCE) - #define BOOST_ARCHIVE_OR_WARCHIVE_DECL BOOST_SYMBOL_IMPORT - #endif #if defined(BOOST_WARCHIVE_SOURCE) || defined(BOOST_ARCHIVE_SOURCE) #define BOOST_ARCHIVE_OR_WARCHIVE_DECL BOOST_SYMBOL_EXPORT diff --git a/boost/archive/detail/iserializer.hpp b/boost/archive/detail/iserializer.hpp index 6419e623c8..6bec499bd2 100644 --- a/boost/archive/detail/iserializer.hpp +++ b/boost/archive/detail/iserializer.hpp @@ -39,7 +39,6 @@ namespace std{ #include <boost/mpl/identity.hpp> #include <boost/mpl/greater_equal.hpp> #include <boost/mpl/equal_to.hpp> -#include <boost/mpl/bool.hpp> #include <boost/core/no_exceptions_support.hpp> #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO @@ -226,15 +225,6 @@ struct heap_allocation { static T * invoke_new() { return static_cast<T *>((T::operator new)(sizeof(T))); } - template<void D(void *, std::size_t)> - static void deleter(void * t, std::size_t s){ - D(t, s); - } - - template<void D(void *)> - static void deleter(void * t, std::size_t s){ - D(t); - } static void invoke_delete(T * t) { // if compilation fails here, the likely cause that the class // T has a class specific new operator but no class specific @@ -244,7 +234,7 @@ struct heap_allocation { // that the class might have class specific new with NO // class specific delete at all. Patches (compatible with // C++03) welcome! - deleter<T::operator delete>(t, sizeof(T)); + delete t; } }; struct doesnt_have_new_operator { @@ -253,7 +243,7 @@ struct heap_allocation { } static void invoke_delete(T * t) { // Note: I'm reliance upon automatic conversion from T * to void * here - (operator delete)(t); + delete t; } }; static T * invoke_new() { diff --git a/boost/archive/detail/oserializer.hpp b/boost/archive/detail/oserializer.hpp index 7a7e239376..0f2e733c58 100644 --- a/boost/archive/detail/oserializer.hpp +++ b/boost/archive/detail/oserializer.hpp @@ -33,6 +33,7 @@ #include <boost/mpl/equal_to.hpp> #include <boost/mpl/greater_equal.hpp> #include <boost/mpl/identity.hpp> +#include <boost/mpl/bool_fwd.hpp> #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO #include <boost/serialization/extended_type_info_typeid.hpp> diff --git a/boost/archive/detail/utf8_codecvt_facet.hpp b/boost/archive/detail/utf8_codecvt_facet.hpp index b2430d5a43..dfbec6bdfd 100644 --- a/boost/archive/detail/utf8_codecvt_facet.hpp +++ b/boost/archive/detail/utf8_codecvt_facet.hpp @@ -7,10 +7,17 @@ #ifndef BOOST_ARCHIVE_DETAIL_UTF8_CODECVT_FACET_HPP #define BOOST_ARCHIVE_DETAIL_UTF8_CODECVT_FACET_HPP -#ifdef BOOST_NO_CXX11_HDR_CODECVT +#include <boost/config.hpp> + +// std::codecvt_utf8 doesn't seem to work for msvc +// versions prior to MSVC 14.0 + +#if defined(_MSC_VER) && _MSC_VER < 1900 \ +|| defined( BOOST_NO_CXX11_HDR_CODECVT ) + #include <boost/archive/detail/decl.hpp> #define BOOST_UTF8_BEGIN_NAMESPACE \ namespace boost { namespace archive { namespace detail { - #define BOOST_UTF8_DECL + #define BOOST_UTF8_DECL BOOST_ARCHIVE_DECL #define BOOST_UTF8_END_NAMESPACE }}} #include <boost/detail/utf8_codecvt_facet.hpp> @@ -18,6 +25,10 @@ #undef BOOST_UTF8_END_NAMESPACE #undef BOOST_UTF8_DECL #undef BOOST_UTF8_BEGIN_NAMESPACE +#else + #include <codecvt> + namespace boost { namespace archive { namespace detail { + typedef std::codecvt_utf8<wchar_t> utf8_codecvt_facet; + } } } #endif // BOOST_NO_CXX11_HDR_CODECVT #endif // BOOST_ARCHIVE_DETAIL_UTF8_CODECVT_FACET_HPP - diff --git a/boost/archive/impl/basic_binary_iprimitive.ipp b/boost/archive/impl/basic_binary_iprimitive.ipp index bee7bafea9..7082b003e7 100644 --- a/boost/archive/impl/basic_binary_iprimitive.ipp +++ b/boost/archive/impl/basic_binary_iprimitive.ipp @@ -20,14 +20,9 @@ namespace std{ } // namespace std #endif -#include <boost/detail/workaround.hpp> // fixup for RogueWave - #include <boost/serialization/throw_exception.hpp> - #include <boost/core/no_exceptions_support.hpp> #include <boost/archive/archive_exception.hpp> -#include <boost/archive/codecvt_null.hpp> -#include <boost/archive/add_facet.hpp> #include <boost/archive/basic_binary_iprimitive.hpp> namespace boost { @@ -152,16 +147,13 @@ basic_binary_iprimitive<Archive, Elem, Tr>::basic_binary_iprimitive( ) : #ifndef BOOST_NO_STD_LOCALE m_sb(sb), - locale_saver(m_sb) + codecvt_null_facet(1), + locale_saver(m_sb), + archive_locale(sb.getloc(), & codecvt_null_facet) { if(! no_codecvt){ - archive_locale.reset( - add_facet( - std::locale::classic(), - new codecvt_null<Elem> - ) - ); - //m_sb.pubimbue(* archive_locale); + m_sb.pubsync(); + m_sb.pubimbue(archive_locale); } } #else @@ -169,42 +161,11 @@ basic_binary_iprimitive<Archive, Elem, Tr>::basic_binary_iprimitive( {} #endif -// some libraries including stl and libcomo fail if the -// buffer isn't flushed before the code_cvt facet is changed. -// I think this is a bug. We explicity invoke sync to when -// we're done with the streambuf to work around this problem. -// Note that sync is a protected member of stream buff so we -// have to invoke it through a contrived derived class. -namespace detail { -// note: use "using" to get past msvc bug -using namespace std; -template<class Elem, class Tr> -class input_streambuf_access : public std::basic_streambuf<Elem, Tr> { - public: - virtual int sync(){ -#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) - return this->basic_streambuf::sync(); -#else - return this->basic_streambuf<Elem, Tr>::sync(); -#endif - } -}; -} // detail - -// scoped_ptr requires that archive_locale be a complete type at time of +// scoped_ptr requires that g be a complete type at time of // destruction so define destructor here rather than in the header template<class Archive, class Elem, class Tr> BOOST_ARCHIVE_OR_WARCHIVE_DECL -basic_binary_iprimitive<Archive, Elem, Tr>::~basic_binary_iprimitive(){ - // push back unread characters - //destructor can't throw ! - BOOST_TRY{ - static_cast<detail::input_streambuf_access<Elem, Tr> &>(m_sb).sync(); - } - BOOST_CATCH(...){ - } - BOOST_CATCH_END -} +basic_binary_iprimitive<Archive, Elem, Tr>::~basic_binary_iprimitive(){} } // namespace archive } // namespace boost diff --git a/boost/archive/impl/basic_binary_oprimitive.ipp b/boost/archive/impl/basic_binary_oprimitive.ipp index 88cc12433c..130831e4fb 100644 --- a/boost/archive/impl/basic_binary_oprimitive.ipp +++ b/boost/archive/impl/basic_binary_oprimitive.ipp @@ -27,10 +27,6 @@ namespace std{ using ::wcslen; } #endif #endif -#include <boost/detail/workaround.hpp> - -#include <boost/archive/add_facet.hpp> -#include <boost/archive/codecvt_null.hpp> #include <boost/archive/basic_binary_oprimitive.hpp> #include <boost/core/no_exceptions_support.hpp> @@ -104,16 +100,13 @@ basic_binary_oprimitive<Archive, Elem, Tr>::basic_binary_oprimitive( ) : #ifndef BOOST_NO_STD_LOCALE m_sb(sb), - locale_saver(m_sb) + codecvt_null_facet(1), + locale_saver(m_sb), + archive_locale(sb.getloc(), & codecvt_null_facet) { if(! no_codecvt){ - archive_locale.reset( - add_facet( - std::locale::classic(), - new codecvt_null<Elem> - ) - ); - //m_sb.pubimbue(* archive_locale); + m_sb.pubsync(); + m_sb.pubimbue(archive_locale); } } #else @@ -121,42 +114,11 @@ basic_binary_oprimitive<Archive, Elem, Tr>::basic_binary_oprimitive( {} #endif -// some libraries including stl and libcomo fail if the -// buffer isn't flushed before the code_cvt facet is changed. -// I think this is a bug. We explicity invoke sync to when -// we're done with the streambuf to work around this problem. -// Note that sync is a protected member of stream buff so we -// have to invoke it through a contrived derived class. -namespace detail { -// note: use "using" to get past msvc bug -using namespace std; -template<class Elem, class Tr> -class output_streambuf_access : public std::basic_streambuf<Elem, Tr> { - public: - virtual int sync(){ -#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) - return this->basic_streambuf::sync(); -#else - return this->basic_streambuf<Elem, Tr>::sync(); -#endif - } -}; -} // detail - // scoped_ptr requires that g be a complete type at time of // destruction so define destructor here rather than in the header template<class Archive, class Elem, class Tr> BOOST_ARCHIVE_OR_WARCHIVE_DECL -basic_binary_oprimitive<Archive, Elem, Tr>::~basic_binary_oprimitive(){ - // flush buffer - //destructor can't throw - BOOST_TRY{ - static_cast<detail::output_streambuf_access<Elem, Tr> &>(m_sb).sync(); - } - BOOST_CATCH(...){ - } - BOOST_CATCH_END -} +basic_binary_oprimitive<Archive, Elem, Tr>::~basic_binary_oprimitive(){} } // namespace archive } // namespace boost diff --git a/boost/archive/impl/basic_text_iprimitive.ipp b/boost/archive/impl/basic_text_iprimitive.ipp index e245dc540f..4e44728068 100644 --- a/boost/archive/impl/basic_text_iprimitive.ipp +++ b/boost/archive/impl/basic_text_iprimitive.ipp @@ -8,8 +8,8 @@ // See http://www.boost.org for updates, documentation, and revision history. -#include <cstddef> // size_t -#include <cstddef> // NULL +#include <cstddef> // size_t, NULL +#include <limits> // NULL #include <boost/config.hpp> #if defined(BOOST_NO_STDC_NAMESPACE) @@ -21,8 +21,6 @@ namespace std{ #include <boost/serialization/throw_exception.hpp> #include <boost/archive/basic_text_iprimitive.hpp> -#include <boost/archive/codecvt_null.hpp> -#include <boost/archive/add_facet.hpp> #include <boost/archive/iterators/remove_whitespace.hpp> #include <boost/archive/iterators/istream_iterator.hpp> @@ -78,7 +76,7 @@ basic_text_iprimitive<IStream>::load_binary( iterators::remove_whitespace< iterators::istream_iterator<CharType> > - ,CharType + ,typename IStream::int_type > ,8 ,6 @@ -112,34 +110,27 @@ basic_text_iprimitive<IStream>::basic_text_iprimitive( IStream &is_, bool no_codecvt ) : -#ifndef BOOST_NO_STD_LOCALE is(is_), flags_saver(is_), precision_saver(is_), - locale_saver(* is_.rdbuf()) +#ifndef BOOST_NO_STD_LOCALE + codecvt_null_facet(1), + archive_locale(is.getloc(), & codecvt_null_facet), + locale_saver(is) { if(! no_codecvt){ - archive_locale.reset( - add_facet( - std::locale::classic(), - new boost::archive::codecvt_null<typename IStream::char_type> - ) - ); - //is.imbue(* archive_locale); + is_.sync(); + is_.imbue(archive_locale); } - is >> std::noboolalpha; + is_ >> std::noboolalpha; } #else - is(is_), - flags_saver(is_), - precision_saver(is_) {} #endif template<class IStream> BOOST_ARCHIVE_OR_WARCHIVE_DECL basic_text_iprimitive<IStream>::~basic_text_iprimitive(){ - is.sync(); } } // namespace archive diff --git a/boost/archive/impl/basic_text_oprimitive.ipp b/boost/archive/impl/basic_text_oprimitive.ipp index f2b0a10a60..6030fd44c5 100644 --- a/boost/archive/impl/basic_text_oprimitive.ipp +++ b/boost/archive/impl/basic_text_oprimitive.ipp @@ -10,10 +10,15 @@ #include <cstddef> // NULL #include <algorithm> // std::copy +#include <exception> // std::uncaught_exception +#include <boost/config.hpp> +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::size_t; +} // namespace std +#endif #include <boost/archive/basic_text_oprimitive.hpp> -#include <boost/archive/codecvt_null.hpp> -#include <boost/archive/add_facet.hpp> #include <boost/archive/iterators/base64_from_binary.hpp> #include <boost/archive/iterators/insert_linebreaks.hpp> @@ -79,33 +84,30 @@ basic_text_oprimitive<OStream>::basic_text_oprimitive( OStream & os_, bool no_codecvt ) : -#ifndef BOOST_NO_STD_LOCALE os(os_), flags_saver(os_), precision_saver(os_), - locale_saver(* os_.rdbuf()) +#ifndef BOOST_NO_STD_LOCALE + codecvt_null_facet(1), + archive_locale(os.getloc(), & codecvt_null_facet), + locale_saver(os) { if(! no_codecvt){ - archive_locale.reset( - add_facet( - std::locale::classic(), - new boost::archive::codecvt_null<typename OStream::char_type> - ) - ); - //os.imbue(* archive_locale); + os_.flush(); + os_.imbue(archive_locale); } - os << std::noboolalpha; + os_ << std::noboolalpha; } #else - os(os_), - flags_saver(os_), - precision_saver(os_) {} #endif + template<class OStream> BOOST_ARCHIVE_OR_WARCHIVE_DECL basic_text_oprimitive<OStream>::~basic_text_oprimitive(){ + if(std::uncaught_exception()) + return; os << std::endl; } diff --git a/boost/archive/impl/basic_xml_grammar.hpp b/boost/archive/impl/basic_xml_grammar.hpp index 70a6013abc..6d4e4683f6 100644 --- a/boost/archive/impl/basic_xml_grammar.hpp +++ b/boost/archive/impl/basic_xml_grammar.hpp @@ -163,7 +163,7 @@ public: bool parse_end_tag(IStream & is) const; bool parse_string(IStream & is, StringType & s) /*const*/; void init(IStream & is); - void windup(IStream & is); + bool windup(IStream & is); basic_xml_grammar(); }; diff --git a/boost/archive/impl/basic_xml_iarchive.ipp b/boost/archive/impl/basic_xml_iarchive.ipp index 9e670120f0..625458b9eb 100644 --- a/boost/archive/impl/basic_xml_iarchive.ipp +++ b/boost/archive/impl/basic_xml_iarchive.ipp @@ -108,7 +108,8 @@ basic_xml_iarchive<Archive>::basic_xml_iarchive(unsigned int flags) : {} template<class Archive> BOOST_ARCHIVE_OR_WARCHIVE_DECL -basic_xml_iarchive<Archive>::~basic_xml_iarchive(){} +basic_xml_iarchive<Archive>::~basic_xml_iarchive(){ +} } // namespace archive } // namespace boost diff --git a/boost/archive/impl/basic_xml_oarchive.ipp b/boost/archive/impl/basic_xml_oarchive.ipp index 5db1e13096..3184413f38 100644 --- a/boost/archive/impl/basic_xml_oarchive.ipp +++ b/boost/archive/impl/basic_xml_oarchive.ipp @@ -247,25 +247,25 @@ basic_xml_oarchive<Archive>::init(){ } template<class Archive> +BOOST_ARCHIVE_OR_WARCHIVE_DECL void +basic_xml_oarchive<Archive>::windup(){ + // xml_trailer + this->This()->put("</boost_serialization>\n"); +} + +template<class Archive> BOOST_ARCHIVE_OR_WARCHIVE_DECL basic_xml_oarchive<Archive>::basic_xml_oarchive(unsigned int flags) : detail::common_oarchive<Archive>(flags), depth(0), - indent_next(false), - pending_preamble(false) + pending_preamble(false), + indent_next(false) { } template<class Archive> BOOST_ARCHIVE_OR_WARCHIVE_DECL basic_xml_oarchive<Archive>::~basic_xml_oarchive(){ - if(0 == (this->get_flags() & no_header)){ - BOOST_TRY{ - this->This()->put("</boost_serialization>\n"); - } - BOOST_CATCH(...){} - BOOST_CATCH_END - } } } // namespace archive diff --git a/boost/archive/impl/text_oarchive_impl.ipp b/boost/archive/impl/text_oarchive_impl.ipp index 4ff488f4cb..37d8664a98 100644 --- a/boost/archive/impl/text_oarchive_impl.ipp +++ b/boost/archive/impl/text_oarchive_impl.ipp @@ -10,7 +10,6 @@ #include <string> #include <boost/config.hpp> -#include <locale> #include <cstddef> // size_t #include <boost/config.hpp> @@ -27,7 +26,6 @@ namespace std{ using ::wcslen; } #endif #endif -#include <boost/archive/add_facet.hpp> #include <boost/archive/text_oarchive.hpp> namespace boost { diff --git a/boost/archive/impl/xml_iarchive_impl.ipp b/boost/archive/impl/xml_iarchive_impl.ipp index bf94774987..efc32e0163 100644 --- a/boost/archive/impl/xml_iarchive_impl.ipp +++ b/boost/archive/impl/xml_iarchive_impl.ipp @@ -11,6 +11,8 @@ #include <boost/config.hpp> #include <cstring> // memcpy #include <cstddef> // NULL +#include <exception> + #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::memcpy; @@ -64,22 +66,22 @@ xml_iarchive_impl<Archive>::load(std::wstring &ws){ #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101)) if(NULL != ws.data()) #endif - ws.resize(0); - std::mbstate_t mbs; + ws.resize(0); + std::mbstate_t mbs = std::mbstate_t(); const char * start = s.data(); const char * end = start + s.size(); while(start < end){ wchar_t wc; - std::size_t result = std::mbrtowc(&wc, start, end - start, &mbs); - if(result == static_cast<std::size_t>(-1)) + std::size_t count = std::mbrtowc(&wc, start, end - start, &mbs); + if(count == static_cast<std::size_t>(-1)) boost::serialization::throw_exception( iterators::dataflow_exception( iterators::dataflow_exception::invalid_conversion ) ); - if(result == static_cast<std::size_t>(-2)) + if(count == static_cast<std::size_t>(-2)) continue; - start += result; + start += count; ws += wc; } } @@ -98,7 +100,7 @@ xml_iarchive_impl<Archive>::load(wchar_t * ws){ ) ); - std::mbstate_t mbs; + std::mbstate_t mbs = std::mbstate_t(); const char * start = s.data(); const char * end = start + s.size(); while(start < end){ @@ -187,12 +189,10 @@ xml_iarchive_impl<Archive>::xml_iarchive_impl( template<class Archive> BOOST_ARCHIVE_DECL xml_iarchive_impl<Archive>::~xml_iarchive_impl(){ + if(std::uncaught_exception()) + return; if(0 == (this->get_flags() & no_header)){ - BOOST_TRY{ - gimpl->windup(is); - } - BOOST_CATCH(...){} - BOOST_CATCH_END + gimpl->windup(is); } } } // namespace archive diff --git a/boost/archive/impl/xml_oarchive_impl.ipp b/boost/archive/impl/xml_oarchive_impl.ipp index 9e714f3ca6..5ebd454e72 100644 --- a/boost/archive/impl/xml_oarchive_impl.ipp +++ b/boost/archive/impl/xml_oarchive_impl.ipp @@ -10,6 +10,7 @@ #include <iomanip> #include <algorithm> // std::copy #include <string> +#include <exception> #include <cstring> // strlen #include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings @@ -113,5 +114,29 @@ xml_oarchive_impl<Archive>::xml_oarchive_impl( this->init(); } +template<class Archive> +BOOST_ARCHIVE_DECL void +xml_oarchive_impl<Archive>::save_binary(const void *address, std::size_t count){ + this->end_preamble(); + #if ! defined(__MWERKS__) + this->basic_text_oprimitive<std::ostream>::save_binary( + #else + this->basic_text_oprimitive::save_binary( + #endif + address, + count + ); + this->indent_next = true; +} + +template<class Archive> +BOOST_ARCHIVE_DECL +xml_oarchive_impl<Archive>::~xml_oarchive_impl(){ + if(std::uncaught_exception()) + return; + if(0 == (this->get_flags() & no_header)) + this->windup(); +} + } // namespace archive } // namespace boost diff --git a/boost/archive/impl/xml_wiarchive_impl.ipp b/boost/archive/impl/xml_wiarchive_impl.ipp index a837347edb..ee66c1263e 100644 --- a/boost/archive/impl/xml_wiarchive_impl.ipp +++ b/boost/archive/impl/xml_wiarchive_impl.ipp @@ -20,7 +20,7 @@ namespace std{ #include <boost/assert.hpp> #include <algorithm> // std::copy - +#include <exception> // uncaught exception #include <boost/detail/workaround.hpp> // Dinkumware and RogueWave #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) #include <boost/archive/dinkumware.hpp> @@ -33,11 +33,11 @@ namespace std{ #include <boost/archive/basic_xml_archive.hpp> #include <boost/archive/xml_wiarchive.hpp> -#include <boost/archive/add_facet.hpp> - #include <boost/archive/xml_archive_exception.hpp> #include <boost/archive/iterators/mb_from_wchar.hpp> +#include <boost/archive/detail/utf8_codecvt_facet.hpp> + #include "basic_xml_grammar.hpp" namespace boost { @@ -161,15 +161,13 @@ xml_wiarchive_impl<Archive>::xml_wiarchive_impl( gimpl(new xml_wgrammar()) { if(0 == (flags & no_codecvt)){ - // note usage of argument "1" so that the locale isn't - // automatically delete the facet - archive_locale.reset( - add_facet( - is_.getloc(), - new boost::archive::detail::utf8_codecvt_facet - ) + std::locale l = std::locale( + is_.getloc(), + new boost::archive::detail::utf8_codecvt_facet ); - //is.imbue(* archive_locale); + // libstdc++ crashes without this + is_.sync(); + is_.imbue(l); } if(0 == (flags & no_header)) init(); @@ -178,12 +176,10 @@ xml_wiarchive_impl<Archive>::xml_wiarchive_impl( template<class Archive> BOOST_WARCHIVE_DECL xml_wiarchive_impl<Archive>::~xml_wiarchive_impl(){ + if(std::uncaught_exception()) + return; if(0 == (this->get_flags() & no_header)){ - BOOST_TRY{ - gimpl->windup(is); - } - BOOST_CATCH(...){} - BOOST_CATCH_END + gimpl->windup(is); } } diff --git a/boost/archive/impl/xml_woarchive_impl.ipp b/boost/archive/impl/xml_woarchive_impl.ipp index d5586d51ae..58f92c9d92 100644 --- a/boost/archive/impl/xml_woarchive_impl.ipp +++ b/boost/archive/impl/xml_woarchive_impl.ipp @@ -13,6 +13,7 @@ #include <string> #include <algorithm> // std::copy #include <locale> +#include <exception> #include <cstring> // strlen #include <cstdlib> // mbtowc @@ -30,6 +31,8 @@ namespace std{ #endif #include <boost/archive/xml_woarchive.hpp> +#include <boost/archive/detail/utf8_codecvt_facet.hpp> + #include <boost/serialization/throw_exception.hpp> #include <boost/archive/iterators/xml_escape.hpp> @@ -37,8 +40,6 @@ namespace std{ #include <boost/archive/iterators/ostream_iterator.hpp> #include <boost/archive/iterators/dataflow_exception.hpp> -#include <boost/archive/add_facet.hpp> - namespace boost { namespace archive { @@ -122,19 +123,13 @@ xml_woarchive_impl<Archive>::xml_woarchive_impl( ), basic_xml_oarchive<Archive>(flags) { - // Standard behavior is that imbue can be called - // a) before output is invoked or - // b) after flush has been called. This prevents one-to-many - // transforms (such as one to many transforms from getting - // mixed up. if(0 == (flags & no_codecvt)){ - archive_locale.reset( - add_facet( - os_.getloc(), - new boost::archive::detail::utf8_codecvt_facet - ) + std::locale l = std::locale( + os_.getloc(), + new boost::archive::detail::utf8_codecvt_facet ); - //os.imbue(* archive_locale); + os_.flush(); + os_.imbue(l); } if(0 == (flags & no_header)) this->init(); @@ -143,6 +138,29 @@ xml_woarchive_impl<Archive>::xml_woarchive_impl( template<class Archive> BOOST_WARCHIVE_DECL xml_woarchive_impl<Archive>::~xml_woarchive_impl(){ + if(std::uncaught_exception()) + return; + if(0 == (this->get_flags() & no_header)){ + save(L"</boost_serialization>\n"); + } +} + +template<class Archive> +BOOST_WARCHIVE_DECL void +xml_woarchive_impl<Archive>::save_binary( + const void *address, + std::size_t count +){ + this->end_preamble(); + #if ! defined(__MWERKS__) + this->basic_text_oprimitive<std::wostream>::save_binary( + #else + this->basic_text_oprimitive::save_binary( + #endif + address, + count + ); + this->indent_next = true; } } // namespace archive diff --git a/boost/archive/iterators/dataflow.hpp b/boost/archive/iterators/dataflow.hpp index 6f8001d3ce..07733d5fd6 100644 --- a/boost/archive/iterators/dataflow.hpp +++ b/boost/archive/iterators/dataflow.hpp @@ -20,7 +20,6 @@ #include <boost/mpl/eval_if.hpp> #include <boost/mpl/if.hpp> -#include <boost/mpl/bool.hpp> #include <boost/mpl/apply.hpp> #include <boost/mpl/plus.hpp> #include <boost/mpl/int.hpp> diff --git a/boost/archive/iterators/istream_iterator.hpp b/boost/archive/iterators/istream_iterator.hpp index 41aa0be37b..9a1d555c10 100644 --- a/boost/archive/iterators/istream_iterator.hpp +++ b/boost/archive/iterators/istream_iterator.hpp @@ -54,21 +54,6 @@ class istream_iterator : return m_istream == rhs.m_istream; } -/* - //Access the value referred to - Elem dereference() const { - return m_current_value; - } - - void increment(){ - if(NULL != m_istream){ - m_current_value = static_cast<Elem>(m_istream->get()); - if(! m_istream->good()){ - const_cast<this_t *>(this)->m_istream = NULL; - } - } - } -*/ //Access the value referred to Elem dereference() const { return m_istream->peek(); diff --git a/boost/archive/iterators/mb_from_wchar.hpp b/boost/archive/iterators/mb_from_wchar.hpp index d76eb3e2d2..d5110de28a 100644 --- a/boost/archive/iterators/mb_from_wchar.hpp +++ b/boost/archive/iterators/mb_from_wchar.hpp @@ -18,17 +18,15 @@ #include <boost/assert.hpp> #include <cstddef> // size_t -#include <cwchar> // for mbstate_t and wcrtomb() +#include <cwchar> // mbstate_t #include <boost/config.hpp> #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ - using ::size_t; using ::mbstate_t; - using ::wcrtomb; } // namespace std #endif - +#include <boost/archive/detail/utf8_codecvt_facet.hpp> #include <boost/iterator/iterator_adaptor.hpp> namespace boost { @@ -67,10 +65,10 @@ class mb_from_wchar } return m_buffer[m_bnext]; } + char dereference() const { return (const_cast<this_t *>(this))->dereference_impl(); } - // test for iterator equality bool equal(const mb_from_wchar<Base> & rhs) const { // once the value is filled, the base_reference has been incremented @@ -83,14 +81,17 @@ class mb_from_wchar } void fill(){ - std::mbstate_t mbs; - std::wcrtomb(0, 0, &mbs); wchar_t value = * this->base_reference(); - m_bend = std::wcrtomb(m_buffer, value, &mbs); - BOOST_ASSERT(-1 != m_bend); - BOOST_ASSERT((std::size_t)m_bend <= sizeof(m_buffer)); - BOOST_ASSERT(m_bend > 0); + const wchar_t *wend; + char *bend; + std::codecvt_base::result r = m_codecvt_facet.out( + m_mbs, + & value, & value + 1, wend, + m_buffer, m_buffer + sizeof(m_buffer), bend + ); + BOOST_ASSERT(std::codecvt_base::ok == r); m_bnext = 0; + m_bend = bend - m_buffer; } void increment(){ @@ -102,10 +103,12 @@ class mb_from_wchar m_full = false; } + boost::archive::detail::utf8_codecvt_facet m_codecvt_facet; + std::mbstate_t m_mbs; // buffer to handle pending characters - int m_bend; - int m_bnext; - char m_buffer[9]; + char m_buffer[9 /* MB_CUR_MAX */]; + std::size_t m_bend; + std::size_t m_bnext; bool m_full; public: @@ -113,6 +116,7 @@ public: template<class T> mb_from_wchar(T start) : super_t(Base(static_cast< T >(start))), + m_mbs(std::mbstate_t()), m_bend(0), m_bnext(0), m_full(false) diff --git a/boost/archive/iterators/wchar_from_mb.hpp b/boost/archive/iterators/wchar_from_mb.hpp index 998a4686b2..52a44bdc79 100644 --- a/boost/archive/iterators/wchar_from_mb.hpp +++ b/boost/archive/iterators/wchar_from_mb.hpp @@ -19,20 +19,22 @@ #include <boost/assert.hpp> #include <cctype> #include <cstddef> // size_t -#include <cwchar> // mbstate_t and mbrtowc +#include <cwchar> // mbstate_t +#include <algorithm> // copy #include <boost/config.hpp> #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::mbstate_t; - using ::mbrtowc; } // namespace std #endif - -#include <boost/serialization/throw_exception.hpp> - +#include <boost/array.hpp> #include <boost/iterator/iterator_adaptor.hpp> +#include <boost/archive/detail/utf8_codecvt_facet.hpp> #include <boost/archive/iterators/dataflow_exception.hpp> +#include <boost/serialization/throw_exception.hpp> + +#include <iostream> namespace boost { namespace archive { @@ -62,57 +64,125 @@ class wchar_from_mb typedef wchar_from_mb<Base> this_t; - wchar_t drain(); + void drain(); - wchar_t dereference_impl() { - if(! m_full){ - m_current_value = drain(); - m_full = true; + wchar_t dereference() const { + if(m_output.m_next == m_output.m_next_available) + return static_cast<wchar_t>(0); + return * m_output.m_next; + } + + void increment(){ + if(m_output.m_next == m_output.m_next_available) + return; + if(++m_output.m_next == m_output.m_next_available){ + if(m_input.m_done) + return; + drain(); } - return m_current_value; } - wchar_t dereference() const { - return const_cast<this_t *>(this)->dereference_impl(); + bool equal(this_t const & rhs) const { + return dereference() == rhs.dereference(); } - void increment(){ - dereference_impl(); - m_full = false; - ++(this->base_reference()); + boost::archive::detail::utf8_codecvt_facet m_codecvt_facet; + std::mbstate_t m_mbs; + + template<typename T> + struct sliding_buffer { + boost::array<T, 32> m_buffer; + typename boost::array<T, 32>::const_iterator m_next_available; + typename boost::array<T, 32>::iterator m_next; + bool m_done; + // default ctor + sliding_buffer() : + m_next_available(m_buffer.begin()), + m_next(m_buffer.begin()), + m_done(false) + {} + // copy ctor + sliding_buffer(const sliding_buffer & rhs) : + m_next_available( + std::copy( + rhs.m_buffer.begin(), + rhs.m_next_available, + m_buffer.begin() + ) + ), + m_next( + m_buffer.begin() + (rhs.m_next - rhs.m_buffer.begin()) + ), + m_done(rhs.m_done) + {} }; - wchar_t m_current_value; - bool m_full; + sliding_buffer<typename iterator_value<Base>::type> m_input; + sliding_buffer<typename iterator_value<this_t>::type> m_output; public: // make composible buy using templated constructor template<class T> wchar_from_mb(T start) : super_t(Base(static_cast< T >(start))), - m_full(false) - {} - // intel 7.1 doesn't like default copy constructor - wchar_from_mb(const wchar_from_mb & rhs) : + m_mbs(std::mbstate_t()) + { + BOOST_ASSERT(std::mbsinit(&m_mbs)); + drain(); + } + // default constructor used as an end iterator + wchar_from_mb(){} + + // copy ctor + wchar_from_mb(const wchar_from_mb & rhs) : super_t(rhs.base_reference()), - m_full(rhs.m_full) + m_mbs(rhs.m_mbs), + m_input(rhs.m_input), + m_output(rhs.m_output) {} }; template<class Base> -wchar_t wchar_from_mb<Base>::drain(){ - std::mbstate_t mbs; - wchar_t retval; - std::size_t result; - do { - char val = *this->base_reference(); - result = std::mbrtowc(&retval, &val, 1, &mbs); - if(result == static_cast<std::size_t>(-1)) - boost::serialization::throw_exception(iterators::dataflow_exception( - iterators::dataflow_exception::invalid_conversion - )); - } while (result == static_cast<std::size_t>(-2)); - return retval; +void wchar_from_mb<Base>::drain(){ + BOOST_ASSERT(! m_input.m_done); + for(;;){ + typename boost::iterators::iterator_reference<Base>::type c = *(this->base_reference()); + // a null character in a multibyte stream is takes as end of string + if(0 == c){ + m_input.m_done = true; + break; + } + ++(this->base_reference()); + * const_cast<typename iterator_value<Base>::type *>( + (m_input.m_next_available++) + ) = c; + // if input buffer is full - we're done for now + if(m_input.m_buffer.end() == m_input.m_next_available) + break; + } + const typename boost::iterators::iterator_value<Base>::type * input_new_start; + typename iterator_value<this_t>::type * next_available; + + std::codecvt_base::result r = m_codecvt_facet.in( + m_mbs, + m_input.m_buffer.begin(), + m_input.m_next_available, + input_new_start, + m_output.m_buffer.begin(), + m_output.m_buffer.end(), + next_available + ); + BOOST_ASSERT(std::codecvt_base::ok == r); + m_output.m_next_available = next_available; + m_output.m_next = m_output.m_buffer.begin(); + + // we're done with some of the input so shift left. + m_input.m_next_available = std::copy( + input_new_start, + m_input.m_next_available, + m_input.m_buffer.begin() + ); + m_input.m_next = m_input.m_buffer.begin(); } } // namespace iterators diff --git a/boost/archive/text_iarchive.hpp b/boost/archive/text_iarchive.hpp index e40db8371d..d9d60adf0b 100644 --- a/boost/archive/text_iarchive.hpp +++ b/boost/archive/text_iarchive.hpp @@ -48,15 +48,8 @@ class BOOST_SYMBOL_VISIBLE text_iarchive_impl : public: #else protected: - #if BOOST_WORKAROUND(BOOST_MSVC, < 1500) - // for some inexplicable reason insertion of "class" generates compile erro - // on msvc 7.1 - friend detail::interface_iarchive<Archive>; - friend load_access; - #else - friend class detail::interface_iarchive<Archive>; - friend class load_access; - #endif + friend class detail::interface_iarchive<Archive>; + friend class load_access; #endif template<class T> void load(T & t){ diff --git a/boost/archive/text_oarchive.hpp b/boost/archive/text_oarchive.hpp index 7eaea17232..9ba0dafffb 100644 --- a/boost/archive/text_oarchive.hpp +++ b/boost/archive/text_oarchive.hpp @@ -55,17 +55,9 @@ class BOOST_SYMBOL_VISIBLE text_oarchive_impl : public: #else protected: - #if BOOST_WORKAROUND(BOOST_MSVC, < 1500) - // for some inexplicable reason insertion of "class" generates compile erro - // on msvc 7.1 - friend detail::interface_oarchive<Archive>; - friend basic_text_oarchive<Archive>; - friend save_access; - #else - friend class detail::interface_oarchive<Archive>; - friend class basic_text_oarchive<Archive>; - friend class save_access; - #endif + friend class detail::interface_oarchive<Archive>; + friend class basic_text_oarchive<Archive>; + friend class save_access; #endif template<class T> void save(const T & t){ diff --git a/boost/archive/xml_iarchive.hpp b/boost/archive/xml_iarchive.hpp index 055ba0f426..abd2f9fc4e 100644 --- a/boost/archive/xml_iarchive.hpp +++ b/boost/archive/xml_iarchive.hpp @@ -52,17 +52,9 @@ class BOOST_SYMBOL_VISIBLE xml_iarchive_impl : public: #else protected: - #if BOOST_WORKAROUND(BOOST_MSVC, < 1500) - // for some inexplicable reason insertion of "class" generates compile erro - // on msvc 7.1 - friend detail::interface_iarchive<Archive>; - friend basic_xml_iarchive<Archive>; - friend load_access; - #else - friend class detail::interface_iarchive<Archive>; - friend class basic_xml_iarchive<Archive>; - friend class load_access; - #endif + friend class detail::interface_iarchive<Archive>; + friend class basic_xml_iarchive<Archive>; + friend class load_access; #endif // use boost:scoped_ptr to implement automatic deletion; boost::scoped_ptr<xml_grammar> gimpl; diff --git a/boost/archive/xml_oarchive.hpp b/boost/archive/xml_oarchive.hpp index c5e6da9271..eea1268037 100644 --- a/boost/archive/xml_oarchive.hpp +++ b/boost/archive/xml_oarchive.hpp @@ -55,21 +55,10 @@ class BOOST_SYMBOL_VISIBLE xml_oarchive_impl : public: #else protected: - #if BOOST_WORKAROUND(BOOST_MSVC, < 1500) - // for some inexplicable reason insertion of "class" generates compile erro - // on msvc 7.1 - friend detail::interface_oarchive<Archive>; - friend basic_xml_oarchive<Archive>; - friend save_access; - #else - friend class detail::interface_oarchive<Archive>; - friend class basic_xml_oarchive<Archive>; - friend class save_access; - #endif + friend class detail::interface_oarchive<Archive>; + friend class basic_xml_oarchive<Archive>; + friend class save_access; #endif - //void end_preamble(){ - // basic_xml_oarchive<Archive>::end_preamble(); - //} template<class T> void save(const T & t){ basic_text_oprimitive<std::ostream>::save(t); @@ -96,22 +85,29 @@ protected: #endif BOOST_ARCHIVE_DECL xml_oarchive_impl(std::ostream & os, unsigned int flags); - ~xml_oarchive_impl(){} + BOOST_ARCHIVE_DECL + ~xml_oarchive_impl(); public: - void save_binary(const void *address, std::size_t count){ - this->end_preamble(); - #if ! defined(__MWERKS__) - this->basic_text_oprimitive<std::ostream>::save_binary( - #else - this->basic_text_oprimitive::save_binary( - #endif - address, - count - ); - this->indent_next = true; - } + BOOST_ARCHIVE_DECL + void save_binary(const void *address, std::size_t count); }; +} // namespace archive +} // namespace boost + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable : 4511 4512) +#endif + +namespace boost { +namespace archive { + // we use the following because we can't use // typedef xml_oarchive_impl<xml_oarchive_impl<...> > xml_oarchive; @@ -138,6 +134,4 @@ BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::xml_oarchive) #pragma warning(pop) #endif -#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas - #endif // BOOST_ARCHIVE_XML_OARCHIVE_HPP diff --git a/boost/archive/xml_wiarchive.hpp b/boost/archive/xml_wiarchive.hpp index dbc2d721a4..ac24289ac1 100644 --- a/boost/archive/xml_wiarchive.hpp +++ b/boost/archive/xml_wiarchive.hpp @@ -29,15 +29,7 @@ #include <boost/archive/basic_xml_iarchive.hpp> #include <boost/archive/detail/register_archive.hpp> #include <boost/serialization/item_version_type.hpp> - -#ifdef BOOST_NO_CXX11_HDR_CODECVT - #include <boost/archive/detail/utf8_codecvt_facet.hpp> -#else - #include <codecvt> - namespace boost { namespace archive { namespace detail { - typedef std::codecvt_utf8<wchar_t> utf8_codecvt_facet; - } } } -#endif +// #include <boost/archive/detail/utf8_codecvt_facet.hpp> #include <boost/archive/detail/abi_prefix.hpp> // must be the last header @@ -66,17 +58,9 @@ class BOOST_SYMBOL_VISIBLE xml_wiarchive_impl : public: #else protected: - #if BOOST_WORKAROUND(BOOST_MSVC, < 1500) - // for some inexplicable reason insertion of "class" generates compile erro - // on msvc 7.1 - friend detail::interface_iarchive<Archive>; - friend basic_xml_iarchive<Archive>; - friend load_access; - #else - friend class detail::interface_iarchive<Archive>; - friend class basic_xml_iarchive<Archive>; - friend class load_access; - #endif + friend class detail::interface_iarchive<Archive>; + friend class basic_xml_iarchive<Archive>; + friend class load_access; #endif boost::scoped_ptr<xml_wgrammar> gimpl; std::wistream & get_is(){ diff --git a/boost/archive/xml_woarchive.hpp b/boost/archive/xml_woarchive.hpp index 62700162d7..cb7ce68cb6 100644 --- a/boost/archive/xml_woarchive.hpp +++ b/boost/archive/xml_woarchive.hpp @@ -20,7 +20,6 @@ #ifdef BOOST_NO_STD_WSTREAMBUF #error "wide char i/o not supported on this platform" #else - #include <cstddef> // size_t #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ @@ -30,21 +29,13 @@ namespace std{ #include <ostream> -#include <boost/smart_ptr/scoped_ptr.hpp> +//#include <boost/smart_ptr/scoped_ptr.hpp> #include <boost/archive/detail/auto_link_warchive.hpp> #include <boost/archive/basic_text_oprimitive.hpp> #include <boost/archive/basic_xml_oarchive.hpp> #include <boost/archive/detail/register_archive.hpp> #include <boost/serialization/item_version_type.hpp> - -#ifdef BOOST_NO_CXX11_HDR_CODECVT - #include <boost/archive/detail/utf8_codecvt_facet.hpp> -#else - #include <codecvt> - namespace boost { namespace archive { namespace detail { - typedef std::codecvt_utf8<wchar_t> utf8_codecvt_facet; - } } } -#endif +//#include <boost/archive/detail/utf8_codecvt_facet.hpp> #include <boost/archive/detail/abi_prefix.hpp> // must be the last header @@ -69,27 +60,19 @@ class BOOST_SYMBOL_VISIBLE xml_woarchive_impl : public: #else protected: - #if BOOST_WORKAROUND(BOOST_MSVC, < 1500) - // for some inexplicable reason insertion of "class" generates compile erro - // on msvc 7.1 - friend detail::interface_oarchive<Archive>; - friend basic_xml_oarchive<Archive>; - friend save_access; - #else - friend class detail::interface_oarchive<Archive>; - friend class basic_xml_oarchive<Archive>; - friend class save_access; - #endif + friend class detail::interface_oarchive<Archive>; + friend class basic_xml_oarchive<Archive>; + friend class save_access; #endif //void end_preamble(){ // basic_xml_oarchive<Archive>::end_preamble(); //} template<class T> - void + void save(const T & t){ basic_text_oprimitive<std::wostream>::save(t); } - void + void save(const version_type & t){ save(static_cast<const unsigned int>(t)); } @@ -111,22 +94,12 @@ protected: #endif BOOST_WARCHIVE_DECL xml_woarchive_impl(std::wostream & os, unsigned int flags); - BOOST_WARCHIVE_DECL + BOOST_WARCHIVE_DECL ~xml_woarchive_impl(); public: - void - save_binary(const void *address, std::size_t count){ - this->end_preamble(); - #if ! defined(__MWERKS__) - this->basic_text_oprimitive<std::wostream>::save_binary( - #else - this->basic_text_oprimitive::save_binary( - #endif - address, - count - ); - this->indent_next = true; - } + BOOST_WARCHIVE_DECL void + save_binary(const void *address, std::size_t count); + }; // we use the following because we can't use @@ -135,7 +108,7 @@ public: // do not derive from this class. If you want to extend this functionality // via inhertance, derived from xml_woarchive_impl instead. This will // preserve correct static polymorphism. -class BOOST_SYMBOL_VISIBLE xml_woarchive : +class BOOST_SYMBOL_VISIBLE xml_woarchive : public xml_woarchive_impl<xml_woarchive> { public: |