File indexing completed on 2025-01-18 09:28:29
0001 #ifndef BOOST_ARCHIVE_BINARY_IPRIMITIVE_HPP
0002 #define BOOST_ARCHIVE_BINARY_IPRIMITIVE_HPP
0003
0004
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008
0009 #if defined(_MSC_VER)
0010 #pragma warning( disable : 4800 )
0011 #endif
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #include <iosfwd>
0031 #include <boost/assert.hpp>
0032 #include <locale>
0033 #include <cstring> // std::memcpy
0034 #include <cstddef> // std::size_t
0035 #include <streambuf> // basic_streambuf
0036 #include <string>
0037
0038 #include <boost/config.hpp>
0039 #if defined(BOOST_NO_STDC_NAMESPACE)
0040 namespace std{
0041 using ::memcpy;
0042 using ::size_t;
0043 }
0044 #endif
0045
0046 #include <boost/cstdint.hpp>
0047 #include <boost/serialization/throw_exception.hpp>
0048 #include <boost/integer.hpp>
0049 #include <boost/integer_traits.hpp>
0050
0051 #include <boost/serialization/is_bitwise_serializable.hpp>
0052 #include <boost/serialization/array_wrapper.hpp>
0053
0054 #include <boost/archive/basic_streambuf_locale_saver.hpp>
0055 #include <boost/archive/codecvt_null.hpp>
0056 #include <boost/archive/archive_exception.hpp>
0057 #include <boost/archive/detail/auto_link_archive.hpp>
0058 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
0059
0060 namespace boost {
0061 namespace archive {
0062
0063
0064
0065 template<class Archive, class Elem, class Tr>
0066 class BOOST_SYMBOL_VISIBLE basic_binary_iprimitive {
0067 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
0068 friend class load_access;
0069 protected:
0070 #else
0071 public:
0072 #endif
0073 std::basic_streambuf<Elem, Tr> & m_sb;
0074
0075 Archive * This(){
0076 return static_cast<Archive *>(this);
0077 }
0078
0079 #ifndef BOOST_NO_STD_LOCALE
0080
0081
0082
0083
0084
0085
0086
0087 boost::archive::codecvt_null<Elem> codecvt_null_facet;
0088 basic_streambuf_locale_saver<Elem, Tr> locale_saver;
0089 std::locale archive_locale;
0090 #endif
0091
0092
0093 template<class T>
0094 void load(T & t){
0095 load_binary(& t, sizeof(T));
0096 }
0097
0098
0099
0100
0101
0102 void load(bool & t){
0103 load_binary(& t, sizeof(t));
0104 int i = t;
0105 BOOST_ASSERT(0 == i || 1 == i);
0106 (void)i;
0107 }
0108 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0109 load(std::string &s);
0110 #ifndef BOOST_NO_STD_WSTRING
0111 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0112 load(std::wstring &ws);
0113 #endif
0114 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0115 load(char * t);
0116 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0117 load(wchar_t * t);
0118
0119 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0120 init();
0121 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0122 basic_binary_iprimitive(
0123 std::basic_streambuf<Elem, Tr> & sb,
0124 bool no_codecvt
0125 );
0126 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0127 ~basic_binary_iprimitive();
0128 public:
0129
0130
0131
0132 struct use_array_optimization {
0133 template <class T>
0134 #if defined(BOOST_NO_DEPENDENT_NESTED_DERIVATIONS)
0135 struct apply {
0136 typedef typename boost::serialization::is_bitwise_serializable< T >::type type;
0137 };
0138 #else
0139 struct apply : public boost::serialization::is_bitwise_serializable< T > {};
0140 #endif
0141 };
0142
0143
0144 template <class ValueType>
0145 void load_array(serialization::array_wrapper<ValueType>& a, unsigned int)
0146 {
0147 load_binary(a.address(),a.count()*sizeof(ValueType));
0148 }
0149
0150 void
0151 load_binary(void *address, std::size_t count);
0152 };
0153
0154 template<class Archive, class Elem, class Tr>
0155 inline void
0156 basic_binary_iprimitive<Archive, Elem, Tr>::load_binary(
0157 void *address,
0158 std::size_t count
0159 ){
0160
0161 BOOST_ASSERT(
0162 static_cast<std::streamsize>(count / sizeof(Elem))
0163 <= boost::integer_traits<std::streamsize>::const_max
0164 );
0165 std::streamsize s = static_cast<std::streamsize>(count / sizeof(Elem));
0166 std::streamsize scount = m_sb.sgetn(
0167 static_cast<Elem *>(address),
0168 s
0169 );
0170 if(scount != s)
0171 boost::serialization::throw_exception(
0172 archive_exception(archive_exception::input_stream_error)
0173 );
0174
0175 BOOST_ASSERT(count % sizeof(Elem) <= boost::integer_traits<std::streamsize>::const_max);
0176 s = static_cast<std::streamsize>(count % sizeof(Elem));
0177 if(0 < s){
0178
0179
0180
0181
0182 Elem t;
0183 scount = m_sb.sgetn(& t, 1);
0184 if(scount != 1)
0185 boost::serialization::throw_exception(
0186 archive_exception(archive_exception::input_stream_error)
0187 );
0188 std::memcpy(static_cast<char*>(address) + (count - s), &t, static_cast<std::size_t>(s));
0189 }
0190 }
0191
0192 }
0193 }
0194
0195 #include <boost/archive/detail/abi_suffix.hpp> // pop pragmas
0196
0197 #endif