|
1 #ifndef BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP |
|
2 #define BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP |
|
3 |
|
4 // MS compatible compilers support #pragma once |
|
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
|
6 # pragma once |
|
7 #endif |
|
8 |
|
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
|
10 // basic_text_iprimitive.hpp |
|
11 |
|
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
|
13 // Use, modification and distribution is subject to the Boost Software |
|
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|
15 // http://www.boost.org/LICENSE_1_0.txt) |
|
16 |
|
17 // See http://www.boost.org for updates, documentation, and revision history. |
|
18 |
|
19 // archives stored as text - note these ar templated on the basic |
|
20 // stream templates to accommodate wide (and other?) kind of characters |
|
21 // |
|
22 // note the fact that on libraries without wide characters, ostream is |
|
23 // is not a specialization of basic_ostream which in fact is not defined |
|
24 // in such cases. So we can't use basic_ostream<IStream::char_type> but rather |
|
25 // use two template parameters |
|
26 |
|
27 #include <cassert> |
|
28 #include <locale> |
|
29 #include <cstddef> // size_t |
|
30 |
|
31 #include <boost/config.hpp> |
|
32 #if defined(BOOST_NO_STDC_NAMESPACE) |
|
33 namespace std{ |
|
34 using ::size_t; |
|
35 #if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT) |
|
36 using ::locale; |
|
37 #endif |
|
38 } // namespace std |
|
39 #endif |
|
40 |
|
41 #include <boost/detail/workaround.hpp> |
|
42 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) |
|
43 #include <boost/archive/dinkumware.hpp> |
|
44 #endif |
|
45 |
|
46 #include <boost/throw_exception.hpp> |
|
47 #include <boost/limits.hpp> |
|
48 #include <boost/io/ios_state.hpp> |
|
49 #include <boost/scoped_ptr.hpp> |
|
50 |
|
51 #include <boost/archive/archive_exception.hpp> |
|
52 |
|
53 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header |
|
54 |
|
55 namespace boost { |
|
56 namespace archive { |
|
57 |
|
58 ///////////////////////////////////////////////////////////////////////// |
|
59 // class basic_text_iarchive - load serialized objects from a input text stream |
|
60 template<class IStream> |
|
61 class basic_text_iprimitive |
|
62 { |
|
63 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS |
|
64 protected: |
|
65 #else |
|
66 public: |
|
67 #endif |
|
68 IStream &is; |
|
69 io::ios_flags_saver flags_saver; |
|
70 io::ios_precision_saver precision_saver; |
|
71 boost::scoped_ptr<std::locale> archive_locale; |
|
72 io::basic_ios_locale_saver< |
|
73 BOOST_DEDUCED_TYPENAME IStream::char_type, BOOST_DEDUCED_TYPENAME IStream::traits_type |
|
74 > locale_saver; |
|
75 template<class T> |
|
76 void load(T & t) |
|
77 { |
|
78 if(is.fail()) |
|
79 boost::throw_exception(archive_exception(archive_exception::stream_error)); |
|
80 is >> t; |
|
81 } |
|
82 void load(unsigned char & t) |
|
83 { |
|
84 if(is.fail()) |
|
85 boost::throw_exception(archive_exception(archive_exception::stream_error)); |
|
86 unsigned short int i; |
|
87 is >> i; |
|
88 t = static_cast<unsigned char>(i); |
|
89 } |
|
90 void load(signed char & t) |
|
91 { |
|
92 if(is.fail()) |
|
93 boost::throw_exception(archive_exception(archive_exception::stream_error)); |
|
94 signed short int i; |
|
95 is >> i; |
|
96 t = static_cast<signed char>(i); |
|
97 } |
|
98 void load(char & t) |
|
99 { |
|
100 if(is.fail()) |
|
101 boost::throw_exception(archive_exception(archive_exception::stream_error)); |
|
102 short int i; |
|
103 is >> i; |
|
104 t = static_cast<char>(i); |
|
105 } |
|
106 #ifndef BOOST_NO_INTRINSIC_WCHAR_T |
|
107 void load(wchar_t & t) |
|
108 { |
|
109 if(is.fail()) |
|
110 boost::throw_exception(archive_exception(archive_exception::stream_error)); |
|
111 unsigned i; |
|
112 is >> i; |
|
113 t = static_cast<wchar_t>(i); |
|
114 } |
|
115 #endif |
|
116 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) |
|
117 basic_text_iprimitive(IStream &is, bool no_codecvt); |
|
118 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) |
|
119 ~basic_text_iprimitive(); |
|
120 public: |
|
121 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void) |
|
122 load_binary(void *address, std::size_t count); |
|
123 }; |
|
124 |
|
125 } // namespace archive |
|
126 } // namespace boost |
|
127 |
|
128 #include <boost/archive/detail/abi_suffix.hpp> // pop pragams |
|
129 |
|
130 #endif // BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP |