Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/archive/basic_text_oprimitive.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
1 #ifndef BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP | 1 #ifndef BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP |
2 #define BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP | 2 #define BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP |
3 | 3 |
4 // MS compatible compilers support #pragma once | 4 // MS compatible compilers support #pragma once |
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020) | 5 #if defined(_MSC_VER) |
6 # pragma once | 6 # pragma once |
7 #endif | 7 #endif |
8 | 8 |
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | 9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
10 // basic_text_oprimitive.hpp | 10 // basic_text_oprimitive.hpp |
24 // in such cases. So we can't use basic_ostream<OStream::char_type> but rather | 24 // in such cases. So we can't use basic_ostream<OStream::char_type> but rather |
25 // use two template parameters | 25 // use two template parameters |
26 | 26 |
27 #include <iomanip> | 27 #include <iomanip> |
28 #include <locale> | 28 #include <locale> |
29 #include <boost/config/no_tr1/cmath.hpp> // isnan | |
30 #include <boost/assert.hpp> | 29 #include <boost/assert.hpp> |
31 #include <cstddef> // size_t | 30 #include <cstddef> // size_t |
32 | 31 |
33 #include <boost/config.hpp> | 32 #include <boost/config.hpp> |
34 #include <boost/static_assert.hpp> | 33 #include <boost/static_assert.hpp> |
35 #include <boost/detail/workaround.hpp> | 34 #include <boost/detail/workaround.hpp> |
35 #include <boost/io/ios_state.hpp> | |
36 | |
36 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) | 37 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) |
37 #include <boost/archive/dinkumware.hpp> | 38 #include <boost/archive/dinkumware.hpp> |
38 #endif | 39 #endif |
39 | 40 |
40 #if defined(BOOST_NO_STDC_NAMESPACE) | 41 #if defined(BOOST_NO_STDC_NAMESPACE) |
44 using ::locale; | 45 using ::locale; |
45 #endif | 46 #endif |
46 } // namespace std | 47 } // namespace std |
47 #endif | 48 #endif |
48 | 49 |
50 #include <boost/type_traits/is_floating_point.hpp> | |
51 #include <boost/mpl/bool.hpp> | |
49 #include <boost/limits.hpp> | 52 #include <boost/limits.hpp> |
50 #include <boost/integer.hpp> | 53 #include <boost/integer.hpp> |
51 #include <boost/io/ios_state.hpp> | 54 #include <boost/io/ios_state.hpp> |
52 #include <boost/scoped_ptr.hpp> | 55 #include <boost/scoped_ptr.hpp> |
53 #include <boost/serialization/throw_exception.hpp> | 56 #include <boost/serialization/throw_exception.hpp> |
56 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header | 59 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header |
57 | 60 |
58 namespace boost { | 61 namespace boost { |
59 namespace archive { | 62 namespace archive { |
60 | 63 |
61 class save_access; | |
62 | |
63 ///////////////////////////////////////////////////////////////////////// | 64 ///////////////////////////////////////////////////////////////////////// |
64 // class basic_text_oprimitive - output of prmitives to stream | 65 // class basic_text_oprimitive - output of prmitives to stream |
65 template<class OStream> | 66 template<class OStream> |
66 class basic_text_oprimitive | 67 class basic_text_oprimitive |
67 { | 68 { |
68 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS | |
69 protected: | 69 protected: |
70 #else | |
71 public: | |
72 #endif | |
73 OStream &os; | 70 OStream &os; |
74 io::ios_flags_saver flags_saver; | 71 io::ios_flags_saver flags_saver; |
75 io::ios_precision_saver precision_saver; | 72 io::ios_precision_saver precision_saver; |
76 | 73 |
77 #ifndef BOOST_NO_STD_LOCALE | 74 #ifndef BOOST_NO_STD_LOCALE |
78 boost::scoped_ptr<std::locale> archive_locale; | 75 boost::scoped_ptr<std::locale> archive_locale; |
79 basic_streambuf_locale_saver< | 76 basic_streambuf_locale_saver< |
80 BOOST_DEDUCED_TYPENAME OStream::char_type, | 77 typename OStream::char_type, |
81 BOOST_DEDUCED_TYPENAME OStream::traits_type | 78 typename OStream::traits_type |
82 > locale_saver; | 79 > locale_saver; |
83 #endif | 80 #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 | 81 |
95 ///////////////////////////////////////////////////////// | 82 ///////////////////////////////////////////////////////// |
96 // fundamental types that need special treatment | 83 // fundamental types that need special treatment |
97 void save(const bool t){ | 84 void save(const bool t){ |
98 // trap usage of invalid uninitialized boolean which would | 85 // trap usage of invalid uninitialized boolean which would |
121 { | 108 { |
122 BOOST_STATIC_ASSERT(sizeof(wchar_t) <= sizeof(int)); | 109 BOOST_STATIC_ASSERT(sizeof(wchar_t) <= sizeof(int)); |
123 save(static_cast<int>(t)); | 110 save(static_cast<int>(t)); |
124 } | 111 } |
125 #endif | 112 #endif |
126 void save(const float t) | 113 |
127 { | 114 ///////////////////////////////////////////////////////// |
115 // saving of any types not listed above | |
116 | |
117 template<class T> | |
118 void save_impl(const T &t, boost::mpl::bool_<false> &){ | |
119 if(os.fail()) | |
120 boost::serialization::throw_exception( | |
121 archive_exception(archive_exception::output_stream_error) | |
122 ); | |
123 os << t; | |
124 } | |
125 | |
126 ///////////////////////////////////////////////////////// | |
127 // floating point types need even more special treatment | |
128 // the following determines whether the type T is some sort | |
129 // of floating point type. Note that we then assume that | |
130 // the stream << operator is defined on that type - if not | |
131 // we'll get a compile time error. This is meant to automatically | |
132 // support synthesized types which support floating point | |
133 // operations. Also it should handle compiler dependent types | |
134 // such long double. Due to John Maddock. | |
135 | |
136 template<class T> | |
137 struct is_float { | |
138 typedef typename mpl::bool_< | |
139 boost::is_floating_point<T>::value | |
140 || (std::numeric_limits<T>::is_specialized | |
141 && !std::numeric_limits<T>::is_integer | |
142 && !std::numeric_limits<T>::is_exact | |
143 && std::numeric_limits<T>::max_exponent) | |
144 >::type type; | |
145 }; | |
146 | |
147 template<class T> | |
148 void save_impl(const T &t, boost::mpl::bool_<true> &){ | |
128 // must be a user mistake - can't serialize un-initialized data | 149 // must be a user mistake - can't serialize un-initialized data |
129 if(os.fail()) | 150 if(os.fail()) |
130 boost::serialization::throw_exception( | 151 boost::serialization::throw_exception( |
131 archive_exception(archive_exception::output_stream_error) | 152 archive_exception(archive_exception::output_stream_error) |
132 ); | 153 ); |
133 os << std::setprecision(std::numeric_limits<float>::digits10 + 2); | 154 // The formulae for the number of decimla digits required is given in |
134 os << t; | 155 // http://www2.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf |
135 } | 156 // which is derived from Kahan's paper: |
136 void save(const double t) | 157 // www.eecs.berkeley.edu/~wkahan/ieee754status/ieee754.ps |
137 { | 158 // const unsigned int digits = (std::numeric_limits<T>::digits * 3010) / 10000; |
138 // must be a user mistake - can't serialize un-initialized data | 159 // note: I've commented out the above because I didn't get good results. e.g. |
139 if(os.fail()) | 160 // in one case I got a difference of 19 units. |
140 boost::serialization::throw_exception( | 161 #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS |
141 archive_exception(archive_exception::output_stream_error) | 162 const unsigned int digits = std::numeric_limits<T>::max_digits10; |
142 ); | 163 #else |
143 os << std::setprecision(std::numeric_limits<double>::digits10 + 2); | 164 const unsigned int digits = std::numeric_limits<T>::digits10 + 2; |
144 os << t; | 165 #endif |
145 } | 166 os << std::setprecision(digits) << std::scientific << t; |
167 } | |
168 | |
169 template<class T> | |
170 void save(const T & t){ | |
171 boost::io::ios_flags_saver fs(os); | |
172 boost::io::ios_precision_saver ps(os); | |
173 typename is_float<T>::type tf; | |
174 save_impl(t, tf); | |
175 } | |
176 | |
146 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) | 177 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) |
147 basic_text_oprimitive(OStream & os, bool no_codecvt); | 178 basic_text_oprimitive(OStream & os, bool no_codecvt); |
148 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) | 179 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) |
149 ~basic_text_oprimitive(); | 180 ~basic_text_oprimitive(); |
150 public: | 181 public: |
151 // unformatted append of one character | 182 // unformatted append of one character |
152 void put(BOOST_DEDUCED_TYPENAME OStream::char_type c){ | 183 void put(typename OStream::char_type c){ |
153 if(os.fail()) | 184 if(os.fail()) |
154 boost::serialization::throw_exception( | 185 boost::serialization::throw_exception( |
155 archive_exception(archive_exception::output_stream_error) | 186 archive_exception(archive_exception::output_stream_error) |
156 ); | 187 ); |
157 os.put(c); | 188 os.put(c); |