/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // xml_oarchive_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 #include #include // std::copy #include #include #include // strlen #include // msvc 6.0 needs this to suppress warnings #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::strlen; } // namespace std #endif #include #include #ifndef BOOST_NO_CWCHAR #include #include #endif namespace lslboost { namespace archive { /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // implemenations of functions specific to char archives // wide char stuff used by char archives #ifndef BOOST_NO_CWCHAR // copy chars to output escaping to xml and translating wide chars to mb chars template void save_iterator(std::ostream &os, InputIterator begin, InputIterator end){ typedef lslboost::archive::iterators::mb_from_wchar< lslboost::archive::iterators::xml_escape > translator; std::copy( translator(begin), translator(end), lslboost::archive::iterators::ostream_iterator(os) ); } #ifndef BOOST_NO_STD_WSTRING template BOOST_ARCHIVE_DECL void xml_oarchive_impl::save(const std::wstring & ws){ // at least one library doesn't typedef value_type for strings // so rather than using string directly make a pointer iterator out of it // save_iterator(os, ws.data(), ws.data() + std::wcslen(ws.data())); save_iterator(os, ws.data(), ws.data() + ws.size()); } #endif #ifndef BOOST_NO_INTRINSIC_WCHAR_T template BOOST_ARCHIVE_DECL void xml_oarchive_impl::save(const wchar_t * ws){ save_iterator(os, ws, ws + std::wcslen(ws)); } #endif #endif // BOOST_NO_CWCHAR template BOOST_ARCHIVE_DECL void xml_oarchive_impl::save(const std::string & s){ // at least one library doesn't typedef value_type for strings // so rather than using string directly make a pointer iterator out of it typedef lslboost::archive::iterators::xml_escape< const char * > xml_escape_translator; std::copy( xml_escape_translator(s.data()), xml_escape_translator(s.data()+ s.size()), lslboost::archive::iterators::ostream_iterator(os) ); } template BOOST_ARCHIVE_DECL void xml_oarchive_impl::save(const char * s){ typedef lslboost::archive::iterators::xml_escape< const char * > xml_escape_translator; std::copy( xml_escape_translator(s), xml_escape_translator(s + std::strlen(s)), lslboost::archive::iterators::ostream_iterator(os) ); } template BOOST_ARCHIVE_DECL xml_oarchive_impl::xml_oarchive_impl( std::ostream & os_, unsigned int flags ) : basic_text_oprimitive( os_, 0 != (flags & no_codecvt) ), basic_xml_oarchive(flags) { if(0 == (flags & no_header)) this->init(); } template BOOST_ARCHIVE_DECL void xml_oarchive_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; } template BOOST_ARCHIVE_DECL xml_oarchive_impl::~xml_oarchive_impl(){ if(std::uncaught_exception()) return; if(0 == (this->get_flags() & no_header)) this->windup(); } } // namespace archive } // namespace lslboost