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 <locale>
28 #include <cstddef> // size_t
29 
30 #include <boost/config.hpp>
31 #if defined(BOOST_NO_STDC_NAMESPACE)
32 namespace std{
33     using ::size_t;
34     #if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT)
35         using ::locale;
36     #endif
37 } // namespace std
38 #endif
39 
40 #include <boost/io/ios_state.hpp>
41 #include <boost/static_assert.hpp>
42 
43 #include <boost/detail/workaround.hpp>
44 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
45 #include <boost/archive/dinkumware.hpp>
46 #endif
47 #include <boost/serialization/throw_exception.hpp>
48 #include <boost/archive/codecvt_null.hpp>
49 #include <boost/archive/archive_exception.hpp>
50 #include <boost/archive/basic_streambuf_locale_saver.hpp>
51 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
52 
53 namespace boost {
54 namespace archive {
55 
56 /////////////////////////////////////////////////////////////////////////
57 // class basic_text_iarchive - load serialized objects from a input text stream
58 #if defined(_MSC_VER)
59 #pragma warning( push )
60 #pragma warning( disable : 4244 4267 )
61 #endif
62 
63 template<class IStream>
64 class BOOST_SYMBOL_VISIBLE basic_text_iprimitive {
65 protected:
66     IStream &is;
67     io::ios_flags_saver flags_saver;
68     io::ios_precision_saver precision_saver;
69 
70     #ifndef BOOST_NO_STD_LOCALE
71     // note order! - if you change this, libstd++ will fail!
72     // a) create new locale with new codecvt facet
73     // b) save current locale
74     // c) change locale to new one
75     // d) use stream buffer
76     // e) change locale back to original
77     // f) destroy new codecvt facet
78     boost::archive::codecvt_null<typename IStream::char_type> codecvt_null_facet;
79     std::locale archive_locale;
80     basic_istream_locale_saver<
81         typename IStream::char_type,
82         typename IStream::traits_type
83     > locale_saver;
84     #endif
85 
86     template<class T>
load(T & t)87     void load(T & t)
88     {
89         if(is >> t)
90             return;
91         boost::serialization::throw_exception(
92             archive_exception(archive_exception::input_stream_error)
93         );
94     }
95 
load(char & t)96     void load(char & t)
97     {
98         short int i;
99         load(i);
100         t = i;
101     }
load(signed char & t)102     void load(signed char & t)
103     {
104         short int i;
105         load(i);
106         t = i;
107     }
load(unsigned char & t)108     void load(unsigned char & t)
109     {
110         unsigned short int i;
111         load(i);
112         t = i;
113     }
114 
115     #ifndef BOOST_NO_INTRINSIC_WCHAR_T
load(wchar_t & t)116     void load(wchar_t & t)
117     {
118         BOOST_STATIC_ASSERT(sizeof(wchar_t) <= sizeof(int));
119         int i;
120         load(i);
121         t = i;
122     }
123     #endif
124     BOOST_ARCHIVE_OR_WARCHIVE_DECL
125     basic_text_iprimitive(IStream  &is, bool no_codecvt);
126     BOOST_ARCHIVE_OR_WARCHIVE_DECL
127     ~basic_text_iprimitive();
128 public:
129     BOOST_ARCHIVE_OR_WARCHIVE_DECL void
130     load_binary(void *address, std::size_t count);
131 };
132 
133 #if defined(_MSC_VER)
134 #pragma warning( pop )
135 #endif
136 
137 } // namespace archive
138 } // namespace boost
139 
140 #include <boost/archive/detail/abi_suffix.hpp> // pop pragmas
141 
142 #endif // BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP
143