1 #ifndef BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP
2 #define BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // basic_text_oprimitive.hpp
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)
17 // See http://www.boost.org for updates, documentation, and revision history.
19 // archives stored as text - note these ar templated on the basic
20 // stream templates to accommodate wide (and other?) kind of characters
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
29 #include <boost/config/no_tr1/cmath.hpp> // isnan
31 #include <cstddef> // size_t
33 #include <boost/config.hpp>
34 #include <boost/detail/workaround.hpp>
35 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
36 #include <boost/archive/dinkumware.hpp>
39 #if defined(BOOST_NO_STDC_NAMESPACE)
42 #if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT)
48 #include <boost/limits.hpp>
49 #include <boost/io/ios_state.hpp>
50 #include <boost/scoped_ptr.hpp>
51 #include <boost/serialization/throw_exception.hpp>
53 #include <boost/archive/archive_exception.hpp>
55 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
62 /////////////////////////////////////////////////////////////////////////
63 // class basic_text_oprimitive - output of prmitives to stream
64 template<class OStream
>
65 class basic_text_oprimitive
67 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
73 io::ios_flags_saver flags_saver
;
74 io::ios_precision_saver precision_saver
;
76 #ifndef BOOST_NO_STD_LOCALE
77 boost::scoped_ptr
<std::locale
> archive_locale
;
78 io::basic_ios_locale_saver
<
79 BOOST_DEDUCED_TYPENAME
OStream::char_type
, BOOST_DEDUCED_TYPENAME
OStream::traits_type
83 // default saving of primitives.
85 void save(const T
&t
){
87 boost::serialization::throw_exception(
88 archive_exception(archive_exception::stream_error
)
93 /////////////////////////////////////////////////////////
94 // fundamental types that need special treatment
95 void save(const bool t
){
96 // trap usage of invalid uninitialized boolean which would
97 // otherwise crash on load.
98 assert(0 == static_cast<int>(t
) || 1 == static_cast<int>(t
));
100 boost::serialization::throw_exception(
101 archive_exception(archive_exception::stream_error
)
105 void save(const signed char t
)
108 boost::serialization::throw_exception(
109 archive_exception(archive_exception::stream_error
)
111 os
<< static_cast<short int>(t
);
113 void save(const unsigned char t
)
116 boost::serialization::throw_exception(
117 archive_exception(archive_exception::stream_error
)
119 os
<< static_cast<short unsigned int>(t
);
121 void save(const char t
)
124 boost::serialization::throw_exception(
125 archive_exception(archive_exception::stream_error
)
127 os
<< static_cast<short int>(t
);
129 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
130 void save(const wchar_t t
)
133 boost::serialization::throw_exception(
134 archive_exception(archive_exception::stream_error
)
136 os
<< static_cast<int>(t
);
139 void save(const float t
)
141 // must be a user mistake - can't serialize un-initialized data
143 boost::serialization::throw_exception(
144 archive_exception(archive_exception::stream_error
)
146 os
<< std::setprecision(std::numeric_limits
<float>::digits10
+ 2);
149 void save(const double t
)
151 // must be a user mistake - can't serialize un-initialized data
153 boost::serialization::throw_exception(
154 archive_exception(archive_exception::stream_error
)
156 os
<< std::setprecision(std::numeric_limits
<double>::digits10
+ 2);
159 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
160 basic_text_oprimitive(OStream
& os
, bool no_codecvt
);
161 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
162 ~basic_text_oprimitive();
164 // unformatted append of one character
167 boost::serialization::throw_exception(
168 archive_exception(archive_exception::stream_error
)
172 // unformatted append of null terminated string
173 void put(const char * s
){
175 boost::serialization::throw_exception(
176 archive_exception(archive_exception::stream_error
)
181 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
182 save_binary(const void *address
, std::size_t count
);
186 } //namespace archive
188 #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
190 #endif // BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP