[857] | 1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
| 2 | // text_oarchive_impl.ipp:
|
---|
| 3 |
|
---|
| 4 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
---|
| 5 | // Distributed under the Boost Software License, Version 1.0. (See
|
---|
| 6 | // 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 <string>
|
---|
| 12 | #include <boost/config.hpp>
|
---|
| 13 | #include <locale>
|
---|
| 14 | #include <cstddef> // size_t
|
---|
| 15 |
|
---|
| 16 | #include <boost/config.hpp>
|
---|
| 17 | #if defined(BOOST_NO_STDC_NAMESPACE)
|
---|
| 18 | namespace std{
|
---|
| 19 | using ::size_t;
|
---|
| 20 | } // namespace std
|
---|
| 21 | #endif
|
---|
| 22 |
|
---|
| 23 | #ifndef BOOST_NO_CWCHAR
|
---|
| 24 | #include <cwchar>
|
---|
| 25 | #ifdef BOOST_NO_STDC_NAMESPACE
|
---|
| 26 | namespace std{ using ::wcslen; }
|
---|
| 27 | #endif
|
---|
| 28 | #endif
|
---|
| 29 |
|
---|
| 30 | #include <boost/archive/add_facet.hpp>
|
---|
| 31 | #include <boost/archive/text_oarchive.hpp>
|
---|
| 32 |
|
---|
| 33 | namespace boost {
|
---|
| 34 | namespace archive {
|
---|
| 35 |
|
---|
| 36 | //////////////////////////////////////////////////////////////////////
|
---|
| 37 | // implementation of basic_text_oprimitive overrides for the combination
|
---|
| 38 | // of template parameters used to create a text_oprimitive
|
---|
| 39 |
|
---|
| 40 | template<class Archive>
|
---|
| 41 | BOOST_ARCHIVE_DECL(void)
|
---|
| 42 | text_oarchive_impl<Archive>::save(const char * s)
|
---|
| 43 | {
|
---|
| 44 | const std::size_t len = std::ostream::traits_type::length(s);
|
---|
| 45 | *this->This() << len;
|
---|
| 46 | this->This()->newtoken();
|
---|
| 47 | os << s;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | template<class Archive>
|
---|
| 51 | BOOST_ARCHIVE_DECL(void)
|
---|
| 52 | text_oarchive_impl<Archive>::save(const std::string &s)
|
---|
| 53 | {
|
---|
| 54 | const std::size_t size = s.size();
|
---|
| 55 | *this->This() << size;
|
---|
| 56 | this->This()->newtoken();
|
---|
| 57 | os << s;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | #ifndef BOOST_NO_CWCHAR
|
---|
| 61 | #ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
---|
| 62 | template<class Archive>
|
---|
| 63 | BOOST_ARCHIVE_DECL(void)
|
---|
| 64 | text_oarchive_impl<Archive>::save(const wchar_t * ws)
|
---|
| 65 | {
|
---|
| 66 | const std::size_t l = std::wcslen(ws);
|
---|
| 67 | * this->This() << l;
|
---|
| 68 | this->This()->newtoken();
|
---|
| 69 | os.write((const char *)ws, l * sizeof(wchar_t)/sizeof(char));
|
---|
| 70 | }
|
---|
| 71 | #endif
|
---|
| 72 |
|
---|
| 73 | #ifndef BOOST_NO_STD_WSTRING
|
---|
| 74 | template<class Archive>
|
---|
| 75 | BOOST_ARCHIVE_DECL(void)
|
---|
| 76 | text_oarchive_impl<Archive>::save(const std::wstring &ws)
|
---|
| 77 | {
|
---|
| 78 | const std::size_t l = ws.size();
|
---|
| 79 | * this->This() << l;
|
---|
| 80 | this->This()->newtoken();
|
---|
| 81 | os.write((const char *)(ws.data()), l * sizeof(wchar_t)/sizeof(char));
|
---|
| 82 | }
|
---|
| 83 | #endif
|
---|
| 84 | #endif // BOOST_NO_CWCHAR
|
---|
| 85 |
|
---|
| 86 | template<class Archive>
|
---|
| 87 | BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
|
---|
| 88 | text_oarchive_impl<Archive>::text_oarchive_impl(
|
---|
| 89 | std::ostream & os,
|
---|
| 90 | unsigned int flags
|
---|
| 91 | ) :
|
---|
| 92 | basic_text_oprimitive<std::ostream>(
|
---|
| 93 | os,
|
---|
| 94 | 0 != (flags & no_codecvt)
|
---|
| 95 | ),
|
---|
| 96 | basic_text_oarchive<Archive>(flags)
|
---|
| 97 | {
|
---|
| 98 | if(0 == (flags & no_header))
|
---|
| 99 | #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
|
---|
| 100 | this->init();
|
---|
| 101 | #else
|
---|
| 102 | this->basic_text_oarchive<Archive>::init();
|
---|
| 103 | #endif
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | template<class Archive>
|
---|
| 107 | BOOST_ARCHIVE_DECL(void)
|
---|
| 108 | text_oarchive_impl<Archive>::save_binary(const void *address, std::size_t count){
|
---|
| 109 | put('\n');
|
---|
| 110 | this->end_preamble();
|
---|
| 111 | #if ! defined(__MWERKS__)
|
---|
| 112 | this->basic_text_oprimitive<std::ostream>::save_binary(
|
---|
| 113 | #else
|
---|
| 114 | this->basic_text_oprimitive::save_binary(
|
---|
| 115 | #endif
|
---|
| 116 | address,
|
---|
| 117 | count
|
---|
| 118 | );
|
---|
| 119 | this->delimiter = this->eol;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | } // namespace archive
|
---|
| 123 | } // namespace boost
|
---|
| 124 |
|
---|