Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / archive / impl / basic_binary_oprimitive.ipp @ 2486

History | View | Annotate | Download (4.7 kB)

1
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2
// basic_binary_oprimitive.ipp:
3

    
4
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
5
// Use, modification and distribution is subject to the Boost Software
6
// License, Version 1.0. (See 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 <ostream>
12
#include <cstddef> // NULL
13
#include <cstring>
14

    
15
#include <boost/config.hpp>
16

    
17
#if defined(BOOST_NO_STDC_NAMESPACE) && ! defined(__LIBCOMO__)
18
namespace std{ 
19
    using ::strlen; 
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/detail/workaround.hpp>
31

    
32
#include <boost/archive/add_facet.hpp>
33
#include <boost/archive/codecvt_null.hpp>
34
#include <boost/archive/basic_binary_oprimitive.hpp>
35
#include <boost/core/no_exceptions_support.hpp>
36

    
37
namespace boost {
38
namespace archive {
39

    
40
//////////////////////////////////////////////////////////////////////
41
// implementation of basic_binary_oprimitive
42

    
43
template<class Archive, class Elem, class Tr>
44
BOOST_ARCHIVE_OR_WARCHIVE_DECL void
45
basic_binary_oprimitive<Archive, Elem, Tr>::init()
46
{
47
    // record native sizes of fundamental types
48
    // this is to permit detection of attempts to pass
49
    // native binary archives accross incompatible machines.
50
    // This is not foolproof but its better than nothing.
51
    this->This()->save(static_cast<unsigned char>(sizeof(int)));
52
    this->This()->save(static_cast<unsigned char>(sizeof(long)));
53
    this->This()->save(static_cast<unsigned char>(sizeof(float)));
54
    this->This()->save(static_cast<unsigned char>(sizeof(double)));
55
    // for checking endianness
56
    this->This()->save(int(1));
57
}
58

    
59
template<class Archive, class Elem, class Tr>
60
BOOST_ARCHIVE_OR_WARCHIVE_DECL void
61
basic_binary_oprimitive<Archive, Elem, Tr>::save(const char * s)
62
{
63
    std::size_t l = std::strlen(s);
64
    this->This()->save(l);
65
    save_binary(s, l);
66
}
67

    
68
template<class Archive, class Elem, class Tr>
69
BOOST_ARCHIVE_OR_WARCHIVE_DECL void
70
basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::string &s)
71
{
72
    std::size_t l = static_cast<std::size_t>(s.size());
73
    this->This()->save(l);
74
    save_binary(s.data(), l);
75
}
76

    
77
#ifndef BOOST_NO_CWCHAR
78
template<class Archive, class Elem, class Tr>
79
BOOST_ARCHIVE_OR_WARCHIVE_DECL void
80
basic_binary_oprimitive<Archive, Elem, Tr>::save(const wchar_t * ws)
81
{
82
    std::size_t l = std::wcslen(ws);
83
    this->This()->save(l);
84
    save_binary(ws, l * sizeof(wchar_t) / sizeof(char));
85
}
86
#endif
87

    
88
#ifndef BOOST_NO_STD_WSTRING
89
template<class Archive, class Elem, class Tr>
90
BOOST_ARCHIVE_OR_WARCHIVE_DECL void
91
basic_binary_oprimitive<Archive, Elem, Tr>::save(const std::wstring &ws)
92
{
93
    std::size_t l = ws.size();
94
    this->This()->save(l);
95
    save_binary(ws.data(), l * sizeof(wchar_t) / sizeof(char));
96
}
97
#endif
98

    
99
template<class Archive, class Elem, class Tr>
100
BOOST_ARCHIVE_OR_WARCHIVE_DECL
101
basic_binary_oprimitive<Archive, Elem, Tr>::basic_binary_oprimitive(
102
    std::basic_streambuf<Elem, Tr> & sb, 
103
    bool no_codecvt
104
) : 
105
#ifndef BOOST_NO_STD_LOCALE
106
    m_sb(sb),
107
    locale_saver(m_sb)
108
{
109
    if(! no_codecvt){
110
        archive_locale.reset(
111
            add_facet(
112
                std::locale::classic(),
113
                new codecvt_null<Elem>
114
            )
115
        );
116
        //m_sb.pubimbue(* archive_locale);
117
    }
118
}
119
#else
120
    m_sb(sb)
121
{}
122
#endif
123

    
124
// some libraries including stl and libcomo fail if the
125
// buffer isn't flushed before the code_cvt facet is changed.
126
// I think this is a bug.  We explicity invoke sync to when
127
// we're done with the streambuf to work around this problem.
128
// Note that sync is a protected member of stream buff so we
129
// have to invoke it through a contrived derived class.
130
namespace detail {
131
// note: use "using" to get past msvc bug
132
using namespace std;
133
template<class Elem, class Tr>
134
class output_streambuf_access : public std::basic_streambuf<Elem, Tr> {
135
    public:
136
        virtual int sync(){
137
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
138
            return this->basic_streambuf::sync();
139
#else
140
            return this->basic_streambuf<Elem, Tr>::sync();
141
#endif
142
        }
143
};
144
} // detail
145

    
146
// scoped_ptr requires that g be a complete type at time of
147
// destruction so define destructor here rather than in the header
148
template<class Archive, class Elem, class Tr>
149
BOOST_ARCHIVE_OR_WARCHIVE_DECL
150
basic_binary_oprimitive<Archive, Elem, Tr>::~basic_binary_oprimitive(){
151
    // flush buffer
152
    //destructor can't throw
153
    BOOST_TRY{
154
        static_cast<detail::output_streambuf_access<Elem, Tr> &>(m_sb).sync();
155
    }
156
    BOOST_CATCH(...){
157
    }
158
    BOOST_CATCH_END
159
}
160

    
161
} // namespace archive
162
} // namespace boost