1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // basic_binary_iprimitive.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>
12 #include <cstddef> // size_t, NULL
13 #include <cstring> // memcpy
15 #include <boost/config.hpp>
16 #if defined(BOOST_NO_STDC_NAMESPACE)
23 #include <boost/serialization/throw_exception.hpp>
24 #include <boost/core/no_exceptions_support.hpp>
25 #include <boost/archive/archive_exception.hpp>
26 #include <boost/archive/basic_binary_iprimitive.hpp>
31 //////////////////////////////////////////////////////////////////////
32 // implementation of basic_binary_iprimitive
34 template<class Archive, class Elem, class Tr>
35 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
36 basic_binary_iprimitive<Archive, Elem, Tr>::init()
38 // Detect attempts to pass native binary archives across
39 // incompatible platforms. This is not fool proof but its
40 // better than nothing.
42 this->This()->load(size);
43 if(sizeof(int) != size)
44 boost::serialization::throw_exception(
46 archive_exception::incompatible_native_format,
50 this->This()->load(size);
51 if(sizeof(long) != size)
52 boost::serialization::throw_exception(
54 archive_exception::incompatible_native_format,
58 this->This()->load(size);
59 if(sizeof(float) != size)
60 boost::serialization::throw_exception(
62 archive_exception::incompatible_native_format,
66 this->This()->load(size);
67 if(sizeof(double) != size)
68 boost::serialization::throw_exception(
70 archive_exception::incompatible_native_format,
75 // for checking endian
77 this->This()->load(i);
79 boost::serialization::throw_exception(
81 archive_exception::incompatible_native_format,
87 #ifndef BOOST_NO_CWCHAR
88 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
89 template<class Archive, class Elem, class Tr>
90 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
91 basic_binary_iprimitive<Archive, Elem, Tr>::load(wchar_t * ws)
93 std::size_t l; // number of wchar_t !!!
94 this->This()->load(l);
95 load_binary(ws, l * sizeof(wchar_t) / sizeof(char));
101 template<class Archive, class Elem, class Tr>
102 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
103 basic_binary_iprimitive<Archive, Elem, Tr>::load(std::string & s)
106 this->This()->load(l);
107 // borland de-allocator fixup
108 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
112 // note breaking a rule here - could be a problem on some platform
114 load_binary(&(*s.begin()), l);
117 template<class Archive, class Elem, class Tr>
118 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
119 basic_binary_iprimitive<Archive, Elem, Tr>::load(char * s)
122 this->This()->load(l);
127 #ifndef BOOST_NO_STD_WSTRING
128 template<class Archive, class Elem, class Tr>
129 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
130 basic_binary_iprimitive<Archive, Elem, Tr>::load(std::wstring & ws)
133 this->This()->load(l);
134 // borland de-allocator fixup
135 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
136 if(NULL != ws.data())
139 // note breaking a rule here - is could be a problem on some platform
140 load_binary(const_cast<wchar_t *>(ws.data()), l * sizeof(wchar_t) / sizeof(char));
144 template<class Archive, class Elem, class Tr>
145 BOOST_ARCHIVE_OR_WARCHIVE_DECL
146 basic_binary_iprimitive<Archive, Elem, Tr>::basic_binary_iprimitive(
147 std::basic_streambuf<Elem, Tr> & sb,
150 #ifndef BOOST_NO_STD_LOCALE
152 codecvt_null_facet(1),
154 archive_locale(sb.getloc(), & codecvt_null_facet)
158 m_sb.pubimbue(archive_locale);
166 // scoped_ptr requires that g be a complete type at time of
167 // destruction so define destructor here rather than in the header
168 template<class Archive, class Elem, class Tr>
169 BOOST_ARCHIVE_OR_WARCHIVE_DECL
170 basic_binary_iprimitive<Archive, Elem, Tr>::~basic_binary_iprimitive(){}
172 } // namespace archive