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

Revision 857, 4.2 KB checked in by igarcia, 18 years ago (diff)
Line 
1#ifndef BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP
2#define BOOST_ARCHIVE_BASIC_BINARY_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_binary_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 native binary - this should be the fastest way
20// to archive the state of a group of obects.  It makes no attempt to
21// convert to any canonical form.
22
23// IN GENERAL, ARCHIVES CREATED WITH THIS CLASS WILL NOT BE READABLE
24// ON PLATFORM APART FROM THE ONE THEY ARE CREATE ON
25
26#include <boost/config.hpp>
27#include <boost/pfto.hpp>
28
29#include <boost/detail/workaround.hpp>
30#include <boost/archive/detail/oserializer.hpp>
31#include <boost/archive/detail/interface_oarchive.hpp>
32#include <boost/archive/detail/common_oarchive.hpp>
33
34#include <boost/serialization/string.hpp>
35
36namespace boost {
37namespace archive {
38
39//////////////////////////////////////////////////////////////////////
40// class basic_binary_oarchive - write serialized objects to a binary output stream
41// note: this archive has no pretensions to portability.  Archive format
42// may vary across machine architectures and compilers.  About the only
43// guarentee is that an archive created with this code will be readable
44// by a program built with the same tools for the same machne.  This class
45// does have the virtue of buiding the smalles archive in the minimum amount
46// of time.  So under some circumstances it may be he right choice.
47
48/////////////////////////////////////////////////////////////////////////
49// class basic_text_iarchive - read serialized objects from a input text stream
50template<class Archive>
51class basic_binary_oarchive :
52    public detail::common_oarchive<Archive>
53{
54#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
55public:
56#elif defined(BOOST_MSVC)
57    // for some inexplicable reason insertion of "class" generates compile erro
58    // on msvc 7.1
59    friend detail::interface_oarchive<Archive>;
60protected:
61#else
62    friend class detail::interface_oarchive<Archive>;
63protected:
64#endif
65    // any datatype not specifed below will be handled
66    // by this function
67    template<class T>
68    void save_override(T & t, BOOST_PFTO int)
69    {
70        archive::save(* this->This(), t);
71    }
72    // binary files don't include the optional information
73    void save_override(const class_id_optional_type & /* t */, int){}
74
75    void save_override(const version_type & t, int){
76        // upto 255 versions
77        // note:t.t resolves borland ambguity
78        unsigned  char x = t.t;
79        * this->This() << x;
80    }
81    void save_override(const class_id_type & t, int){
82        // upto 32K classes
83        int_least16_t x = t.t;
84        * this->This() << x;
85    }
86    void save_override(const class_id_reference_type & t, int){
87        // upto 32K classes
88        int_least16_t x = t.t;
89        * this->This() << x;
90    }
91    void save_override(const object_id_type & t, int){
92        // upto 2G objects
93        uint_least32_t x = t.t;
94        * this->This() << x;
95    }
96    void save_override(const object_reference_type & t, int){
97        // upto 2G objects
98        uint_least32_t x = t.t;
99        * this->This() << x;
100    }
101    void save_override(const tracking_type & t, int){
102        char x = t.t;
103        * this->This() << x;
104    }
105
106    // explicitly convert to char * to avoid compile ambiguities
107    void save_override(const class_name_type & t, int){
108                const std::string s(t);
109                * this->This() << s;
110    }
111
112    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
113    init();
114
115    basic_binary_oarchive(unsigned int flags) :
116        detail::common_oarchive<Archive>(flags)
117    {}
118};
119
120} // namespace archive
121} // namespace boost
122
123#endif // BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP
Note: See TracBrowser for help on using the repository browser.