File indexing completed on 2025-01-18 09:28:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <boost/assert.hpp>
0012 #include <cstddef> // size_t, NULL
0013 #include <cstring> // memcpy
0014
0015 #include <boost/config.hpp>
0016 #if defined(BOOST_NO_STDC_NAMESPACE)
0017 namespace std{
0018 using ::size_t;
0019 using ::memcpy;
0020 }
0021 #endif
0022
0023 #include <boost/serialization/throw_exception.hpp>
0024 #include <boost/core/no_exceptions_support.hpp>
0025 #include <boost/archive/archive_exception.hpp>
0026 #include <boost/archive/basic_binary_iprimitive.hpp>
0027
0028 namespace boost {
0029 namespace archive {
0030
0031
0032
0033
0034 template<class Archive, class Elem, class Tr>
0035 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0036 basic_binary_iprimitive<Archive, Elem, Tr>::init()
0037 {
0038
0039
0040
0041 unsigned char size;
0042 this->This()->load(size);
0043 if(sizeof(int) != size)
0044 boost::serialization::throw_exception(
0045 archive_exception(
0046 archive_exception::incompatible_native_format,
0047 "size of int"
0048 )
0049 );
0050 this->This()->load(size);
0051 if(sizeof(long) != size)
0052 boost::serialization::throw_exception(
0053 archive_exception(
0054 archive_exception::incompatible_native_format,
0055 "size of long"
0056 )
0057 );
0058 this->This()->load(size);
0059 if(sizeof(float) != size)
0060 boost::serialization::throw_exception(
0061 archive_exception(
0062 archive_exception::incompatible_native_format,
0063 "size of float"
0064 )
0065 );
0066 this->This()->load(size);
0067 if(sizeof(double) != size)
0068 boost::serialization::throw_exception(
0069 archive_exception(
0070 archive_exception::incompatible_native_format,
0071 "size of double"
0072 )
0073 );
0074
0075
0076 int i;
0077 this->This()->load(i);
0078 if(1 != i)
0079 boost::serialization::throw_exception(
0080 archive_exception(
0081 archive_exception::incompatible_native_format,
0082 "endian setting"
0083 )
0084 );
0085 }
0086
0087 #ifndef BOOST_NO_CWCHAR
0088 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
0089 template<class Archive, class Elem, class Tr>
0090 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0091 basic_binary_iprimitive<Archive, Elem, Tr>::load(wchar_t * ws)
0092 {
0093 std::size_t l;
0094 this->This()->load(l);
0095 load_binary(ws, l * sizeof(wchar_t) / sizeof(char));
0096 ws[l] = L'\0';
0097 }
0098 #endif
0099 #endif
0100
0101 template<class Archive, class Elem, class Tr>
0102 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0103 basic_binary_iprimitive<Archive, Elem, Tr>::load(std::string & s)
0104 {
0105 std::size_t l;
0106 this->This()->load(l);
0107
0108 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
0109 if(NULL != s.data())
0110 #endif
0111 s.resize(l);
0112
0113 if(0 < l)
0114 load_binary(&(*s.begin()), l);
0115 }
0116
0117 template<class Archive, class Elem, class Tr>
0118 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0119 basic_binary_iprimitive<Archive, Elem, Tr>::load(char * s)
0120 {
0121 std::size_t l;
0122 this->This()->load(l);
0123 load_binary(s, l);
0124 s[l] = '\0';
0125 }
0126
0127 #ifndef BOOST_NO_STD_WSTRING
0128 template<class Archive, class Elem, class Tr>
0129 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0130 basic_binary_iprimitive<Archive, Elem, Tr>::load(std::wstring & ws)
0131 {
0132 std::size_t l;
0133 this->This()->load(l);
0134
0135 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
0136 if(NULL != ws.data())
0137 #endif
0138 ws.resize(l);
0139
0140 load_binary(const_cast<wchar_t *>(ws.data()), l * sizeof(wchar_t) / sizeof(char));
0141 }
0142 #endif
0143
0144 template<class Archive, class Elem, class Tr>
0145 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0146 basic_binary_iprimitive<Archive, Elem, Tr>::basic_binary_iprimitive(
0147 std::basic_streambuf<Elem, Tr> & sb,
0148 bool no_codecvt
0149 ) :
0150 #ifndef BOOST_NO_STD_LOCALE
0151 m_sb(sb),
0152 codecvt_null_facet(1),
0153 locale_saver(m_sb),
0154 archive_locale(sb.getloc(), & codecvt_null_facet)
0155 {
0156 if(! no_codecvt){
0157 m_sb.pubsync();
0158 m_sb.pubimbue(archive_locale);
0159 }
0160 }
0161 #else
0162 m_sb(sb)
0163 {}
0164 #endif
0165
0166
0167
0168 template<class Archive, class Elem, class Tr>
0169 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0170 basic_binary_iprimitive<Archive, Elem, Tr>::~basic_binary_iprimitive(){}
0171
0172 }
0173 }