comparison DEPENDENCIES/generic/include/boost/archive/basic_text_oprimitive.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 #ifndef BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP
2 #define BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_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_oprimitive.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<OStream::char_type> but rather
25 // use two template parameters
26
27 #include <iomanip>
28 #include <locale>
29 #include <boost/config/no_tr1/cmath.hpp> // isnan
30 #include <boost/assert.hpp>
31 #include <cstddef> // size_t
32
33 #include <boost/config.hpp>
34 #include <boost/static_assert.hpp>
35 #include <boost/detail/workaround.hpp>
36 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
37 #include <boost/archive/dinkumware.hpp>
38 #endif
39
40 #if defined(BOOST_NO_STDC_NAMESPACE)
41 namespace std{
42 using ::size_t;
43 #if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT)
44 using ::locale;
45 #endif
46 } // namespace std
47 #endif
48
49 #include <boost/limits.hpp>
50 #include <boost/integer.hpp>
51 #include <boost/io/ios_state.hpp>
52 #include <boost/scoped_ptr.hpp>
53 #include <boost/serialization/throw_exception.hpp>
54 #include <boost/archive/archive_exception.hpp>
55 #include <boost/archive/basic_streambuf_locale_saver.hpp>
56 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
57
58 namespace boost {
59 namespace archive {
60
61 class save_access;
62
63 /////////////////////////////////////////////////////////////////////////
64 // class basic_text_oprimitive - output of prmitives to stream
65 template<class OStream>
66 class basic_text_oprimitive
67 {
68 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
69 protected:
70 #else
71 public:
72 #endif
73 OStream &os;
74 io::ios_flags_saver flags_saver;
75 io::ios_precision_saver precision_saver;
76
77 #ifndef BOOST_NO_STD_LOCALE
78 boost::scoped_ptr<std::locale> archive_locale;
79 basic_streambuf_locale_saver<
80 BOOST_DEDUCED_TYPENAME OStream::char_type,
81 BOOST_DEDUCED_TYPENAME OStream::traits_type
82 > locale_saver;
83 #endif
84
85 // default saving of primitives.
86 template<class T>
87 void save(const T &t){
88 if(os.fail())
89 boost::serialization::throw_exception(
90 archive_exception(archive_exception::output_stream_error)
91 );
92 os << t;
93 }
94
95 /////////////////////////////////////////////////////////
96 // fundamental types that need special treatment
97 void save(const bool t){
98 // trap usage of invalid uninitialized boolean which would
99 // otherwise crash on load.
100 BOOST_ASSERT(0 == static_cast<int>(t) || 1 == static_cast<int>(t));
101 if(os.fail())
102 boost::serialization::throw_exception(
103 archive_exception(archive_exception::output_stream_error)
104 );
105 os << t;
106 }
107 void save(const signed char t)
108 {
109 save(static_cast<short int>(t));
110 }
111 void save(const unsigned char t)
112 {
113 save(static_cast<short unsigned int>(t));
114 }
115 void save(const char t)
116 {
117 save(static_cast<short int>(t));
118 }
119 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
120 void save(const wchar_t t)
121 {
122 BOOST_STATIC_ASSERT(sizeof(wchar_t) <= sizeof(int));
123 save(static_cast<int>(t));
124 }
125 #endif
126 void save(const float t)
127 {
128 // must be a user mistake - can't serialize un-initialized data
129 if(os.fail())
130 boost::serialization::throw_exception(
131 archive_exception(archive_exception::output_stream_error)
132 );
133 os << std::setprecision(std::numeric_limits<float>::digits10 + 2);
134 os << t;
135 }
136 void save(const double t)
137 {
138 // must be a user mistake - can't serialize un-initialized data
139 if(os.fail())
140 boost::serialization::throw_exception(
141 archive_exception(archive_exception::output_stream_error)
142 );
143 os << std::setprecision(std::numeric_limits<double>::digits10 + 2);
144 os << t;
145 }
146 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
147 basic_text_oprimitive(OStream & os, bool no_codecvt);
148 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
149 ~basic_text_oprimitive();
150 public:
151 // unformatted append of one character
152 void put(BOOST_DEDUCED_TYPENAME OStream::char_type c){
153 if(os.fail())
154 boost::serialization::throw_exception(
155 archive_exception(archive_exception::output_stream_error)
156 );
157 os.put(c);
158 }
159 // unformatted append of null terminated string
160 void put(const char * s){
161 while('\0' != *s)
162 os.put(*s++);
163 }
164 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
165 save_binary(const void *address, std::size_t count);
166 };
167
168 } //namespace boost
169 } //namespace archive
170
171 #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
172
173 #endif // BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP