1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // basic_binary_oprimitive.ipp:
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)
9 // See http://www.boost.org for updates, documentation, and revision history.
12 #include <cstddef> // NULL
15 #include <boost/config.hpp>
17 #if defined(BOOST_NO_STDC_NAMESPACE) && ! defined(__LIBCOMO__)
23 #ifndef BOOST_NO_CWCHAR
25 #ifdef BOOST_NO_STDC_NAMESPACE
26 namespace std{ using ::wcslen; }
30 #include <boost/archive/basic_binary_oprimitive.hpp>
31 #include <boost/core/no_exceptions_support.hpp>
36 //////////////////////////////////////////////////////////////////////
37 // implementation of basic_binary_oprimitive
39 template<class Archive, class Elem, class Tr>
40 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
41 basic_binary_oprimitive<Archive, Elem, Tr>::init()
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));
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)
59 std::size_t l = std::strlen(s);
60 this->This()->save(l);
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)
68 std::size_t l = static_cast<std::size_t>(s.size());
69 this->This()->save(l);
70 save_binary(s.data(), l);
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)
78 std::size_t l = std::wcslen(ws);
79 this->This()->save(l);
80 save_binary(ws, l * sizeof(wchar_t) / sizeof(char));
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)
89 std::size_t l = ws.size();
90 this->This()->save(l);
91 save_binary(ws.data(), l * sizeof(wchar_t) / sizeof(char));
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,
101 #ifndef BOOST_NO_STD_LOCALE
103 codecvt_null_facet(1),
105 archive_locale(sb.getloc(), & codecvt_null_facet)
109 m_sb.pubimbue(archive_locale);
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(){}
123 } // namespace archive