Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // basic_binary_iarchive.ipp: Chris@16: Chris@16: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@101: #include Chris@16: #if defined(BOOST_NO_STDC_NAMESPACE) Chris@16: namespace std{ Chris@16: using ::memcpy; Chris@16: using ::strlen; Chris@16: using ::size_t; Chris@16: } Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace archive { Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // implementation of binary_binary_archive Chris@16: template Chris@16: BOOST_ARCHIVE_OR_WARCHIVE_DECL(void) Chris@16: basic_binary_iarchive::load_override(class_name_type & t, int){ Chris@16: std::string cn; Chris@16: cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE); Chris@16: load_override(cn, 0); Chris@16: if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1)) Chris@16: boost::serialization::throw_exception( Chris@16: archive_exception(archive_exception::invalid_class_name) Chris@16: ); Chris@16: std::memcpy(t, cn.data(), cn.size()); Chris@16: // borland tweak Chris@16: t.t[cn.size()] = '\0'; Chris@16: } Chris@16: Chris@16: template Chris@16: BOOST_ARCHIVE_OR_WARCHIVE_DECL(void) Chris@16: basic_binary_iarchive::init(){ Chris@16: // read signature in an archive version independent manner Chris@16: std::string file_signature; Chris@101: Chris@101: #if 0 // commented out since it interfers with derivation Chris@101: BOOST_TRY { Chris@16: std::size_t l; Chris@16: this->This()->load(l); Chris@16: if(l == std::strlen(BOOST_ARCHIVE_SIGNATURE())) { Chris@16: // borland de-allocator fixup Chris@16: #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101)) Chris@16: if(NULL != file_signature.data()) Chris@16: #endif Chris@16: file_signature.resize(l); Chris@16: // note breaking a rule here - could be a problem on some platform Chris@16: if(0 < l) Chris@16: this->This()->load_binary(&(*file_signature.begin()), l); Chris@16: } Chris@16: } Chris@101: BOOST_CATCH(archive_exception const &) { // catch stream_error archive exceptions Chris@16: // will cause invalid_signature archive exception to be thrown below Chris@16: file_signature = ""; Chris@16: } Chris@101: BOOST_CATCH_END Chris@101: #else Chris@101: // https://svn.boost.org/trac/boost/ticket/7301 Chris@101: * this->This() >> file_signature; Chris@101: #endif Chris@101: Chris@16: if(file_signature != BOOST_ARCHIVE_SIGNATURE()) Chris@16: boost::serialization::throw_exception( Chris@16: archive_exception(archive_exception::invalid_signature) Chris@16: ); Chris@16: Chris@16: // make sure the version of the reading archive library can Chris@16: // support the format of the archive being read Chris@16: library_version_type input_library_version; Chris@16: //* this->This() >> input_library_version; Chris@16: { Chris@16: int v = 0; Chris@16: v = this->This()->m_sb.sbumpc(); Chris@16: #if defined(BOOST_LITTLE_ENDIAN) Chris@16: if(v < 6){ Chris@16: ; Chris@16: } Chris@16: else Chris@16: if(v < 7){ Chris@16: // version 6 - next byte should be zero Chris@16: this->This()->m_sb.sbumpc(); Chris@16: } Chris@16: else Chris@16: if(v < 8){ Chris@16: int x1; Chris@16: // version 7 = might be followed by zero or some other byte Chris@16: x1 = this->This()->m_sb.sgetc(); Chris@16: // it's =a zero, push it back Chris@16: if(0 == x1) Chris@16: this->This()->m_sb.sbumpc(); Chris@16: } Chris@16: else{ Chris@16: // version 8+ followed by a zero Chris@16: this->This()->m_sb.sbumpc(); Chris@16: } Chris@16: #elif defined(BOOST_BIG_ENDIAN) Chris@16: if(v == 0) Chris@16: v = this->This()->m_sb.sbumpc(); Chris@16: #endif Chris@16: input_library_version = static_cast(v); Chris@16: } Chris@16: Chris@16: #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) Chris@16: this->set_library_version(input_library_version); Chris@16: #else Chris@101: detail::basic_iarchive::set_library_version(input_library_version); Chris@16: #endif Chris@16: Chris@16: if(BOOST_ARCHIVE_VERSION() < input_library_version) Chris@16: boost::serialization::throw_exception( Chris@16: archive_exception(archive_exception::unsupported_version) Chris@16: ); Chris@16: } Chris@16: Chris@16: } // namespace archive Chris@16: } // namespace boost