1 #ifndef BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP
2 #define BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP
4 // MS compatible compilers support #pragma once
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/assert.hpp>
27 #include <boost/config.hpp>
28 #include <boost/detail/workaround.hpp>
30 #include <boost/integer.hpp>
31 #include <boost/integer_traits.hpp>
33 #include <boost/archive/detail/common_oarchive.hpp>
34 #include <boost/serialization/string.hpp>
35 #include <boost/serialization/collection_size_type.hpp>
36 #include <boost/serialization/item_version_type.hpp>
38 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
41 # pragma warning(push)
42 # pragma warning(disable : 4511 4512)
49 template<class Archive> class interface_oarchive;
52 //////////////////////////////////////////////////////////////////////
53 // class basic_binary_oarchive - write serialized objects to a binary output stream
54 // note: this archive has no pretensions to portability. Archive format
55 // may vary across machine architectures and compilers. About the only
56 // guarentee is that an archive created with this code will be readable
57 // by a program built with the same tools for the same machne. This class
58 // does have the virtue of buiding the smalles archive in the minimum amount
59 // of time. So under some circumstances it may be he right choice.
60 template<class Archive>
61 class BOOST_SYMBOL_VISIBLE basic_binary_oarchive :
62 public detail::common_oarchive<Archive>
64 #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
68 #if BOOST_WORKAROUND(BOOST_MSVC, < 1500)
69 // for some inexplicable reason insertion of "class" generates compile erro
71 friend detail::interface_oarchive<Archive>;
73 friend class detail::interface_oarchive<Archive>;
76 // any datatype not specifed below will be handled by base class
77 typedef detail::common_oarchive<Archive> detail_common_oarchive;
79 void save_override(const T & t){
80 this->detail_common_oarchive::save_override(t);
83 // include these to trap a change in binary format which
84 // isn't specifically handled
85 BOOST_STATIC_ASSERT(sizeof(tracking_type) == sizeof(bool));
87 BOOST_STATIC_ASSERT(sizeof(class_id_type) == sizeof(int_least16_t));
88 BOOST_STATIC_ASSERT(sizeof(class_id_reference_type) == sizeof(int_least16_t));
90 BOOST_STATIC_ASSERT(sizeof(object_id_type) == sizeof(uint_least32_t));
91 BOOST_STATIC_ASSERT(sizeof(object_reference_type) == sizeof(uint_least32_t));
93 // binary files don't include the optional information
94 void save_override(const class_id_optional_type & /* t */){}
96 // enable this if we decide to support generation of previous versions
98 void save_override(const boost::archive::version_type & t){
99 library_version_type lvt = this->get_library_version();
100 if(boost::archive::library_version_type(7) < lvt){
101 this->detail_common_oarchive::save_override(t);
104 if(boost::archive::library_version_type(6) < lvt){
105 const boost::uint_least16_t x = t;
109 const unsigned int x = t;
113 void save_override(const boost::serialization::item_version_type & t){
114 library_version_type lvt = this->get_library_version();
115 if(boost::archive::library_version_type(7) < lvt){
116 this->detail_common_oarchive::save_override(t);
119 if(boost::archive::library_version_type(6) < lvt){
120 const boost::uint_least16_t x = t;
124 const unsigned int x = t;
129 void save_override(class_id_type & t){
130 library_version_type lvt = this->get_library_version();
131 if(boost::archive::library_version_type(7) < lvt){
132 this->detail_common_oarchive::save_override(t);
135 if(boost::archive::library_version_type(6) < lvt){
136 const boost::int_least16_t x = t;
144 void save_override(class_id_reference_type & t){
145 save_override(static_cast<class_id_type &>(t));
150 // explicitly convert to char * to avoid compile ambiguities
151 void save_override(const class_name_type & t){
152 const std::string s(t);
157 void save_override(const serialization::collection_size_type & t){
158 if (get_library_version() < boost::archive::library_version_type(6)){
161 t = serialization::collection_size_type(x);
168 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
171 basic_binary_oarchive(unsigned int flags) :
172 detail::common_oarchive<Archive>(flags)
176 } // namespace archive
183 #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
185 #endif // BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP