1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // portable_binary_iarchive.cpp
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.
14 #include <boost/predef/other/endian.h>
15 #include <boost/serialization/throw_exception.hpp>
16 #include <boost/archive/archive_exception.hpp>
18 #include "portable_binary_iarchive.hpp"
21 portable_binary_iarchive::load_impl(boost::intmax_t & l
, char maxsize
){
24 this->primitive_base_t::load(size
);
30 bool negative
= (size
< 0);
35 boost::serialization::throw_exception(
36 portable_binary_iarchive_exception()
39 char * cptr
= reinterpret_cast<char *>(& l
);
40 #if BOOST_ENDIAN_BIG_BYTE
41 cptr
+= (sizeof(boost::intmax_t) - size
);
43 this->primitive_base_t::load_binary(cptr
, size
);
45 #if BOOST_ENDIAN_BIG_BYTE
46 if(m_flags
& endian_little
)
48 if(m_flags
& endian_big
)
50 reverse_bytes(size
, cptr
);
57 portable_binary_iarchive::load_override(
58 boost::archive::class_name_type
& t
61 cn
.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE
);
63 if(cn
.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE
- 1))
64 boost::serialization::throw_exception(
65 boost::archive::archive_exception(
66 boost::archive::archive_exception::invalid_class_name
)
68 std::memcpy(t
, cn
.data(), cn
.size());
70 t
.t
[cn
.size()] = '\0';
74 portable_binary_iarchive::init(unsigned int flags
){
75 if(0 == (flags
& boost::archive::no_header
)){
76 // read signature in an archive version independent manner
77 std::string file_signature
;
78 * this >> file_signature
;
79 if(file_signature
!= boost::archive::BOOST_ARCHIVE_SIGNATURE())
80 boost::serialization::throw_exception(
81 boost::archive::archive_exception(
82 boost::archive::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 boost::archive::library_version_type input_library_version
;
88 * this >> input_library_version
;
90 // extra little .t is to get around borland quirk
91 if(boost::archive::BOOST_ARCHIVE_VERSION() < input_library_version
)
92 boost::serialization::throw_exception(
93 boost::archive::archive_exception(
94 boost::archive::archive_exception::unsupported_version
98 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
99 this->set_library_version(input_library_version
);
101 //#if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
104 boost::archive::detail::basic_iarchive::set_library_version(
105 input_library_version
111 m_flags
= x
<< CHAR_BIT
;
114 #include <boost/archive/impl/archive_serializer_map.ipp>
115 #include <boost/archive/impl/basic_binary_iprimitive.ipp>
121 template class archive_serializer_map
<portable_binary_iarchive
>;
124 template class basic_binary_iprimitive
<
125 portable_binary_iarchive
,
126 std::istream::char_type
,
127 std::istream::traits_type
130 } // namespace archive