]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/include/boost/archive/impl/basic_binary_oprimitive.ipp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / serialization / include / boost / archive / impl / basic_binary_oprimitive.ipp
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // basic_binary_oprimitive.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 <ostream>
12 #include <cstddef> // NULL
13 #include <cstring>
14
15 #include <boost/config.hpp>
16
17 #if defined(BOOST_NO_STDC_NAMESPACE) && ! defined(__LIBCOMO__)
18 namespace std{
19 using ::strlen;
20 } // namespace std
21 #endif
22
23 #ifndef BOOST_NO_CWCHAR
24 #include <cwchar>
25 #ifdef BOOST_NO_STDC_NAMESPACE
26 namespace std{ using ::wcslen; }
27 #endif
28 #endif
29
30 #include <boost/archive/basic_binary_oprimitive.hpp>
31 #include <boost/core/no_exceptions_support.hpp>
32
33 namespace boost {
34 namespace archive {
35
36 //////////////////////////////////////////////////////////////////////
37 // implementation of basic_binary_oprimitive
38
39 template<class Archive, class Elem, class Tr>
40 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
41 basic_binary_oprimitive<Archive, Elem, Tr>::init()
42 {
43 // record native sizes of fundamental types
44 // this is to permit detection of attempts to pass
45 // native binary archives accross incompatible machines.
46 // This is not foolproof but its better than nothing.
47 this->This()->save(static_cast<unsigned char>(sizeof(int)));
48 this->This()->save(static_cast<unsigned char>(sizeof(long)));
49 this->This()->save(static_cast<unsigned char>(sizeof(float)));
50 this->This()->save(static_cast<unsigned char>(sizeof(double)));
51 // for checking endianness
52 this->This()->save(int(1));
53 }
54
55 template<class Archive, class Elem, class Tr>
56 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
57 basic_binary_oprimitive<Archive, Elem, Tr>::save(const char * s)
58 {
59 std::size_t l = std::strlen(s);
60 this->This()->save(l);
61 save_binary(s, l);
62 }
63
64 template<class Archive, class Elem, class Tr>
65 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
66 basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::string &s)
67 {
68 std::size_t l = static_cast<std::size_t>(s.size());
69 this->This()->save(l);
70 save_binary(s.data(), l);
71 }
72
73 #ifndef BOOST_NO_CWCHAR
74 template<class Archive, class Elem, class Tr>
75 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
76 basic_binary_oprimitive<Archive, Elem, Tr>::save(const wchar_t * ws)
77 {
78 std::size_t l = std::wcslen(ws);
79 this->This()->save(l);
80 save_binary(ws, l * sizeof(wchar_t) / sizeof(char));
81 }
82 #endif
83
84 #ifndef BOOST_NO_STD_WSTRING
85 template<class Archive, class Elem, class Tr>
86 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
87 basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::wstring &ws)
88 {
89 std::size_t l = ws.size();
90 this->This()->save(l);
91 save_binary(ws.data(), l * sizeof(wchar_t) / sizeof(char));
92 }
93 #endif
94
95 template<class Archive, class Elem, class Tr>
96 BOOST_ARCHIVE_OR_WARCHIVE_DECL
97 basic_binary_oprimitive<Archive, Elem, Tr>::basic_binary_oprimitive(
98 std::basic_streambuf<Elem, Tr> & sb,
99 bool no_codecvt
100 ) :
101 #ifndef BOOST_NO_STD_LOCALE
102 m_sb(sb),
103 codecvt_null_facet(1),
104 locale_saver(m_sb),
105 archive_locale(sb.getloc(), & codecvt_null_facet)
106 {
107 if(! no_codecvt){
108 m_sb.pubsync();
109 m_sb.pubimbue(archive_locale);
110 }
111 }
112 #else
113 m_sb(sb)
114 {}
115 #endif
116
117 // scoped_ptr requires that g be a complete type at time of
118 // destruction so define destructor here rather than in the header
119 template<class Archive, class Elem, class Tr>
120 BOOST_ARCHIVE_OR_WARCHIVE_DECL
121 basic_binary_oprimitive<Archive, Elem, Tr>::~basic_binary_oprimitive(){}
122
123 } // namespace archive
124 } // namespace boost