source: NonGTP/Boost/boost/archive/impl/text_wiarchive_impl.ipp @ 857

Revision 857, 2.9 KB checked in by igarcia, 19 years ago (diff)
Line 
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)
15namespace 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
25namespace boost {
26namespace archive {
27
28//////////////////////////////////////////////////////////////////////
29// implementation of wiprimtives functions
30//
31template<class Archive>
32BOOST_WARCHIVE_DECL(void)
33text_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
45template<class Archive>
46BOOST_WARCHIVE_DECL(void)
47text_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
65template<class Archive>
66BOOST_WARCHIVE_DECL(void)
67text_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
80template<class Archive>
81BOOST_WARCHIVE_DECL(void)
82text_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
99template<class Archive>
100BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY())
101text_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
Note: See TracBrowser for help on using the repository browser.