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)
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 are 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 // 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 <boost/assert.hpp>
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/limits.hpp>
47 #include <boost/io/ios_state.hpp>
48 #include <boost/scoped_ptr.hpp>
49 #include <boost/static_assert.hpp>
50 
51 #include <boost/serialization/throw_exception.hpp>
52 #include <boost/archive/archive_exception.hpp>
53 #include <boost/archive/basic_streambuf_locale_saver.hpp>
54 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
55 
56 namespace boost {
57 namespace archive {
58 
59 /////////////////////////////////////////////////////////////////////////
60 // class basic_text_iarchive - load serialized objects from a input text stream
61 #if defined(_MSC_VER)
62 #pragma warning( push )
63 #pragma warning( disable : 4244 4267 )
64 #endif
65 
66 template<class IStream>
67 class BOOST_SYMBOL_VISIBLE basic_text_iprimitive {
68 protected:
69     IStream &is;
70     io::ios_flags_saver flags_saver;
71     io::ios_precision_saver precision_saver;
72 
73     #ifndef BOOST_NO_STD_LOCALE
74     boost::scoped_ptr<std::locale> archive_locale;
75     basic_streambuf_locale_saver<
76         typename IStream::char_type,
77         typename IStream::traits_type
78     > locale_saver;
79     #endif
80 
81     template<class T>
load(T & t)82     void load(T & t)
83     {
84         if(is >> t)
85             return;
86         boost::serialization::throw_exception(
87             archive_exception(archive_exception::input_stream_error)
88         );
89     }
90 
load(char & t)91     void load(char & t)
92     {
93         short int i;
94         load(i);
95         t = i;
96     }
load(signed char & t)97     void load(signed char & t)
98     {
99         short int i;
100         load(i);
101         t = i;
102     }
load(unsigned char & t)103     void load(unsigned char & t)
104     {
105         unsigned short int i;
106         load(i);
107         t = i;
108     }
109 
110     #ifndef BOOST_NO_INTRINSIC_WCHAR_T
load(wchar_t & t)111     void load(wchar_t & t)
112     {
113         BOOST_STATIC_ASSERT(sizeof(wchar_t) <= sizeof(int));
114         int i;
115         load(i);
116         t = i;
117     }
118     #endif
119     BOOST_ARCHIVE_OR_WARCHIVE_DECL
120     basic_text_iprimitive(IStream  &is, bool no_codecvt);
121     BOOST_ARCHIVE_OR_WARCHIVE_DECL
122     ~basic_text_iprimitive();
123 public:
124     BOOST_ARCHIVE_OR_WARCHIVE_DECL void
125     load_binary(void *address, std::size_t count);
126 };
127 
128 #if defined(_MSC_VER)
129 #pragma warning( pop )
130 #endif
131 
132 } // namespace archive
133 } // namespace boost
134 
135 #include <boost/archive/detail/abi_suffix.hpp> // pop pragmas
136 
137 #endif // BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP
138