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__) 18namespace std{ 19 using ::strlen; 20} // namespace std 21#endif 22 23#ifndef BOOST_NO_CWCHAR 24#include <cwchar> 25#ifdef BOOST_NO_STDC_NAMESPACE 26namespace 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 33namespace boost { 34namespace archive { 35 36////////////////////////////////////////////////////////////////////// 37// implementation of basic_binary_oprimitive 38 39template<class Archive, class Elem, class Tr> 40BOOST_ARCHIVE_OR_WARCHIVE_DECL void 41basic_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 55template<class Archive, class Elem, class Tr> 56BOOST_ARCHIVE_OR_WARCHIVE_DECL void 57basic_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 64template<class Archive, class Elem, class Tr> 65BOOST_ARCHIVE_OR_WARCHIVE_DECL void 66basic_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#ifndef BOOST_NO_INTRINSIC_WCHAR_T 75template<class Archive, class Elem, class Tr> 76BOOST_ARCHIVE_OR_WARCHIVE_DECL void 77basic_binary_oprimitive<Archive, Elem, Tr>::save(const wchar_t * ws) 78{ 79 std::size_t l = std::wcslen(ws); 80 this->This()->save(l); 81 save_binary(ws, l * sizeof(wchar_t) / sizeof(char)); 82} 83#endif 84 85#ifndef BOOST_NO_STD_WSTRING 86template<class Archive, class Elem, class Tr> 87BOOST_ARCHIVE_OR_WARCHIVE_DECL void 88basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::wstring &ws) 89{ 90 std::size_t l = ws.size(); 91 this->This()->save(l); 92 save_binary(ws.data(), l * sizeof(wchar_t) / sizeof(char)); 93} 94#endif 95#endif // BOOST_NO_CWCHAR 96 97template<class Archive, class Elem, class Tr> 98BOOST_ARCHIVE_OR_WARCHIVE_DECL 99basic_binary_oprimitive<Archive, Elem, Tr>::basic_binary_oprimitive( 100 std::basic_streambuf<Elem, Tr> & sb, 101 bool no_codecvt 102) : 103#ifndef BOOST_NO_STD_LOCALE 104 m_sb(sb), 105 codecvt_null_facet(1), 106 locale_saver(m_sb), 107 archive_locale(sb.getloc(), & codecvt_null_facet) 108{ 109 if(! no_codecvt){ 110 m_sb.pubsync(); 111 m_sb.pubimbue(archive_locale); 112 } 113} 114#else 115 m_sb(sb) 116{} 117#endif 118 119// scoped_ptr requires that g be a complete type at time of 120// destruction so define destructor here rather than in the header 121template<class Archive, class Elem, class Tr> 122BOOST_ARCHIVE_OR_WARCHIVE_DECL 123basic_binary_oprimitive<Archive, Elem, Tr>::~basic_binary_oprimitive(){} 124 125} // namespace archive 126} // namespace boost 127