annotate DEPENDENCIES/generic/include/boost/archive/impl/basic_binary_iarchive.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_iarchive.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 #include <string>
Chris@16 11 #include <boost/assert.hpp>
Chris@16 12 #include <algorithm>
Chris@16 13 #include <cstring>
Chris@16 14
Chris@101 15 #include <boost/config.hpp>
Chris@16 16 #if defined(BOOST_NO_STDC_NAMESPACE)
Chris@16 17 namespace std{
Chris@16 18 using ::memcpy;
Chris@16 19 using ::strlen;
Chris@16 20 using ::size_t;
Chris@16 21 }
Chris@16 22 #endif
Chris@16 23
Chris@16 24 #include <boost/detail/workaround.hpp>
Chris@16 25 #include <boost/detail/endian.hpp>
Chris@16 26
Chris@16 27 #include <boost/archive/basic_binary_iarchive.hpp>
Chris@16 28
Chris@16 29 namespace boost {
Chris@16 30 namespace archive {
Chris@16 31
Chris@16 32 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
Chris@16 33 // implementation of binary_binary_archive
Chris@16 34 template<class Archive>
Chris@16 35 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 36 basic_binary_iarchive<Archive>::load_override(class_name_type & t, int){
Chris@16 37 std::string cn;
Chris@16 38 cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE);
Chris@16 39 load_override(cn, 0);
Chris@16 40 if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1))
Chris@16 41 boost::serialization::throw_exception(
Chris@16 42 archive_exception(archive_exception::invalid_class_name)
Chris@16 43 );
Chris@16 44 std::memcpy(t, cn.data(), cn.size());
Chris@16 45 // borland tweak
Chris@16 46 t.t[cn.size()] = '\0';
Chris@16 47 }
Chris@16 48
Chris@16 49 template<class Archive>
Chris@16 50 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
Chris@16 51 basic_binary_iarchive<Archive>::init(){
Chris@16 52 // read signature in an archive version independent manner
Chris@16 53 std::string file_signature;
Chris@101 54
Chris@101 55 #if 0 // commented out since it interfers with derivation
Chris@101 56 BOOST_TRY {
Chris@16 57 std::size_t l;
Chris@16 58 this->This()->load(l);
Chris@16 59 if(l == std::strlen(BOOST_ARCHIVE_SIGNATURE())) {
Chris@16 60 // borland de-allocator fixup
Chris@16 61 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
Chris@16 62 if(NULL != file_signature.data())
Chris@16 63 #endif
Chris@16 64 file_signature.resize(l);
Chris@16 65 // note breaking a rule here - could be a problem on some platform
Chris@16 66 if(0 < l)
Chris@16 67 this->This()->load_binary(&(*file_signature.begin()), l);
Chris@16 68 }
Chris@16 69 }
Chris@101 70 BOOST_CATCH(archive_exception const &) { // catch stream_error archive exceptions
Chris@16 71 // will cause invalid_signature archive exception to be thrown below
Chris@16 72 file_signature = "";
Chris@16 73 }
Chris@101 74 BOOST_CATCH_END
Chris@101 75 #else
Chris@101 76 // https://svn.boost.org/trac/boost/ticket/7301
Chris@101 77 * this->This() >> file_signature;
Chris@101 78 #endif
Chris@101 79
Chris@16 80 if(file_signature != BOOST_ARCHIVE_SIGNATURE())
Chris@16 81 boost::serialization::throw_exception(
Chris@16 82 archive_exception(archive_exception::invalid_signature)
Chris@16 83 );
Chris@16 84
Chris@16 85 // make sure the version of the reading archive library can
Chris@16 86 // support the format of the archive being read
Chris@16 87 library_version_type input_library_version;
Chris@16 88 //* this->This() >> input_library_version;
Chris@16 89 {
Chris@16 90 int v = 0;
Chris@16 91 v = this->This()->m_sb.sbumpc();
Chris@16 92 #if defined(BOOST_LITTLE_ENDIAN)
Chris@16 93 if(v < 6){
Chris@16 94 ;
Chris@16 95 }
Chris@16 96 else
Chris@16 97 if(v < 7){
Chris@16 98 // version 6 - next byte should be zero
Chris@16 99 this->This()->m_sb.sbumpc();
Chris@16 100 }
Chris@16 101 else
Chris@16 102 if(v < 8){
Chris@16 103 int x1;
Chris@16 104 // version 7 = might be followed by zero or some other byte
Chris@16 105 x1 = this->This()->m_sb.sgetc();
Chris@16 106 // it's =a zero, push it back
Chris@16 107 if(0 == x1)
Chris@16 108 this->This()->m_sb.sbumpc();
Chris@16 109 }
Chris@16 110 else{
Chris@16 111 // version 8+ followed by a zero
Chris@16 112 this->This()->m_sb.sbumpc();
Chris@16 113 }
Chris@16 114 #elif defined(BOOST_BIG_ENDIAN)
Chris@16 115 if(v == 0)
Chris@16 116 v = this->This()->m_sb.sbumpc();
Chris@16 117 #endif
Chris@16 118 input_library_version = static_cast<library_version_type>(v);
Chris@16 119 }
Chris@16 120
Chris@16 121 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
Chris@16 122 this->set_library_version(input_library_version);
Chris@16 123 #else
Chris@101 124 detail::basic_iarchive::set_library_version(input_library_version);
Chris@16 125 #endif
Chris@16 126
Chris@16 127 if(BOOST_ARCHIVE_VERSION() < input_library_version)
Chris@16 128 boost::serialization::throw_exception(
Chris@16 129 archive_exception(archive_exception::unsupported_version)
Chris@16 130 );
Chris@16 131 }
Chris@16 132
Chris@16 133 } // namespace archive
Chris@16 134 } // namespace boost