]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/serialization/include/boost/archive/impl/basic_binary_iprimitive.ipp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / serialization / include / boost / archive / impl / basic_binary_iprimitive.ipp
CommitLineData
7c673cae
FG
1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// basic_binary_iprimitive.ipp:
3
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)
8
9// See http://www.boost.org for updates, documentation, and revision history.
10
11#include <boost/assert.hpp>
12#include <cstddef> // size_t, NULL
13#include <cstring> // memcpy
14
15#include <boost/config.hpp>
16#if defined(BOOST_NO_STDC_NAMESPACE)
17namespace std{
18 using ::size_t;
19 using ::memcpy;
20} // namespace std
21#endif
22
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>
27
28namespace boost {
29namespace archive {
30
31//////////////////////////////////////////////////////////////////////
32// implementation of basic_binary_iprimitive
33
34template<class Archive, class Elem, class Tr>
35BOOST_ARCHIVE_OR_WARCHIVE_DECL void
36basic_binary_iprimitive<Archive, Elem, Tr>::init()
37{
38 // Detect attempts to pass native binary archives across
39 // incompatible platforms. This is not fool proof but its
40 // better than nothing.
41 unsigned char size;
42 this->This()->load(size);
43 if(sizeof(int) != size)
44 boost::serialization::throw_exception(
45 archive_exception(
46 archive_exception::incompatible_native_format,
47 "size of int"
48 )
49 );
50 this->This()->load(size);
51 if(sizeof(long) != size)
52 boost::serialization::throw_exception(
53 archive_exception(
54 archive_exception::incompatible_native_format,
55 "size of long"
56 )
57 );
58 this->This()->load(size);
59 if(sizeof(float) != size)
60 boost::serialization::throw_exception(
61 archive_exception(
62 archive_exception::incompatible_native_format,
63 "size of float"
64 )
65 );
66 this->This()->load(size);
67 if(sizeof(double) != size)
68 boost::serialization::throw_exception(
69 archive_exception(
70 archive_exception::incompatible_native_format,
71 "size of double"
72 )
73 );
74
75 // for checking endian
76 int i;
77 this->This()->load(i);
78 if(1 != i)
79 boost::serialization::throw_exception(
80 archive_exception(
81 archive_exception::incompatible_native_format,
82 "endian setting"
83 )
84 );
85}
86
87template<class Archive, class Elem, class Tr>
88BOOST_ARCHIVE_OR_WARCHIVE_DECL void
89basic_binary_iprimitive<Archive, Elem, Tr>::load(wchar_t * ws)
90{
91 std::size_t l; // number of wchar_t !!!
92 this->This()->load(l);
93 load_binary(ws, l * sizeof(wchar_t) / sizeof(char));
94 ws[l] = L'\0';
95}
96
97template<class Archive, class Elem, class Tr>
98BOOST_ARCHIVE_OR_WARCHIVE_DECL void
99basic_binary_iprimitive<Archive, Elem, Tr>::load(std::string & s)
100{
101 std::size_t l;
102 this->This()->load(l);
103 // borland de-allocator fixup
104 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
105 if(NULL != s.data())
106 #endif
107 s.resize(l);
108 // note breaking a rule here - could be a problem on some platform
109 if(0 < l)
110 load_binary(&(*s.begin()), l);
111}
112
113#ifndef BOOST_NO_CWCHAR
114template<class Archive, class Elem, class Tr>
115BOOST_ARCHIVE_OR_WARCHIVE_DECL void
116basic_binary_iprimitive<Archive, Elem, Tr>::load(char * s)
117{
118 std::size_t l;
119 this->This()->load(l);
120 load_binary(s, l);
121 s[l] = '\0';
122}
123#endif
124
125#ifndef BOOST_NO_STD_WSTRING
126template<class Archive, class Elem, class Tr>
127BOOST_ARCHIVE_OR_WARCHIVE_DECL void
128basic_binary_iprimitive<Archive, Elem, Tr>::load(std::wstring & ws)
129{
130 std::size_t l;
131 this->This()->load(l);
132 // borland de-allocator fixup
133 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
134 if(NULL != ws.data())
135 #endif
136 ws.resize(l);
137 // note breaking a rule here - is could be a problem on some platform
138 load_binary(const_cast<wchar_t *>(ws.data()), l * sizeof(wchar_t) / sizeof(char));
139}
140#endif
141
142template<class Archive, class Elem, class Tr>
143BOOST_ARCHIVE_OR_WARCHIVE_DECL
144basic_binary_iprimitive<Archive, Elem, Tr>::basic_binary_iprimitive(
145 std::basic_streambuf<Elem, Tr> & sb,
146 bool no_codecvt
147) :
148#ifndef BOOST_NO_STD_LOCALE
149 m_sb(sb),
150 codecvt_null_facet(1),
151 locale_saver(m_sb),
152 archive_locale(sb.getloc(), & codecvt_null_facet)
153{
154 if(! no_codecvt){
155 m_sb.pubsync();
156 m_sb.pubimbue(archive_locale);
157 }
158}
159#else
160 m_sb(sb)
161{}
162#endif
163
164// scoped_ptr requires that g be a complete type at time of
165// destruction so define destructor here rather than in the header
166template<class Archive, class Elem, class Tr>
167BOOST_ARCHIVE_OR_WARCHIVE_DECL
168basic_binary_iprimitive<Archive, Elem, Tr>::~basic_binary_iprimitive(){}
169
170} // namespace archive
171} // namespace boost