Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / archive / basic_binary_iprimitive.hpp @ 2486

History | View | Annotate | Download (6 kB)

1 2486 sjacqu01
#ifndef BOOST_ARCHIVE_BINARY_IPRIMITIVE_HPP
2 2486 sjacqu01
#define BOOST_ARCHIVE_BINARY_IPRIMITIVE_HPP
3 2486 sjacqu01
4 2486 sjacqu01
// MS compatible compilers support #pragma once
5 2486 sjacqu01
#if defined(_MSC_VER)
6 2486 sjacqu01
# pragma once
7 2486 sjacqu01
#endif
8 2486 sjacqu01
9 2486 sjacqu01
#if defined(_MSC_VER)
10 2486 sjacqu01
#pragma warning( disable : 4800 )
11 2486 sjacqu01
#endif
12 2486 sjacqu01
13 2486 sjacqu01
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
14 2486 sjacqu01
// basic_binary_iprimitive.hpp
15 2486 sjacqu01
//
16 2486 sjacqu01
// archives stored as native binary - this should be the fastest way
17 2486 sjacqu01
// to archive the state of a group of obects.  It makes no attempt to
18 2486 sjacqu01
// convert to any canonical form.
19 2486 sjacqu01
20 2486 sjacqu01
// IN GENERAL, ARCHIVES CREATED WITH THIS CLASS WILL NOT BE READABLE
21 2486 sjacqu01
// ON PLATFORM APART FROM THE ONE THEY ARE CREATED ON
22 2486 sjacqu01
23 2486 sjacqu01
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
24 2486 sjacqu01
// Use, modification and distribution is subject to the Boost Software
25 2486 sjacqu01
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
26 2486 sjacqu01
// http://www.boost.org/LICENSE_1_0.txt)
27 2486 sjacqu01
28 2486 sjacqu01
//  See http://www.boost.org for updates, documentation, and revision history.
29 2486 sjacqu01
30 2486 sjacqu01
#include <iosfwd>
31 2486 sjacqu01
#include <boost/assert.hpp>
32 2486 sjacqu01
#include <locale>
33 2486 sjacqu01
#include <cstring> // std::memcpy
34 2486 sjacqu01
#include <cstddef> // std::size_t
35 2486 sjacqu01
#include <streambuf> // basic_streambuf
36 2486 sjacqu01
#include <string>
37 2486 sjacqu01
38 2486 sjacqu01
#include <boost/config.hpp>
39 2486 sjacqu01
#if defined(BOOST_NO_STDC_NAMESPACE)
40 2486 sjacqu01
namespace std{
41 2486 sjacqu01
    using ::memcpy;
42 2486 sjacqu01
    using ::size_t;
43 2486 sjacqu01
} // namespace std
44 2486 sjacqu01
#endif
45 2486 sjacqu01
46 2486 sjacqu01
#include <boost/cstdint.hpp>
47 2486 sjacqu01
#include <boost/scoped_ptr.hpp>
48 2486 sjacqu01
#include <boost/serialization/throw_exception.hpp>
49 2486 sjacqu01
#include <boost/integer.hpp>
50 2486 sjacqu01
#include <boost/integer_traits.hpp>
51 2486 sjacqu01
52 2486 sjacqu01
#include <boost/mpl/placeholders.hpp>
53 2486 sjacqu01
#include <boost/serialization/is_bitwise_serializable.hpp>
54 2486 sjacqu01
#include <boost/serialization/array.hpp>
55 2486 sjacqu01
56 2486 sjacqu01
#include <boost/archive/basic_streambuf_locale_saver.hpp>
57 2486 sjacqu01
#include <boost/archive/archive_exception.hpp>
58 2486 sjacqu01
#include <boost/archive/detail/auto_link_archive.hpp>
59 2486 sjacqu01
#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
60 2486 sjacqu01
61 2486 sjacqu01
namespace boost {
62 2486 sjacqu01
namespace archive {
63 2486 sjacqu01
64 2486 sjacqu01
template<class Ch>
65 2486 sjacqu01
class codecvt_null;
66 2486 sjacqu01
67 2486 sjacqu01
/////////////////////////////////////////////////////////////////////////////
68 2486 sjacqu01
// class binary_iarchive - read serialized objects from a input binary stream
69 2486 sjacqu01
template<class Archive, class Elem, class Tr>
70 2486 sjacqu01
class BOOST_SYMBOL_VISIBLE basic_binary_iprimitive {
71 2486 sjacqu01
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
72 2486 sjacqu01
    friend class load_access;
73 2486 sjacqu01
protected:
74 2486 sjacqu01
#else
75 2486 sjacqu01
public:
76 2486 sjacqu01
#endif
77 2486 sjacqu01
    std::basic_streambuf<Elem, Tr> & m_sb;
78 2486 sjacqu01
    // return a pointer to the most derived class
79 2486 sjacqu01
    Archive * This(){
80 2486 sjacqu01
        return static_cast<Archive *>(this);
81 2486 sjacqu01
    }
82 2486 sjacqu01
83 2486 sjacqu01
    #ifndef BOOST_NO_STD_LOCALE
84 2486 sjacqu01
    boost::scoped_ptr<codecvt_null<Elem> > codecvt_facet;
85 2486 sjacqu01
    boost::scoped_ptr<std::locale> archive_locale;
86 2486 sjacqu01
    basic_streambuf_locale_saver<Elem, Tr> locale_saver;
87 2486 sjacqu01
    #endif
88 2486 sjacqu01
89 2486 sjacqu01
    // main template for serilization of primitive types
90 2486 sjacqu01
    template<class T>
91 2486 sjacqu01
    void load(T & t){
92 2486 sjacqu01
        load_binary(& t, sizeof(T));
93 2486 sjacqu01
    }
94 2486 sjacqu01
95 2486 sjacqu01
    /////////////////////////////////////////////////////////
96 2486 sjacqu01
    // fundamental types that need special treatment
97 2486 sjacqu01
98 2486 sjacqu01
    // trap usage of invalid uninitialized boolean
99 2486 sjacqu01
    void load(bool & t){
100 2486 sjacqu01
        load_binary(& t, sizeof(t));
101 2486 sjacqu01
        int i = t;
102 2486 sjacqu01
        BOOST_ASSERT(0 == i || 1 == i);
103 2486 sjacqu01
        (void)i; // warning suppression for release builds.
104 2486 sjacqu01
    }
105 2486 sjacqu01
    BOOST_ARCHIVE_OR_WARCHIVE_DECL void
106 2486 sjacqu01
    load(std::string &s);
107 2486 sjacqu01
    #ifndef BOOST_NO_STD_WSTRING
108 2486 sjacqu01
    BOOST_ARCHIVE_OR_WARCHIVE_DECL void
109 2486 sjacqu01
    load(std::wstring &ws);
110 2486 sjacqu01
    #endif
111 2486 sjacqu01
    BOOST_ARCHIVE_OR_WARCHIVE_DECL void
112 2486 sjacqu01
    load(char * t);
113 2486 sjacqu01
    BOOST_ARCHIVE_OR_WARCHIVE_DECL void
114 2486 sjacqu01
    load(wchar_t * t);
115 2486 sjacqu01
116 2486 sjacqu01
    BOOST_ARCHIVE_OR_WARCHIVE_DECL void
117 2486 sjacqu01
    init();
118 2486 sjacqu01
    BOOST_ARCHIVE_OR_WARCHIVE_DECL
119 2486 sjacqu01
    basic_binary_iprimitive(
120 2486 sjacqu01
        std::basic_streambuf<Elem, Tr> & sb,
121 2486 sjacqu01
        bool no_codecvt
122 2486 sjacqu01
    );
123 2486 sjacqu01
    BOOST_ARCHIVE_OR_WARCHIVE_DECL
124 2486 sjacqu01
    ~basic_binary_iprimitive();
125 2486 sjacqu01
public:
126 2486 sjacqu01
    // we provide an optimized load for all fundamental types
127 2486 sjacqu01
    // typedef serialization::is_bitwise_serializable<mpl::_1>
128 2486 sjacqu01
    // use_array_optimization;
129 2486 sjacqu01
    struct use_array_optimization {
130 2486 sjacqu01
        template <class T>
131 2486 sjacqu01
        #if defined(BOOST_NO_DEPENDENT_NESTED_DERIVATIONS)
132 2486 sjacqu01
            struct apply {
133 2486 sjacqu01
                typedef typename boost::serialization::is_bitwise_serializable< T >::type type;
134 2486 sjacqu01
            };
135 2486 sjacqu01
        #else
136 2486 sjacqu01
            struct apply : public boost::serialization::is_bitwise_serializable< T > {};
137 2486 sjacqu01
        #endif
138 2486 sjacqu01
    };
139 2486 sjacqu01
140 2486 sjacqu01
    // the optimized load_array dispatches to load_binary
141 2486 sjacqu01
    template <class ValueType>
142 2486 sjacqu01
    void load_array(serialization::array<ValueType>& a, unsigned int)
143 2486 sjacqu01
    {
144 2486 sjacqu01
      load_binary(a.address(),a.count()*sizeof(ValueType));
145 2486 sjacqu01
    }
146 2486 sjacqu01
147 2486 sjacqu01
    void
148 2486 sjacqu01
    load_binary(void *address, std::size_t count);
149 2486 sjacqu01
};
150 2486 sjacqu01
151 2486 sjacqu01
template<class Archive, class Elem, class Tr>
152 2486 sjacqu01
inline void
153 2486 sjacqu01
basic_binary_iprimitive<Archive, Elem, Tr>::load_binary(
154 2486 sjacqu01
    void *address,
155 2486 sjacqu01
    std::size_t count
156 2486 sjacqu01
){
157 2486 sjacqu01
    // note: an optimizer should eliminate the following for char files
158 2486 sjacqu01
    BOOST_ASSERT(
159 2486 sjacqu01
        static_cast<std::streamsize>(count / sizeof(Elem))
160 2486 sjacqu01
        <= boost::integer_traits<std::streamsize>::const_max
161 2486 sjacqu01
    );
162 2486 sjacqu01
    std::streamsize s = static_cast<std::streamsize>(count / sizeof(Elem));
163 2486 sjacqu01
    std::streamsize scount = m_sb.sgetn(
164 2486 sjacqu01
        static_cast<Elem *>(address),
165 2486 sjacqu01
        s
166 2486 sjacqu01
    );
167 2486 sjacqu01
    if(scount != s)
168 2486 sjacqu01
        boost::serialization::throw_exception(
169 2486 sjacqu01
            archive_exception(archive_exception::input_stream_error)
170 2486 sjacqu01
        );
171 2486 sjacqu01
    // note: an optimizer should eliminate the following for char files
172 2486 sjacqu01
    BOOST_ASSERT(count % sizeof(Elem) <= boost::integer_traits<std::streamsize>::const_max);
173 2486 sjacqu01
    s = static_cast<std::streamsize>(count % sizeof(Elem));
174 2486 sjacqu01
    if(0 < s){
175 2486 sjacqu01
//        if(is.fail())
176 2486 sjacqu01
//            boost::serialization::throw_exception(
177 2486 sjacqu01
//                archive_exception(archive_exception::stream_error)
178 2486 sjacqu01
//        );
179 2486 sjacqu01
        Elem t;
180 2486 sjacqu01
        scount = m_sb.sgetn(& t, 1);
181 2486 sjacqu01
        if(scount != 1)
182 2486 sjacqu01
            boost::serialization::throw_exception(
183 2486 sjacqu01
                archive_exception(archive_exception::input_stream_error)
184 2486 sjacqu01
            );
185 2486 sjacqu01
        std::memcpy(static_cast<char*>(address) + (count - s), &t, static_cast<std::size_t>(s));
186 2486 sjacqu01
    }
187 2486 sjacqu01
}
188 2486 sjacqu01
189 2486 sjacqu01
} // namespace archive
190 2486 sjacqu01
} // namespace boost
191 2486 sjacqu01
192 2486 sjacqu01
#include <boost/archive/detail/abi_suffix.hpp> // pop pragmas
193 2486 sjacqu01
194 2486 sjacqu01
#endif // BOOST_ARCHIVE_BINARY_IPRIMITIVE_HPP