Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // xml_woarchive_impl.ipp: Chris@16: Chris@16: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #include Chris@16: #ifndef BOOST_NO_STD_WSTREAMBUF Chris@16: Chris@16: #include Chris@16: #include Chris@101: #include // std::copy Chris@16: #include Chris@16: Chris@16: #include // strlen Chris@16: #include // mbtowc Chris@16: #include // wcslen Chris@16: Chris@101: #include Chris@16: #if defined(BOOST_NO_STDC_NAMESPACE) Chris@16: namespace std{ Chris@16: using ::strlen; Chris@16: #if ! defined(BOOST_NO_INTRINSIC_WCHAR_T) Chris@16: using ::mbtowc; Chris@16: using ::wcslen; Chris@16: #endif Chris@16: } // namespace std Chris@16: #endif Chris@16: Chris@101: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace archive { Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // implemenations of functions specific to wide char archives Chris@16: Chris@16: // copy chars to output escaping to xml and widening characters as we go Chris@16: template Chris@16: void save_iterator(std::wostream &os, InputIterator begin, InputIterator end){ Chris@16: typedef iterators::wchar_from_mb< Chris@16: iterators::xml_escape Chris@16: > xmbtows; Chris@16: std::copy( Chris@16: xmbtows(BOOST_MAKE_PFTO_WRAPPER(begin)), Chris@16: xmbtows(BOOST_MAKE_PFTO_WRAPPER(end)), Chris@16: boost::archive::iterators::ostream_iterator(os) Chris@16: ); Chris@16: } Chris@16: Chris@16: template Chris@16: BOOST_WARCHIVE_DECL(void) Chris@16: xml_woarchive_impl::save(const std::string & s){ Chris@16: // note: we don't use s.begin() and s.end() because dinkumware Chris@16: // doesn't have string::value_type defined. So use a wrapper Chris@16: // around these values to implement the definitions. Chris@16: const char * begin = s.data(); Chris@16: const char * end = begin + s.size(); Chris@16: save_iterator(os, begin, end); Chris@16: } Chris@16: Chris@16: #ifndef BOOST_NO_STD_WSTRING Chris@16: template Chris@16: BOOST_WARCHIVE_DECL(void) Chris@16: xml_woarchive_impl::save(const std::wstring & ws){ Chris@16: #if 0 Chris@16: typedef iterators::xml_escape xmbtows; Chris@16: std::copy( Chris@16: xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws.begin())), Chris@16: xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws.end())), Chris@16: boost::archive::iterators::ostream_iterator(os) Chris@16: ); Chris@16: #endif Chris@16: typedef iterators::xml_escape xmbtows; Chris@16: std::copy( Chris@16: xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws.data())), Chris@16: xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws.data() + ws.size())), Chris@16: boost::archive::iterators::ostream_iterator(os) Chris@16: ); Chris@16: } Chris@16: #endif //BOOST_NO_STD_WSTRING Chris@16: Chris@16: template Chris@16: BOOST_WARCHIVE_DECL(void) Chris@16: xml_woarchive_impl::save(const char * s){ Chris@16: save_iterator(os, s, s + std::strlen(s)); Chris@16: } Chris@16: Chris@16: #ifndef BOOST_NO_INTRINSIC_WCHAR_T Chris@16: template Chris@16: BOOST_WARCHIVE_DECL(void) Chris@16: xml_woarchive_impl::save(const wchar_t * ws){ Chris@16: os << ws; Chris@16: typedef iterators::xml_escape xmbtows; Chris@16: std::copy( Chris@16: xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws)), Chris@16: xmbtows(BOOST_MAKE_PFTO_WRAPPER(ws + std::wcslen(ws))), Chris@16: boost::archive::iterators::ostream_iterator(os) Chris@16: ); Chris@16: } Chris@16: #endif Chris@16: Chris@16: template Chris@16: BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY()) Chris@16: xml_woarchive_impl::xml_woarchive_impl( Chris@16: std::wostream & os_, Chris@16: unsigned int flags Chris@16: ) : Chris@16: basic_text_oprimitive( Chris@16: os_, Chris@16: true // don't change the codecvt - use the one below Chris@16: ), Chris@16: basic_xml_oarchive(flags) Chris@16: { Chris@16: // Standard behavior is that imbue can be called Chris@16: // a) before output is invoked or Chris@16: // b) after flush has been called. This prevents one-to-many Chris@16: // transforms (such as one to many transforms from getting Chris@101: // mixed up. Chris@16: if(0 == (flags & no_codecvt)){ Chris@101: archive_locale.reset( Chris@101: add_facet( Chris@101: os_.getloc(), Chris@101: new boost::archive::detail::utf8_codecvt_facet Chris@101: ) Chris@101: ); Chris@101: //os.imbue(* archive_locale); Chris@16: } Chris@16: if(0 == (flags & no_header)) Chris@16: this->init(); Chris@16: } Chris@16: Chris@101: template Chris@101: BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY()) Chris@101: xml_woarchive_impl::~xml_woarchive_impl(){ Chris@101: } Chris@101: Chris@16: } // namespace archive Chris@16: } // namespace boost Chris@16: Chris@16: #endif //BOOST_NO_STD_WSTREAMBUF