1 #ifndef PORTABLE_BINARY_IARCHIVE_HPP
2 #define PORTABLE_BINARY_IARCHIVE_HPP
4 // MS compatible compilers support #pragma once
10 #pragma warning( push )
11 #pragma warning( disable : 4244 )
14 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
15 // portable_binary_iarchive.hpp
17 // (C) Copyright 2002-7 Robert Ramey - http://www.rrsd.com .
18 // Use, modification and distribution is subject to the Boost Software
19 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
20 // http://www.boost.org/LICENSE_1_0.txt)
22 // See http://www.boost.org for updates, documentation, and revision history.
25 #include <boost/serialization/string.hpp>
26 #include <boost/serialization/item_version_type.hpp>
27 #include <boost/archive/archive_exception.hpp>
28 #include <boost/archive/basic_binary_iprimitive.hpp>
29 #include <boost/archive/detail/common_iarchive.hpp>
30 #include <boost/archive/detail/register_archive.hpp>
32 #include "portable_binary_archive.hpp"
34 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
35 // exception to be thrown if integer read from archive doesn't fit
36 // variable being loaded
37 class portable_binary_iarchive_exception :
38 public boost::archive::archive_exception
42 incompatible_integer_size
44 portable_binary_iarchive_exception(exception_code c = incompatible_integer_size ) :
45 boost::archive::archive_exception(boost::archive::archive_exception::other_exception),
48 virtual const char *what( ) const throw( )
50 const char *msg = "programmer error";
51 switch(m_exception_code){
52 case incompatible_integer_size:
53 msg = "integer cannot be represented";
56 msg = boost::archive::archive_exception::what();
64 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
65 // "Portable" input binary archive. It addresses integer size and endienness so
66 // that binary archives can be passed across systems. Note:floating point types
68 class portable_binary_iarchive :
69 public boost::archive::basic_binary_iprimitive<
70 portable_binary_iarchive,
71 std::istream::char_type,
72 std::istream::traits_type
74 public boost::archive::detail::common_iarchive<
75 portable_binary_iarchive
78 typedef boost::archive::basic_binary_iprimitive<
79 portable_binary_iarchive,
80 std::istream::char_type,
81 std::istream::traits_type
83 typedef boost::archive::detail::common_iarchive<
84 portable_binary_iarchive
86 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
89 friend archive_base_t;
90 friend primitive_base_t; // since with override load below
91 friend class boost::archive::detail::interface_iarchive<
92 portable_binary_iarchive
94 friend class boost::archive::load_access;
98 void load_impl(boost::intmax_t & l, char maxsize);
100 // default fall through for any types not specified here
104 load_impl(l, sizeof(T));
105 // use cast to avoid compile time warning
106 //t = static_cast< T >(l);
109 void load(boost::serialization::item_version_type & t){
111 load_impl(l, sizeof(boost::serialization::item_version_type));
112 // use cast to avoid compile time warning
113 t = boost::serialization::item_version_type(l);
115 void load(boost::archive::version_type & t){
117 load_impl(l, sizeof(boost::archive::version_type));
118 // use cast to avoid compile time warning
119 t = boost::archive::version_type(l);
121 void load(boost::archive::class_id_type & t){
123 load_impl(l, sizeof(boost::archive::class_id_type));
124 // use cast to avoid compile time warning
125 t = boost::archive::class_id_type(static_cast<int>(l));
127 void load(std::string & t){
128 this->primitive_base_t::load(t);
130 #ifndef BOOST_NO_STD_WSTRING
131 void load(std::wstring & t){
132 this->primitive_base_t::load(t);
135 void load(float & t){
136 this->primitive_base_t::load(t);
137 // floats not supported
138 //BOOST_STATIC_ASSERT(false);
140 void load(double & t){
141 this->primitive_base_t::load(t);
142 // doubles not supported
143 //BOOST_STATIC_ASSERT(false);
146 this->primitive_base_t::load(t);
148 void load(unsigned char & t){
149 this->primitive_base_t::load(t);
151 typedef boost::archive::detail::common_iarchive<portable_binary_iarchive>
152 detail_common_iarchive;
154 void load_override(T & t){
155 this->detail_common_iarchive::load_override(t);
157 void load_override(boost::archive::class_name_type & t);
158 // binary files don't include the optional information
159 void load_override(boost::archive::class_id_optional_type &){}
161 void init(unsigned int flags);
163 portable_binary_iarchive(std::istream & is, unsigned flags = 0) :
166 0 != (flags & boost::archive::no_codecvt)
168 archive_base_t(flags),
174 portable_binary_iarchive(
175 std::basic_streambuf<
176 std::istream::char_type,
177 std::istream::traits_type
183 0 != (flags & boost::archive::no_codecvt)
185 archive_base_t(flags),
192 // required by export in boost version > 1.34
193 #ifdef BOOST_SERIALIZATION_REGISTER_ARCHIVE
194 BOOST_SERIALIZATION_REGISTER_ARCHIVE(portable_binary_iarchive)
197 // required by export in boost <= 1.34
198 #define BOOST_ARCHIVE_CUSTOM_IARCHIVE_TYPES portable_binary_iarchive
200 #if defined(_MSC_VER)
201 #pragma warning( pop )
204 #endif // PORTABLE_BINARY_IARCHIVE_HPP