Monero
Loading...
Searching...
No Matches
portable_binary_oarchive.hpp
Go to the documentation of this file.
1#ifndef PORTABLE_BINARY_OARCHIVE_HPP
2#define PORTABLE_BINARY_OARCHIVE_HPP
3
4// MS compatible compilers support #pragma once
5#if defined(_MSC_VER)
6# pragma once
7#endif
8
9#if defined(_MSC_VER)
10#pragma warning( push )
11#pragma warning( disable : 4244 )
12#endif
13
15// portable_binary_oarchive.hpp
16
17// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
18// Use, modification and distribution is subject to the Boost Software
19// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
20// http://www.boost.org/LICENSE_1_0.txt)
21
22// See http://www.boost.org for updates, documentation, and revision history.
23
24#include <ostream>
25#include <boost/version.hpp>
26#include <boost/serialization/string.hpp>
27#include <boost/archive/archive_exception.hpp>
28#include <boost/archive/basic_binary_oprimitive.hpp>
29#include <boost/archive/detail/common_oarchive.hpp>
30#include <boost/archive/detail/register_archive.hpp>
31
33#include <boost/archive/impl/basic_binary_oprimitive.ipp>
34
35namespace boost { namespace archive {
36
38// exception to be thrown if integer read from archive doesn't fit
39// variable being loaded
41 public boost::archive::archive_exception
42{
43public:
48 boost::archive::archive_exception(boost::archive::archive_exception::other_exception),
50 {}
51 virtual const char *what( ) const throw( )
52 {
53 const char *msg = "programmer error";
54 switch(m_exception_code){
55 case invalid_flags:
56 msg = "cannot be both big and little endian";
57 break;
58 default:
59 msg = boost::archive::archive_exception::what();
60 assert(false);
61 break;
62 }
63 return msg;
64 }
65};
66
68// "Portable" output binary archive. This is a variation of the native binary
69// archive. it addresses integer size and endienness so that binary archives can
70// be passed across systems. Note:floating point types not addressed here
71
73 public boost::archive::basic_binary_oprimitive<
74 portable_binary_oarchive,
75 std::ostream::char_type,
76 std::ostream::traits_type
77 >,
78 public boost::archive::detail::common_oarchive<
79 portable_binary_oarchive
80 >
81{
82 typedef boost::archive::basic_binary_oprimitive<
84 std::ostream::char_type,
85 std::ostream::traits_type
87 typedef boost::archive::detail::common_oarchive<
90#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
91public:
92#else
93 friend archive_base_t;
94 friend primitive_base_t; // since with override save below
95 friend class boost::archive::detail::interface_oarchive<
97 >;
98 friend class boost::archive::save_access;
99protected:
100#endif
101 unsigned int m_flags;
102 void save_impl(const boost::intmax_t l, const char maxsize);
103 // add base class to the places considered when matching
104 // save function to a specific set of arguments. Note, this didn't
105 // work on my MSVC 7.0 system so we use the sure-fire method below
106 // using archive_base_t::save;
107
108 // default fall through for any types not specified here
109 template<class T>
110 void save(const T & t){
111 save_impl(t, sizeof(T));
112 }
113 void save(const std::string & t){
114 this->primitive_base_t::save(t);
115 }
116 #ifndef BOOST_NO_STD_WSTRING
117 void save(const std::wstring & t){
118 this->primitive_base_t::save(t);
119 }
120 #endif
121 void save(const float & t){
122 this->primitive_base_t::save(t);
123 // floats not supported
124 //BOOST_STATIC_ASSERT(false);
125 }
126 void save(const double & t){
127 this->primitive_base_t::save(t);
128 // doubles not supported
129 //BOOST_STATIC_ASSERT(false);
130 }
131 void save(const char & t){
132 this->primitive_base_t::save(t);
133 }
134 void save(const unsigned char & t){
135 this->primitive_base_t::save(t);
136 }
137
138 // default processing - kick back to base class. Note the
139 // extra stuff to get it passed borland compilers
140 typedef boost::archive::detail::common_oarchive<portable_binary_oarchive>
142#if BOOST_VERSION > 105800
143 template<class T>
144 void save_override(T & t){
145 this->detail_common_oarchive::save_override(t);
146 }
147 // explicitly convert to char * to avoid compile ambiguities
148 void save_override(const boost::archive::class_name_type & t){
149 const std::string s(t);
150 * this << s;
151 }
152 // binary files don't include the optional information
153 void save_override(
154 const boost::archive::class_id_optional_type & /* t */
155 ){}
156#else
157 template<class T>
158 void save_override(T & t, int){
159 this->detail_common_oarchive::save_override(t, 0);
160 }
161 // explicitly convert to char * to avoid compile ambiguities
162 void save_override(const boost::archive::class_name_type & t, int){
163 const std::string s(t);
164 * this << s;
165 }
166 // binary files don't include the optional information
168 const boost::archive::class_id_optional_type & /* t */, int
169 ){}
170#endif
171
172 void init(unsigned int flags);
173public:
174 portable_binary_oarchive(std::ostream & os, unsigned flags = endian_little) :
176 * os.rdbuf(),
177 0 != (flags & boost::archive::no_codecvt)
178 ),
181 {
182 init(flags);
183 }
184
186 std::basic_streambuf<
187 std::ostream::char_type,
188 std::ostream::traits_type
189 > & bsb,
190 unsigned int flags
191 ) :
193 bsb,
194 0 != (flags & boost::archive::no_codecvt)
195 ),
197 m_flags(0)
198 {
199 init(flags);
200 }
201};
202
203} }
204
205// required by export in boost version > 1.34
206#ifdef BOOST_SERIALIZATION_REGISTER_ARCHIVE
207 BOOST_SERIALIZATION_REGISTER_ARCHIVE(portable_binary_oarchive)
208#endif
209
210// required by export in boost <= 1.34
211#define BOOST_ARCHIVE_CUSTOM_OARCHIVE_TYPES portable_binary_oarchive
212
214// portable_binary_oarchive.cpp
215
216// (C) Copyright 2002-7 Robert Ramey - http://www.rrsd.com .
217// Use, modification and distribution is subject to the Boost Software
218// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
219// http://www.boost.org/LICENSE_1_0.txt)
220
221// See http://www.boost.org for updates, documentation, and revision history.
222
223#include <ostream>
224#include <boost/predef/other/endian.h>
225
226namespace boost { namespace archive {
227
228inline void
230 const boost::intmax_t l,
231 const char maxsize
232){
233 signed char size = 0;
234
235 if(l == 0){
236 this->primitive_base_t::save(size);
237 return;
238 }
239
240 boost::intmax_t ll;
241 bool negative = (l < 0);
242 if(negative)
243 ll = -l;
244 else
245 ll = l;
246
247 do{
248 ll >>= CHAR_BIT;
249 ++size;
250 }while(ll != 0);
251
252 this->primitive_base_t::save(
253 static_cast<signed char>(negative ? -size : size)
254 );
255
256 if(negative)
257 ll = -l;
258 else
259 ll = l;
260 char * cptr = reinterpret_cast<char *>(& ll);
261 #if BOOST_ENDIAN_BIG_BYTE
262 cptr += (sizeof(boost::intmax_t) - size);
264 reverse_bytes(size, cptr);
265 #else
266 if(m_flags & endian_big)
267 reverse_bytes(size, cptr);
268 #endif
269 this->primitive_base_t::save_binary(cptr, size);
270}
271
272inline void
275 boost::serialization::throw_exception(
277 );
278 }
279 if(0 == (flags & boost::archive::no_header)){
280 // write signature in an archive version independent manner
281 const std::string file_signature(
282 boost::archive::BOOST_ARCHIVE_SIGNATURE()
283 );
284 * this << file_signature;
285 // ignore archive version checking
286 const boost::archive::library_version_type v{};
287 /*
288 // write library version
289 const boost::archive::library_version_type v(
290 boost::archive::BOOST_ARCHIVE_VERSION()
291 );
292 */
293 * this << v;
294 }
295 save(static_cast<unsigned char>(m_flags >> CHAR_BIT));
296}
297
298} }
299
300namespace boost {
301namespace archive {
302
303namespace detail {
304 template class archive_serializer_map<portable_binary_oarchive>;
305}
306
307// template class basic_binary_oprimitive<
308// portable_binary_oarchive,
309// std::ostream::char_type,
310// std::ostream::traits_type
311// > ;
312
313} // namespace archive
314} // namespace boost
315
316#if defined(_MSC_VER)
317#pragma warning( pop )
318#endif
319
320#endif // PORTABLE_BINARY_OARCHIVE_HPP
#define s(x, c)
Definition aesb.c:47
Definition portable_binary_oarchive.hpp:42
virtual const char * what() const
Definition portable_binary_oarchive.hpp:51
exception_code
Definition portable_binary_oarchive.hpp:44
@ invalid_flags
Definition portable_binary_oarchive.hpp:45
enum boost::archive::portable_binary_oarchive_exception::exception_code m_exception_code
portable_binary_oarchive_exception(exception_code c=invalid_flags)
Definition portable_binary_oarchive.hpp:47
boost::archive::basic_binary_oprimitive< portable_binary_oarchive, std::ostream::char_type, std::ostream::traits_type > primitive_base_t
Definition portable_binary_oarchive.hpp:86
void save(const unsigned char &t)
Definition portable_binary_oarchive.hpp:134
void save(const std::wstring &t)
Definition portable_binary_oarchive.hpp:117
void save_override(const boost::archive::class_name_type &t, int)
Definition portable_binary_oarchive.hpp:162
void save_impl(const boost::intmax_t l, const char maxsize)
Definition portable_binary_oarchive.hpp:229
void save(const double &t)
Definition portable_binary_oarchive.hpp:126
boost::archive::detail::common_oarchive< portable_binary_oarchive > archive_base_t
Definition portable_binary_oarchive.hpp:89
portable_binary_oarchive(std::basic_streambuf< std::ostream::char_type, std::ostream::traits_type > &bsb, unsigned int flags)
Definition portable_binary_oarchive.hpp:185
void save(const char &t)
Definition portable_binary_oarchive.hpp:131
void save_override(T &t, int)
Definition portable_binary_oarchive.hpp:158
void save(const T &t)
Definition portable_binary_oarchive.hpp:110
void init(unsigned int flags)
Definition portable_binary_oarchive.hpp:273
void save(const std::string &t)
Definition portable_binary_oarchive.hpp:113
portable_binary_oarchive(std::ostream &os, unsigned flags=endian_little)
Definition portable_binary_oarchive.hpp:174
boost::archive::detail::common_oarchive< portable_binary_oarchive > detail_common_oarchive
Definition portable_binary_oarchive.hpp:141
void save_override(const boost::archive::class_id_optional_type &, int)
Definition portable_binary_oarchive.hpp:167
void save(const float &t)
Definition portable_binary_oarchive.hpp:121
unsigned int m_flags
Definition portable_binary_oarchive.hpp:101
static void init()
Definition logging.cpp:42
static int flags
Definition mdb_load.c:31
Definition portable_binary_archive.hpp:29
@ endian_big
Definition portable_binary_archive.hpp:32
@ endian_little
Definition portable_binary_archive.hpp:33
void reverse_bytes(signed char size, char *address)
Definition portable_binary_archive.hpp:41
Definition portable_binary_archive.hpp:29
declaration and default definition for the functions used the API
Definition expect.cpp:34
static unsigned char negative(signed char b)
Definition crypto-ops.c:1598
#define T(x)