source: NonGTP/Boost/boost/archive/basic_text_oprimitive.hpp @ 857

Revision 857, 5.0 KB checked in by igarcia, 18 years ago (diff)
Line 
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 <boost/config.hpp>
28#include <boost/detail/workaround.hpp>
29#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
30#include <boost/archive/dinkumware.hpp>
31#endif
32
33#include <iomanip>
34#include <locale>
35#include <cstddef> // size_t
36
37#if defined(BOOST_NO_STDC_NAMESPACE)
38namespace std{
39    using ::size_t;
40    #if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT)
41        using ::locale;
42    #endif
43} // namespace std
44#endif
45
46#include <boost/limits.hpp>
47#include <boost/io/ios_state.hpp>
48#include <boost/scoped_ptr.hpp>
49#include <boost/throw_exception.hpp>
50#include <boost/archive/archive_exception.hpp>
51
52#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
53
54namespace boost {
55namespace archive {
56
57class save_access;
58
59/////////////////////////////////////////////////////////////////////////
60// class basic_text_oprimitive - output of prmitives to stream
61template<class OStream>
62class basic_text_oprimitive
63{
64#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
65protected:
66#else
67public:
68#endif
69    OStream &os;
70    io::ios_flags_saver flags_saver;
71    io::ios_precision_saver precision_saver;
72    boost::scoped_ptr<std::locale> archive_locale;
73    io::basic_ios_locale_saver<
74        BOOST_DEDUCED_TYPENAME OStream::char_type, BOOST_DEDUCED_TYPENAME OStream::traits_type
75    > locale_saver;
76
77    // default saving of primitives.
78    template<class T>
79    void save(const T &t){
80        if(os.fail())
81            boost::throw_exception(archive_exception(archive_exception::stream_error));
82        os << t;
83    }
84
85    /////////////////////////////////////////////////////////
86    // fundamental types that need special treatment
87    void save(const signed char t)
88    {
89        if(os.fail())
90            boost::throw_exception(archive_exception(archive_exception::stream_error));
91        os << static_cast<short int>(t);
92    }
93    void save(const unsigned char t)
94    {
95        if(os.fail())
96            boost::throw_exception(archive_exception(archive_exception::stream_error));
97        os << static_cast<short unsigned int>(t);
98    }
99    void save(const char t)
100    {
101        if(os.fail())
102            boost::throw_exception(archive_exception(archive_exception::stream_error));
103        os << static_cast<short int>(t);
104    }
105    #ifndef BOOST_NO_INTRINSIC_WCHAR_T
106    void save(const wchar_t t)
107    {
108        if(os.fail())
109            boost::throw_exception(archive_exception(archive_exception::stream_error));
110        os << static_cast<int>(t);
111    }
112    #endif
113    void save(const float t)
114    {
115        if(os.fail())
116            boost::throw_exception(archive_exception(archive_exception::stream_error));
117        os << std::setprecision(std::numeric_limits<float>::digits10 + 2);
118        os << t;
119    }
120    void save(const double t)
121    {
122        if(os.fail())
123            boost::throw_exception(archive_exception(archive_exception::stream_error));
124        os << std::setprecision(std::numeric_limits<double>::digits10 + 2);
125        os << t;
126    }
127    BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
128    basic_text_oprimitive(OStream & os, bool no_codecvt);
129    BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
130    ~basic_text_oprimitive();
131public:
132    // unformatted append of one character
133    void put(int c){
134        if(os.fail())
135            boost::throw_exception(archive_exception(archive_exception::stream_error));
136        os.put(c);
137    }
138    // unformatted append of null terminated string
139    void put(const char * s){
140        if(os.fail())
141            boost::throw_exception(archive_exception(archive_exception::stream_error));
142        while('\0' != *s)
143            os.put(*s++);
144    }
145    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
146    save_binary(const void *address, std::size_t count);
147};
148
149} //namespace boost
150} //namespace archive
151
152#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
153
154#endif // BOOST_ARCHIVE_BASIC_TEXT_OPRIMITIVE_HPP
Note: See TracBrowser for help on using the repository browser.