Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:28

0001 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0002 // basic_binary_iarchive.ipp:
0003 
0004 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
0005 // Use, modification and distribution is subject to the Boost Software
0006 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 //  See http://www.boost.org for updates, documentation, and revision history.
0010 #include <string>
0011 #include <boost/assert.hpp>
0012 #include <algorithm>
0013 #include <cstring>
0014 
0015 #include <boost/config.hpp>
0016 #if defined(BOOST_NO_STDC_NAMESPACE)
0017 namespace std{ 
0018     using ::memcpy; 
0019     using ::strlen;
0020     using ::size_t;
0021 }
0022 #endif
0023 
0024 #include <boost/detail/workaround.hpp>
0025 #include <boost/predef/other/endian.h>
0026 
0027 #include <boost/archive/basic_binary_iarchive.hpp>
0028 
0029 namespace boost {
0030 namespace archive {
0031 
0032 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0033 // implementation of binary_binary_archive
0034 template<class Archive>
0035 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0036 basic_binary_iarchive<Archive>::load_override(class_name_type & t){
0037     std::string cn;
0038     cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE);
0039     load_override(cn);
0040     if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1))
0041         boost::serialization::throw_exception(
0042             archive_exception(archive_exception::invalid_class_name)
0043         );
0044     std::memcpy(t, cn.data(), cn.size());
0045     // borland tweak
0046     t.t[cn.size()] = '\0';
0047 }
0048 
0049 template<class Archive>
0050 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0051 basic_binary_iarchive<Archive>::init() {
0052     // read signature in an archive version independent manner
0053     std::string file_signature;
0054     
0055     #if 0 // commented out since it interfers with derivation
0056     BOOST_TRY {
0057         std::size_t l;
0058         this->This()->load(l);
0059         if(l == std::strlen(BOOST_ARCHIVE_SIGNATURE())) {
0060             // borland de-allocator fixup
0061             #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
0062             if(NULL != file_signature.data())
0063             #endif
0064                 file_signature.resize(l);
0065             // note breaking a rule here - could be a problem on some platform
0066             if(0 < l)
0067                 this->This()->load_binary(&(*file_signature.begin()), l);
0068         }
0069     }
0070     BOOST_CATCH(archive_exception const &) {  // catch stream_error archive exceptions
0071         // will cause invalid_signature archive exception to be thrown below
0072         file_signature = "";   
0073     }
0074     BOOST_CATCH_END
0075     #else
0076     // https://svn.boost.org/trac/boost/ticket/7301
0077     * this->This() >> file_signature;
0078     #endif
0079 
0080     if(file_signature != BOOST_ARCHIVE_SIGNATURE())
0081         boost::serialization::throw_exception(
0082             archive_exception(archive_exception::invalid_signature)
0083         );
0084 
0085     // make sure the version of the reading archive library can
0086     // support the format of the archive being read
0087     boost::serialization::library_version_type input_library_version;
0088     //* this->This() >> input_library_version;
0089     {
0090         int v = 0;
0091         v = this->This()->m_sb.sbumpc();
0092         #if BOOST_ENDIAN_LITTLE_BYTE
0093         if(v < 6){
0094             ;
0095         }
0096         else
0097         if(v < 7){
0098             // version 6 - next byte should be zero
0099             this->This()->m_sb.sbumpc();
0100         }
0101         else
0102         if(v < 8){
0103             int x1;
0104             // version 7 = might be followed by zero or some other byte
0105             x1 = this->This()->m_sb.sgetc();
0106             // it's =a zero, push it back
0107             if(0 == x1)
0108                 this->This()->m_sb.sbumpc();
0109         }
0110         else{
0111             // version 8+ followed by a zero
0112             this->This()->m_sb.sbumpc();
0113         }
0114         #elif BOOST_ENDIAN_BIG_BYTE
0115         if(v == 0)
0116             v = this->This()->m_sb.sbumpc();
0117         #endif
0118         input_library_version = static_cast<boost::serialization::library_version_type>(v);
0119     }
0120     
0121     #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
0122     this->set_library_version(input_library_version);
0123     #else
0124     detail::basic_iarchive::set_library_version(input_library_version);
0125     #endif
0126     
0127     if(BOOST_ARCHIVE_VERSION() < input_library_version)
0128         boost::serialization::throw_exception(
0129             archive_exception(archive_exception::unsupported_version)
0130         );
0131 }
0132 
0133 } // namespace archive
0134 } // namespace boost