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