1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
---|
2 | // text_text_wiarchive_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 <cstddef> // size_t |
---|
12 | |
---|
13 | #include <boost/config.hpp> |
---|
14 | #if defined(BOOST_NO_STDC_NAMESPACE) |
---|
15 | namespace std{ |
---|
16 | using ::size_t; |
---|
17 | } // namespace std |
---|
18 | #endif |
---|
19 | |
---|
20 | #include <boost/detail/workaround.hpp> // fixup for RogueWave |
---|
21 | |
---|
22 | #ifndef BOOST_NO_STD_WSTREAMBUF |
---|
23 | #include <boost/archive/basic_text_iprimitive.hpp> |
---|
24 | |
---|
25 | namespace boost { |
---|
26 | namespace archive { |
---|
27 | |
---|
28 | ////////////////////////////////////////////////////////////////////// |
---|
29 | // implementation of wiprimtives functions |
---|
30 | // |
---|
31 | template<class Archive> |
---|
32 | BOOST_WARCHIVE_DECL(void) |
---|
33 | text_wiarchive_impl<Archive>::load(char *s) |
---|
34 | { |
---|
35 | std::size_t size; |
---|
36 | * this->This() >> size; |
---|
37 | // skip separating space |
---|
38 | is.get(); |
---|
39 | while(size-- > 0){ |
---|
40 | *s++ = is.narrow(is.get(), '\0'); |
---|
41 | } |
---|
42 | *s = '\0'; |
---|
43 | } |
---|
44 | |
---|
45 | template<class Archive> |
---|
46 | BOOST_WARCHIVE_DECL(void) |
---|
47 | text_wiarchive_impl<Archive>::load(std::string &s) |
---|
48 | { |
---|
49 | std::size_t size; |
---|
50 | * this->This() >> size; |
---|
51 | // skip separating space |
---|
52 | is.get(); |
---|
53 | #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101)) |
---|
54 | if(NULL != s.data()) |
---|
55 | #endif |
---|
56 | s.resize(0); |
---|
57 | s.reserve(size); |
---|
58 | while(size-- > 0){ |
---|
59 | int x = is.narrow(is.get(), '\0'); |
---|
60 | s += x; |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | #ifndef BOOST_NO_INTRINSIC_WCHAR_T |
---|
65 | template<class Archive> |
---|
66 | BOOST_WARCHIVE_DECL(void) |
---|
67 | text_wiarchive_impl<Archive>::load(wchar_t *s) |
---|
68 | { |
---|
69 | std::size_t size; |
---|
70 | * this->This() >> size; |
---|
71 | // skip separating space |
---|
72 | is.get(); |
---|
73 | // Works on all tested platforms |
---|
74 | is.read(s, size); |
---|
75 | s[size] = L'\0'; |
---|
76 | } |
---|
77 | #endif |
---|
78 | |
---|
79 | #ifndef BOOST_NO_STD_WSTRING |
---|
80 | template<class Archive> |
---|
81 | BOOST_WARCHIVE_DECL(void) |
---|
82 | text_wiarchive_impl<Archive>::load(std::wstring &ws) |
---|
83 | { |
---|
84 | std::size_t size; |
---|
85 | * this->This() >> size; |
---|
86 | // skip separating space |
---|
87 | is.get(); |
---|
88 | // borland complains about resize |
---|
89 | // borland de-allocator fixup |
---|
90 | #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101)) |
---|
91 | if(NULL != ws.data()) |
---|
92 | #endif |
---|
93 | ws.resize(size); |
---|
94 | // note breaking a rule here - is this a problem on some platform |
---|
95 | is.read(const_cast<wchar_t *>(ws.data()), size); |
---|
96 | } |
---|
97 | #endif |
---|
98 | |
---|
99 | template<class Archive> |
---|
100 | BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY()) |
---|
101 | text_wiarchive_impl<Archive>::text_wiarchive_impl( |
---|
102 | std::wistream & is, |
---|
103 | unsigned int flags |
---|
104 | ) : |
---|
105 | basic_text_iprimitive<std::wistream>( |
---|
106 | is, |
---|
107 | 0 != (flags & no_codecvt) |
---|
108 | ), |
---|
109 | basic_text_iarchive<Archive>(flags) |
---|
110 | { |
---|
111 | if(0 == (flags & no_header)) |
---|
112 | basic_text_iarchive<Archive>::init(); |
---|
113 | } |
---|
114 | |
---|
115 | } // archive |
---|
116 | } // boost |
---|
117 | |
---|
118 | #endif // BOOST_NO_STD_WSTREAMBUF |
---|