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