1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // basic_binary_iarchive.ipp:
4 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org for updates, documentation, and revision history.
11 #include <boost/assert.hpp>
15 #include <boost/config.hpp>
16 #if defined(BOOST_NO_STDC_NAMESPACE)
24 #include <boost/detail/workaround.hpp>
25 #include <boost/detail/endian.hpp>
27 #include <boost/archive/basic_binary_iarchive.hpp>
32 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
33 // implementation of binary_binary_archive
34 template<class Archive>
35 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
36 basic_binary_iarchive<Archive>::load_override(class_name_type & t){
38 cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE);
40 if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1))
41 boost::serialization::throw_exception(
42 archive_exception(archive_exception::invalid_class_name)
44 std::memcpy(t, cn.data(), cn.size());
46 t.t[cn.size()] = '\0';
49 template<class Archive>
50 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
51 basic_binary_iarchive<Archive>::init(void){
52 // read signature in an archive version independent manner
53 std::string file_signature;
55 #if 0 // commented out since it interfers with derivation
58 this->This()->load(l);
59 if(l == std::strlen(BOOST_ARCHIVE_SIGNATURE())) {
60 // borland de-allocator fixup
61 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
62 if(NULL != file_signature.data())
64 file_signature.resize(l);
65 // note breaking a rule here - could be a problem on some platform
67 this->This()->load_binary(&(*file_signature.begin()), l);
70 BOOST_CATCH(archive_exception const &) { // catch stream_error archive exceptions
71 // will cause invalid_signature archive exception to be thrown below
76 // https://svn.boost.org/trac/boost/ticket/7301
77 * this->This() >> file_signature;
80 if(file_signature != BOOST_ARCHIVE_SIGNATURE())
81 boost::serialization::throw_exception(
82 archive_exception(archive_exception::invalid_signature)
85 // make sure the version of the reading archive library can
86 // support the format of the archive being read
87 library_version_type input_library_version;
88 //* this->This() >> input_library_version;
91 v = this->This()->m_sb.sbumpc();
92 #if defined(BOOST_LITTLE_ENDIAN)
98 // version 6 - next byte should be zero
99 this->This()->m_sb.sbumpc();
104 // version 7 = might be followed by zero or some other byte
105 x1 = this->This()->m_sb.sgetc();
106 // it's =a zero, push it back
108 this->This()->m_sb.sbumpc();
111 // version 8+ followed by a zero
112 this->This()->m_sb.sbumpc();
114 #elif defined(BOOST_BIG_ENDIAN)
116 v = this->This()->m_sb.sbumpc();
118 input_library_version = static_cast<library_version_type>(v);
121 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
122 this->set_library_version(input_library_version);
124 detail::basic_iarchive::set_library_version(input_library_version);
127 if(BOOST_ARCHIVE_VERSION() < input_library_version)
128 boost::serialization::throw_exception(
129 archive_exception(archive_exception::unsupported_version)
133 } // namespace archive