• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // portable_binary_iarchive.cpp
3 
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)
8 
9 //  See http://www.boost.org for updates, documentation, and revision history.
10 
11 #include <istream>
12 #include <string>
13 
14 #include <boost/predef/other/endian.h>
15 #include <boost/serialization/throw_exception.hpp>
16 #include <boost/archive/archive_exception.hpp>
17 
18 #include "portable_binary_iarchive.hpp"
19 
20 void
load_impl(boost::intmax_t & l,char maxsize)21 portable_binary_iarchive::load_impl(boost::intmax_t & l, char maxsize){
22     char size;
23     l = 0;
24     this->primitive_base_t::load(size);
25 
26     if(0 == size){
27         return;
28     }
29 
30     bool negative = (size < 0);
31     if(negative)
32         size = -size;
33 
34     if(size > maxsize)
35         boost::serialization::throw_exception(
36             portable_binary_iarchive_exception()
37         );
38 
39     char * cptr = reinterpret_cast<char *>(& l);
40     #if BOOST_ENDIAN_BIG_BYTE
41         cptr += (sizeof(boost::intmax_t) - size);
42     #endif
43     this->primitive_base_t::load_binary(cptr, size);
44 
45     #if BOOST_ENDIAN_BIG_BYTE
46         if(m_flags & endian_little)
47     #else
48         if(m_flags & endian_big)
49     #endif
50     reverse_bytes(size, cptr);
51 
52     if(negative)
53         l = -l;
54 }
55 
56 void
load_override(boost::archive::class_name_type & t)57 portable_binary_iarchive::load_override(
58     boost::archive::class_name_type & t
59 ){
60     std::string cn;
61     cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE);
62     load_override(cn);
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)
67             );
68     std::memcpy(t, cn.data(), cn.size());
69     // borland tweak
70     t.t[cn.size()] = '\0';
71 }
72 
73 void
init(unsigned int flags)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
83                 )
84             );
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;
89 
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
95                 )
96             );
97 
98         #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
99         this->set_library_version(input_library_version);
100         //#else
101         //#if ! BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
102         //detail::
103         //#endif
104         boost::archive::detail::basic_iarchive::set_library_version(
105             input_library_version
106         );
107         #endif
108     }
109     unsigned char x;
110     load(x);
111     m_flags = x << CHAR_BIT;
112 }
113 
114 #include <boost/archive/impl/archive_serializer_map.ipp>
115 #include <boost/archive/impl/basic_binary_iprimitive.ipp>
116 
117 namespace boost {
118 namespace archive {
119 
120 namespace detail {
121     template class archive_serializer_map<portable_binary_iarchive>;
122 }
123 
124 template class basic_binary_iprimitive<
125     portable_binary_iarchive,
126     std::istream::char_type,
127     std::istream::traits_type
128 > ;
129 
130 } // namespace archive
131 } // namespace boost
132