fix doc example typo
[boost.git] / boost / archive / basic_binary_oarchive.hpp
blobdcd5679d442c8d451c4538c17809241206d02804
1 #ifndef BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP
2 #define BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
6 # pragma once
7 #endif
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // basic_binary_oarchive.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 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.
23 // IN GENERAL, ARCHIVES CREATED WITH THIS CLASS WILL NOT BE READABLE
24 // ON PLATFORM APART FROM THE ONE THEY ARE CREATE ON
26 #include <boost/config.hpp>
27 #include <boost/serialization/pfto.hpp>
29 #include <boost/detail/workaround.hpp>
30 #include <boost/archive/detail/common_oarchive.hpp>
31 #include <boost/serialization/string.hpp>
32 #include <boost/serialization/collection_size_type.hpp>
34 namespace boost {
35 namespace archive {
37 //////////////////////////////////////////////////////////////////////
38 // class basic_binary_oarchive - write serialized objects to a binary output stream
39 // note: this archive has no pretensions to portability. Archive format
40 // may vary across machine architectures and compilers. About the only
41 // guarentee is that an archive created with this code will be readable
42 // by a program built with the same tools for the same machne. This class
43 // does have the virtue of buiding the smalles archive in the minimum amount
44 // of time. So under some circumstances it may be he right choice.
45 template<class Archive>
46 class basic_binary_oarchive :
47 public archive::detail::common_oarchive<Archive>
49 protected:
50 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
51 public:
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>;
56 #else
57 friend class detail::interface_oarchive<Archive>;
58 #endif
59 // any datatype not specifed below will be handled by base class
60 typedef detail::common_oarchive<Archive> detail_common_oarchive;
61 template<class T>
62 void save_override(const T & t, BOOST_PFTO int version){
63 this->detail_common_oarchive::save_override(t, static_cast<int>(version));
66 // binary files don't include the optional information
67 void save_override(const class_id_optional_type & /* t */, int){}
69 void save_override(const version_type & t, int){
70 // upto 255 versions
71 // note:t.t resolves borland ambguity
72 const unsigned char x = t.t;
73 * this->This() << x;
75 void save_override(const class_id_type & t, int){
76 // upto 32K classes
77 const int_least16_t x = t.t;
78 * this->This() << x;
80 void save_override(const class_id_reference_type & t, int){
81 // upto 32K classes
82 const int_least16_t x = t.t;
83 * this->This() << x;
85 void save_override(const object_id_type & t, int){
86 // upto 2G objects
87 const uint_least32_t x = t.t;
88 * this->This() << x;
90 void save_override(const object_reference_type & t, int){
91 // upto 2G objects
92 uint_least32_t x = t.t;
93 * this->This() << x;
95 void save_override(const tracking_type & t, int){
96 const char x = t.t;
97 * this->This() << x;
100 // explicitly convert to char * to avoid compile ambiguities
101 void save_override(const class_name_type & t, int){
102 const std::string s(t);
103 * this->This() << s;
106 void save_override(const serialization::collection_size_type & t, int){
107 // for backward compatibility, 64 bit integer or variable length integer would be preferred
108 unsigned int x = t.t;
109 * this->This() << x;
112 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
113 init();
115 basic_binary_oarchive(unsigned int flags) :
116 detail::common_oarchive<Archive>(flags)
120 } // namespace archive
121 } // namespace boost
123 #endif // BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP