/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // xml_woarchive_impl.ipp: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #ifndef BOOST_NO_STD_WSTREAMBUF #include #include #include // std::copy #include #include // strlen #include // mbtowc #ifndef BOOST_NO_CWCHAR #include // wcslen #endif #include #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::strlen; #if ! defined(BOOST_NO_INTRINSIC_WCHAR_T) using ::mbtowc; using ::wcslen; #endif } // namespace std #endif #include #include #include #include #include #include #include #include namespace boost { namespace archive { /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // implemenations of functions specific to wide char archives // copy chars to output escaping to xml and widening characters as we go template void save_iterator(std::wostream &os, InputIterator begin, InputIterator end){ typedef iterators::wchar_from_mb< iterators::xml_escape > xmbtows; std::copy( xmbtows(begin), xmbtows(end), boost::archive::iterators::ostream_iterator(os) ); } template BOOST_WARCHIVE_DECL void xml_woarchive_impl::save(const std::string & s){ // note: we don't use s.begin() and s.end() because dinkumware // doesn't have string::value_type defined. So use a wrapper // around these values to implement the definitions. const char * begin = s.data(); const char * end = begin + s.size(); save_iterator(os, begin, end); } #ifndef BOOST_NO_STD_WSTRING template BOOST_WARCHIVE_DECL void xml_woarchive_impl::save(const std::wstring & ws){ #if 0 typedef iterators::xml_escape xmbtows; std::copy( xmbtows(ws.begin()), xmbtows(ws.end()), boost::archive::iterators::ostream_iterator(os) ); #endif typedef iterators::xml_escape xmbtows; std::copy( xmbtows(ws.data()), xmbtows(ws.data() + ws.size()), boost::archive::iterators::ostream_iterator(os) ); } #endif //BOOST_NO_STD_WSTRING template BOOST_WARCHIVE_DECL void xml_woarchive_impl::save(const char * s){ save_iterator(os, s, s + std::strlen(s)); } #ifndef BOOST_NO_INTRINSIC_WCHAR_T template BOOST_WARCHIVE_DECL void xml_woarchive_impl::save(const wchar_t * ws){ typedef iterators::xml_escape xmbtows; std::copy( xmbtows(ws), xmbtows(ws + std::wcslen(ws)), boost::archive::iterators::ostream_iterator(os) ); } #endif template BOOST_WARCHIVE_DECL xml_woarchive_impl::xml_woarchive_impl( std::wostream & os_, unsigned int flags ) : basic_text_oprimitive( os_, true // don't change the codecvt - use the one below ), basic_xml_oarchive(flags) { if(0 == (flags & no_codecvt)){ archive_locale = std::locale( os_.getloc(), new boost::archive::detail::utf8_codecvt_facet ); os_.flush(); os_.imbue(archive_locale); } } template BOOST_WARCHIVE_DECL xml_woarchive_impl::~xml_woarchive_impl(){ if(boost::core::uncaught_exceptions() > 0) return; if(0 == (this->get_flags() & no_header)){ os << L""; } } template BOOST_WARCHIVE_DECL void xml_woarchive_impl::save_binary( const void *address, std::size_t count ){ this->end_preamble(); #if ! defined(__MWERKS__) this->basic_text_oprimitive::save_binary( #else this->basic_text_oprimitive::save_binary( #endif address, count ); this->indent_next = true; } } // namespace archive } // namespace boost #endif //BOOST_NO_STD_WSTREAMBUF