annotate DEPENDENCIES/generic/include/boost/archive/impl/basic_binary_oprimitive.ipp @ 46:d572322e2efe

Fix to .cat file check (was susceptible to DOS line-endings) and subrepo update
author Chris Cannam
date Thu, 07 Aug 2014 14:39:38 +0100
parents 2665513ce2d3
children c530137014c0
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@16 34
Chris@16 35 namespace boost {
Chris@16 36 namespace archive {
Chris@16 37
Chris@16 38 //////////////////////////////////////////////////////////////////////
Chris@16 39 // implementation of basic_binary_oprimitive
Chris@16 40
Chris@16 41 template<class Archive, class Elem, class Tr>
Chris@16 42 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 43 basic_binary_oprimitive<Archive, Elem, Tr>::init()
Chris@16 44 {
Chris@16 45 // record native sizes of fundamental types
Chris@16 46 // this is to permit detection of attempts to pass
Chris@16 47 // native binary archives accross incompatible machines.
Chris@16 48 // This is not foolproof but its better than nothing.
Chris@16 49 this->This()->save(static_cast<unsigned char>(sizeof(int)));
Chris@16 50 this->This()->save(static_cast<unsigned char>(sizeof(long)));
Chris@16 51 this->This()->save(static_cast<unsigned char>(sizeof(float)));
Chris@16 52 this->This()->save(static_cast<unsigned char>(sizeof(double)));
Chris@16 53 // for checking endianness
Chris@16 54 this->This()->save(int(1));
Chris@16 55 }
Chris@16 56
Chris@16 57 template<class Archive, class Elem, class Tr>
Chris@16 58 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 59 basic_binary_oprimitive<Archive, Elem, Tr>::save(const char * s)
Chris@16 60 {
Chris@16 61 std::size_t l = std::strlen(s);
Chris@16 62 this->This()->save(l);
Chris@16 63 save_binary(s, l);
Chris@16 64 }
Chris@16 65
Chris@16 66 template<class Archive, class Elem, class Tr>
Chris@16 67 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 68 basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::string &s)
Chris@16 69 {
Chris@16 70 std::size_t l = static_cast<std::size_t>(s.size());
Chris@16 71 this->This()->save(l);
Chris@16 72 save_binary(s.data(), l);
Chris@16 73 }
Chris@16 74
Chris@16 75 #ifndef BOOST_NO_CWCHAR
Chris@16 76 template<class Archive, class Elem, class Tr>
Chris@16 77 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 78 basic_binary_oprimitive<Archive, Elem, Tr>::save(const wchar_t * ws)
Chris@16 79 {
Chris@16 80 std::size_t l = std::wcslen(ws);
Chris@16 81 this->This()->save(l);
Chris@16 82 save_binary(ws, l * sizeof(wchar_t) / sizeof(char));
Chris@16 83 }
Chris@16 84 #endif
Chris@16 85
Chris@16 86 #ifndef BOOST_NO_STD_WSTRING
Chris@16 87 template<class Archive, class Elem, class Tr>
Chris@16 88 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 89 basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::wstring &ws)
Chris@16 90 {
Chris@16 91 std::size_t l = ws.size();
Chris@16 92 this->This()->save(l);
Chris@16 93 save_binary(ws.data(), l * sizeof(wchar_t) / sizeof(char));
Chris@16 94 }
Chris@16 95 #endif
Chris@16 96
Chris@16 97 template<class Archive, class Elem, class Tr>
Chris@16 98 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
Chris@16 99 basic_binary_oprimitive<Archive, Elem, Tr>::basic_binary_oprimitive(
Chris@16 100 std::basic_streambuf<Elem, Tr> & sb,
Chris@16 101 bool no_codecvt
Chris@16 102 ) :
Chris@16 103 #ifndef BOOST_NO_STD_LOCALE
Chris@16 104 m_sb(sb),
Chris@16 105 archive_locale(NULL),
Chris@16 106 locale_saver(m_sb)
Chris@16 107 {
Chris@16 108 if(! no_codecvt){
Chris@16 109 archive_locale.reset(
Chris@16 110 add_facet(
Chris@16 111 std::locale::classic(),
Chris@16 112 new codecvt_null<Elem>
Chris@16 113 )
Chris@16 114 );
Chris@16 115 m_sb.pubimbue(* archive_locale);
Chris@16 116 }
Chris@16 117 }
Chris@16 118 #else
Chris@16 119 m_sb(sb)
Chris@16 120 {}
Chris@16 121 #endif
Chris@16 122
Chris@16 123 // some libraries including stl and libcomo fail if the
Chris@16 124 // buffer isn't flushed before the code_cvt facet is changed.
Chris@16 125 // I think this is a bug. We explicity invoke sync to when
Chris@16 126 // we're done with the streambuf to work around this problem.
Chris@16 127 // Note that sync is a protected member of stream buff so we
Chris@16 128 // have to invoke it through a contrived derived class.
Chris@16 129 namespace detail {
Chris@16 130 // note: use "using" to get past msvc bug
Chris@16 131 using namespace std;
Chris@16 132 template<class Elem, class Tr>
Chris@16 133 class output_streambuf_access : public std::basic_streambuf<Elem, Tr> {
Chris@16 134 public:
Chris@16 135 virtual int sync(){
Chris@16 136 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
Chris@16 137 return this->basic_streambuf::sync();
Chris@16 138 #else
Chris@16 139 return this->basic_streambuf<Elem, Tr>::sync();
Chris@16 140 #endif
Chris@16 141 }
Chris@16 142 };
Chris@16 143 } // detail
Chris@16 144
Chris@16 145 // scoped_ptr requires that g be a complete type at time of
Chris@16 146 // destruction so define destructor here rather than in the header
Chris@16 147 template<class Archive, class Elem, class Tr>
Chris@16 148 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
Chris@16 149 basic_binary_oprimitive<Archive, Elem, Tr>::~basic_binary_oprimitive(){
Chris@16 150 // flush buffer
Chris@16 151 //destructor can't throw
Chris@16 152 try{
Chris@16 153 static_cast<detail::output_streambuf_access<Elem, Tr> &>(m_sb).sync();
Chris@16 154 }
Chris@16 155 catch(...){
Chris@16 156 }
Chris@16 157 }
Chris@16 158
Chris@16 159 } // namespace archive
Chris@16 160 } // namespace boost