annotate DEPENDENCIES/generic/include/boost/archive/impl/basic_binary_oprimitive.ipp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
Chris@16 2 // basic_binary_oprimitive.ipp:
Chris@16 3
Chris@16 4 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
Chris@16 5 // Use, modification and distribution is subject to the Boost Software
Chris@16 6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8
Chris@16 9 // See http://www.boost.org for updates, documentation, and revision history.
Chris@16 10
Chris@16 11 #include <ostream>
Chris@16 12 #include <cstddef> // NULL
Chris@16 13 #include <cstring>
Chris@16 14
Chris@16 15 #include <boost/config.hpp>
Chris@16 16
Chris@16 17 #if defined(BOOST_NO_STDC_NAMESPACE) && ! defined(__LIBCOMO__)
Chris@16 18 namespace std{
Chris@16 19 using ::strlen;
Chris@16 20 } // namespace std
Chris@16 21 #endif
Chris@16 22
Chris@16 23 #ifndef BOOST_NO_CWCHAR
Chris@16 24 #include <cwchar>
Chris@16 25 #ifdef BOOST_NO_STDC_NAMESPACE
Chris@16 26 namespace std{ using ::wcslen; }
Chris@16 27 #endif
Chris@16 28 #endif
Chris@16 29
Chris@16 30 #include <boost/detail/workaround.hpp>
Chris@16 31
Chris@16 32 #include <boost/archive/add_facet.hpp>
Chris@16 33 #include <boost/archive/codecvt_null.hpp>
Chris@101 34 #include <boost/archive/basic_binary_oprimitive.hpp>
Chris@101 35 #include <boost/core/no_exceptions_support.hpp>
Chris@16 36
Chris@16 37 namespace boost {
Chris@16 38 namespace archive {
Chris@16 39
Chris@16 40 //////////////////////////////////////////////////////////////////////
Chris@16 41 // implementation of basic_binary_oprimitive
Chris@16 42
Chris@16 43 template<class Archive, class Elem, class Tr>
Chris@16 44 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 45 basic_binary_oprimitive<Archive, Elem, Tr>::init()
Chris@16 46 {
Chris@16 47 // record native sizes of fundamental types
Chris@16 48 // this is to permit detection of attempts to pass
Chris@16 49 // native binary archives accross incompatible machines.
Chris@16 50 // This is not foolproof but its better than nothing.
Chris@16 51 this->This()->save(static_cast<unsigned char>(sizeof(int)));
Chris@16 52 this->This()->save(static_cast<unsigned char>(sizeof(long)));
Chris@16 53 this->This()->save(static_cast<unsigned char>(sizeof(float)));
Chris@16 54 this->This()->save(static_cast<unsigned char>(sizeof(double)));
Chris@16 55 // for checking endianness
Chris@16 56 this->This()->save(int(1));
Chris@16 57 }
Chris@16 58
Chris@16 59 template<class Archive, class Elem, class Tr>
Chris@16 60 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 61 basic_binary_oprimitive<Archive, Elem, Tr>::save(const char * s)
Chris@16 62 {
Chris@16 63 std::size_t l = std::strlen(s);
Chris@16 64 this->This()->save(l);
Chris@16 65 save_binary(s, l);
Chris@16 66 }
Chris@16 67
Chris@16 68 template<class Archive, class Elem, class Tr>
Chris@16 69 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 70 basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::string &s)
Chris@16 71 {
Chris@16 72 std::size_t l = static_cast<std::size_t>(s.size());
Chris@16 73 this->This()->save(l);
Chris@16 74 save_binary(s.data(), l);
Chris@16 75 }
Chris@16 76
Chris@16 77 #ifndef BOOST_NO_CWCHAR
Chris@16 78 template<class Archive, class Elem, class Tr>
Chris@16 79 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 80 basic_binary_oprimitive<Archive, Elem, Tr>::save(const wchar_t * ws)
Chris@16 81 {
Chris@16 82 std::size_t l = std::wcslen(ws);
Chris@16 83 this->This()->save(l);
Chris@16 84 save_binary(ws, l * sizeof(wchar_t) / sizeof(char));
Chris@16 85 }
Chris@16 86 #endif
Chris@16 87
Chris@16 88 #ifndef BOOST_NO_STD_WSTRING
Chris@16 89 template<class Archive, class Elem, class Tr>
Chris@16 90 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 91 basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::wstring &ws)
Chris@16 92 {
Chris@16 93 std::size_t l = ws.size();
Chris@16 94 this->This()->save(l);
Chris@16 95 save_binary(ws.data(), l * sizeof(wchar_t) / sizeof(char));
Chris@16 96 }
Chris@16 97 #endif
Chris@16 98
Chris@16 99 template<class Archive, class Elem, class Tr>
Chris@16 100 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
Chris@16 101 basic_binary_oprimitive<Archive, Elem, Tr>::basic_binary_oprimitive(
Chris@16 102 std::basic_streambuf<Elem, Tr> & sb,
Chris@16 103 bool no_codecvt
Chris@16 104 ) :
Chris@16 105 #ifndef BOOST_NO_STD_LOCALE
Chris@16 106 m_sb(sb),
Chris@16 107 locale_saver(m_sb)
Chris@16 108 {
Chris@16 109 if(! no_codecvt){
Chris@16 110 archive_locale.reset(
Chris@16 111 add_facet(
Chris@101 112 std::locale::classic(),
Chris@16 113 new codecvt_null<Elem>
Chris@16 114 )
Chris@16 115 );
Chris@101 116 //m_sb.pubimbue(* archive_locale);
Chris@16 117 }
Chris@16 118 }
Chris@16 119 #else
Chris@16 120 m_sb(sb)
Chris@16 121 {}
Chris@16 122 #endif
Chris@16 123
Chris@16 124 // some libraries including stl and libcomo fail if the
Chris@16 125 // buffer isn't flushed before the code_cvt facet is changed.
Chris@16 126 // I think this is a bug. We explicity invoke sync to when
Chris@16 127 // we're done with the streambuf to work around this problem.
Chris@16 128 // Note that sync is a protected member of stream buff so we
Chris@16 129 // have to invoke it through a contrived derived class.
Chris@16 130 namespace detail {
Chris@16 131 // note: use "using" to get past msvc bug
Chris@16 132 using namespace std;
Chris@16 133 template<class Elem, class Tr>
Chris@16 134 class output_streambuf_access : public std::basic_streambuf<Elem, Tr> {
Chris@16 135 public:
Chris@16 136 virtual int sync(){
Chris@16 137 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
Chris@16 138 return this->basic_streambuf::sync();
Chris@16 139 #else
Chris@16 140 return this->basic_streambuf<Elem, Tr>::sync();
Chris@16 141 #endif
Chris@16 142 }
Chris@16 143 };
Chris@16 144 } // detail
Chris@16 145
Chris@16 146 // scoped_ptr requires that g be a complete type at time of
Chris@16 147 // destruction so define destructor here rather than in the header
Chris@16 148 template<class Archive, class Elem, class Tr>
Chris@16 149 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
Chris@16 150 basic_binary_oprimitive<Archive, Elem, Tr>::~basic_binary_oprimitive(){
Chris@16 151 // flush buffer
Chris@16 152 //destructor can't throw
Chris@101 153 BOOST_TRY{
Chris@16 154 static_cast<detail::output_streambuf_access<Elem, Tr> &>(m_sb).sync();
Chris@16 155 }
Chris@101 156 BOOST_CATCH(...){
Chris@16 157 }
Chris@101 158 BOOST_CATCH_END
Chris@16 159 }
Chris@16 160
Chris@16 161 } // namespace archive
Chris@16 162 } // namespace boost