author | William Roberts <williamr@symbian.org> |
Tue, 16 Mar 2010 16:12:26 +0000 | |
branch | Symbian2 |
changeset 2 | 2fe1408b6811 |
permissions | -rw-r--r-- |
williamr@2 | 1 |
#ifndef BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP |
williamr@2 | 2 |
#define BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP |
williamr@2 | 3 |
|
williamr@2 | 4 |
// MS compatible compilers support #pragma once |
williamr@2 | 5 |
#if defined(_MSC_VER) && (_MSC_VER >= 1020) |
williamr@2 | 6 |
# pragma once |
williamr@2 | 7 |
#endif |
williamr@2 | 8 |
|
williamr@2 | 9 |
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
williamr@2 | 10 |
// basic_text_oprimitive.hpp |
williamr@2 | 11 |
|
williamr@2 | 12 |
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
williamr@2 | 13 |
// Use, modification and distribution is subject to the Boost Software |
williamr@2 | 14 |
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
williamr@2 | 15 |
// http://www.boost.org/LICENSE_1_0.txt) |
williamr@2 | 16 |
|
williamr@2 | 17 |
// See http://www.boost.org for updates, documentation, and revision history. |
williamr@2 | 18 |
|
williamr@2 | 19 |
// archives stored as text - note these ar templated on the basic |
williamr@2 | 20 |
// stream templates to accommodate wide (and other?) kind of characters |
williamr@2 | 21 |
// |
williamr@2 | 22 |
// note the fact that on libraries without wide characters, ostream is |
williamr@2 | 23 |
// is not a specialization of basic_ostream which in fact is not defined |
williamr@2 | 24 |
// in such cases. So we can't use basic_ostream<OStream::char_type> but rather |
williamr@2 | 25 |
// use two template parameters |
williamr@2 | 26 |
|
williamr@2 | 27 |
#include <iomanip> |
williamr@2 | 28 |
#include <locale> |
williamr@2 | 29 |
#include <cstddef> // size_t |
williamr@2 | 30 |
#include <cmath> // isnan |
williamr@2 | 31 |
#include <cassert> |
williamr@2 | 32 |
|
williamr@2 | 33 |
#include <boost/config.hpp> |
williamr@2 | 34 |
#include <boost/detail/workaround.hpp> |
williamr@2 | 35 |
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) |
williamr@2 | 36 |
#include <boost/archive/dinkumware.hpp> |
williamr@2 | 37 |
#endif |
williamr@2 | 38 |
|
williamr@2 | 39 |
#if defined(BOOST_NO_STDC_NAMESPACE) |
williamr@2 | 40 |
namespace std{ |
williamr@2 | 41 |
using ::size_t; |
williamr@2 | 42 |
#if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT) |
williamr@2 | 43 |
using ::locale; |
williamr@2 | 44 |
#endif |
williamr@2 | 45 |
} // namespace std |
williamr@2 | 46 |
#endif |
williamr@2 | 47 |
|
williamr@2 | 48 |
#include <boost/limits.hpp> |
williamr@2 | 49 |
#include <boost/io/ios_state.hpp> |
williamr@2 | 50 |
#include <boost/scoped_ptr.hpp> |
williamr@2 | 51 |
#include <boost/throw_exception.hpp> |
williamr@2 | 52 |
#include <boost/archive/archive_exception.hpp> |
williamr@2 | 53 |
|
williamr@2 | 54 |
#include <boost/archive/detail/abi_prefix.hpp> // must be the last header |
williamr@2 | 55 |
|
williamr@2 | 56 |
namespace boost { |
williamr@2 | 57 |
namespace archive { |
williamr@2 | 58 |
|
williamr@2 | 59 |
class save_access; |
williamr@2 | 60 |
|
williamr@2 | 61 |
///////////////////////////////////////////////////////////////////////// |
williamr@2 | 62 |
// class basic_text_oprimitive - output of prmitives to stream |
williamr@2 | 63 |
template<class OStream> |
williamr@2 | 64 |
class basic_text_oprimitive |
williamr@2 | 65 |
{ |
williamr@2 | 66 |
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS |
williamr@2 | 67 |
protected: |
williamr@2 | 68 |
#else |
williamr@2 | 69 |
public: |
williamr@2 | 70 |
#endif |
williamr@2 | 71 |
OStream &os; |
williamr@2 | 72 |
io::ios_flags_saver flags_saver; |
williamr@2 | 73 |
io::ios_precision_saver precision_saver; |
williamr@2 | 74 |
boost::scoped_ptr<std::locale> archive_locale; |
williamr@2 | 75 |
io::basic_ios_locale_saver< |
williamr@2 | 76 |
BOOST_DEDUCED_TYPENAME OStream::char_type, BOOST_DEDUCED_TYPENAME OStream::traits_type |
williamr@2 | 77 |
> locale_saver; |
williamr@2 | 78 |
|
williamr@2 | 79 |
// default saving of primitives. |
williamr@2 | 80 |
template<class T> |
williamr@2 | 81 |
void save(const T &t){ |
williamr@2 | 82 |
if(os.fail()) |
williamr@2 | 83 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 84 |
os << t; |
williamr@2 | 85 |
} |
williamr@2 | 86 |
|
williamr@2 | 87 |
///////////////////////////////////////////////////////// |
williamr@2 | 88 |
// fundamental types that need special treatment |
williamr@2 | 89 |
void save(const bool t){ |
williamr@2 | 90 |
// trap usage of invalid uninitialized boolean which would |
williamr@2 | 91 |
// otherwise crash on load. |
williamr@2 | 92 |
int i = t; |
williamr@2 | 93 |
assert(0 == i || 1 == i); |
williamr@2 | 94 |
if(os.fail()) |
williamr@2 | 95 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 96 |
os << t; |
williamr@2 | 97 |
} |
williamr@2 | 98 |
void save(const signed char t) |
williamr@2 | 99 |
{ |
williamr@2 | 100 |
if(os.fail()) |
williamr@2 | 101 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 102 |
os << static_cast<short int>(t); |
williamr@2 | 103 |
} |
williamr@2 | 104 |
void save(const unsigned char t) |
williamr@2 | 105 |
{ |
williamr@2 | 106 |
if(os.fail()) |
williamr@2 | 107 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 108 |
os << static_cast<short unsigned int>(t); |
williamr@2 | 109 |
} |
williamr@2 | 110 |
void save(const char t) |
williamr@2 | 111 |
{ |
williamr@2 | 112 |
if(os.fail()) |
williamr@2 | 113 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 114 |
os << static_cast<short int>(t); |
williamr@2 | 115 |
} |
williamr@2 | 116 |
#ifndef BOOST_NO_INTRINSIC_WCHAR_T |
williamr@2 | 117 |
void save(const wchar_t t) |
williamr@2 | 118 |
{ |
williamr@2 | 119 |
if(os.fail()) |
williamr@2 | 120 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 121 |
os << static_cast<int>(t); |
williamr@2 | 122 |
} |
williamr@2 | 123 |
#endif |
williamr@2 | 124 |
void save(const float t) |
williamr@2 | 125 |
{ |
williamr@2 | 126 |
// must be a user mistake - can't serialize un-initialized data |
williamr@2 | 127 |
if(os.fail()) |
williamr@2 | 128 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 129 |
os << std::setprecision(std::numeric_limits<float>::digits10 + 2); |
williamr@2 | 130 |
os << t; |
williamr@2 | 131 |
} |
williamr@2 | 132 |
void save(const double t) |
williamr@2 | 133 |
{ |
williamr@2 | 134 |
// must be a user mistake - can't serialize un-initialized data |
williamr@2 | 135 |
if(os.fail()) |
williamr@2 | 136 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 137 |
os << std::setprecision(std::numeric_limits<double>::digits10 + 2); |
williamr@2 | 138 |
os << t; |
williamr@2 | 139 |
} |
williamr@2 | 140 |
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) |
williamr@2 | 141 |
basic_text_oprimitive(OStream & os, bool no_codecvt); |
williamr@2 | 142 |
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) |
williamr@2 | 143 |
~basic_text_oprimitive(); |
williamr@2 | 144 |
public: |
williamr@2 | 145 |
// unformatted append of one character |
williamr@2 | 146 |
void put(int c){ |
williamr@2 | 147 |
if(os.fail()) |
williamr@2 | 148 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 149 |
os.put(c); |
williamr@2 | 150 |
} |
williamr@2 | 151 |
// unformatted append of null terminated string |
williamr@2 | 152 |
void put(const char * s){ |
williamr@2 | 153 |
if(os.fail()) |
williamr@2 | 154 |
boost::throw_exception(archive_exception(archive_exception::stream_error)); |
williamr@2 | 155 |
while('\0' != *s) |
williamr@2 | 156 |
os.put(*s++); |
williamr@2 | 157 |
} |
williamr@2 | 158 |
BOOST_ARCHIVE_OR_WARCHIVE_DECL(void) |
williamr@2 | 159 |
save_binary(const void *address, std::size_t count); |
williamr@2 | 160 |
}; |
williamr@2 | 161 |
|
williamr@2 | 162 |
} //namespace boost |
williamr@2 | 163 |
} //namespace archive |
williamr@2 | 164 |
|
williamr@2 | 165 |
#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas |
williamr@2 | 166 |
|
williamr@2 | 167 |
#endif // BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP |