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

Revision 857, 3.6 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]1#ifndef BOOST_ARCHIVE_BASIC_TEXT_OARCHIVE_HPP
2#define BOOST_ARCHIVE_BASIC_TEXT_OARCHIVE_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_oarchive.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 <cassert>
28#include <boost/config.hpp>
29#include <boost/pfto.hpp>
30#include <boost/detail/workaround.hpp>
31
32#include <boost/archive/detail/oserializer.hpp>
33#include <boost/archive/detail/interface_oarchive.hpp>
34#include <boost/archive/detail/common_oarchive.hpp>
35
36#include <boost/serialization/string.hpp>
37
38#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
39
40namespace boost {
41namespace archive {
42
43/////////////////////////////////////////////////////////////////////////
44// class basic_text_iarchive - read serialized objects from a input text stream
45template<class Archive>
46class basic_text_oarchive :
47    public detail::common_oarchive<Archive>
48{
49#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
50|| BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x560))
51public:
52#elif defined(BOOST_MSVC)
53    // for some inexplicable reason insertion of "class" generates compile erro
54    // on msvc 7.1
55    friend detail::interface_oarchive<Archive>;
56protected:
57#else
58    friend class detail::interface_oarchive<Archive>;
59protected:
60#endif
61    enum {
62        none,
63        eol,
64        space
65    } delimiter;
66
67    void newline(){
68        delimiter = eol;
69    }
70
71    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
72    newtoken();
73
74    // default processing - invoke serialization library
75    template<class T>
76    void save_override(T & t, BOOST_PFTO int)
77    {
78        archive::save(* this->This(), t);
79    }
80
81    // start new objects on a new line
82    void save_override(const object_id_type & t, int){
83        this->This()->newline();
84        // and and invoke prmitive to underlying value
85        this->This()->save(t.t);
86    }
87
88    void save_override(const object_reference_type & t, int){
89        this->This()->newline();
90        // and and invoke prmitive to underlying value
91        this->This()->save(t.t);
92    }
93
94    // text file don't include the optional information
95    void save_override(const class_id_optional_type & /* t */, int){}
96
97    void save_override(const class_name_type & t, int){
98                const std::string s(t);
99                * this->This() << s;
100    }
101
102    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
103    init();
104
105    basic_text_oarchive(unsigned int flags) :
106        detail::common_oarchive<Archive>(flags),
107        delimiter(none)
108    {}
109
110    ~basic_text_oarchive(){}
111};
112
113} // namespace archive
114} // namespace boost
115
116#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
117
118#endif // BOOST_ARCHIVE_BASIC_TEXT_OARCHIVE_HPP
Note: See TracBrowser for help on using the repository browser.