PageRenderTime 48ms CodeModel.GetById 39ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/archive/basic_binary_oarchive.hpp

http://hadesmem.googlecode.com/
C++ Header | 180 lines | 124 code | 25 blank | 31 comment | 13 complexity | 6724710d82fda1c0b2ff65046c0bf375 MD5 | raw file
  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/assert.hpp>
 27#include <boost/config.hpp>
 28#include <boost/detail/workaround.hpp>
 29#include <boost/serialization/pfto.hpp>
 30
 31#include <boost/integer.hpp>
 32#include <boost/integer_traits.hpp>
 33
 34#include <boost/archive/detail/common_oarchive.hpp>
 35#include <boost/serialization/string.hpp>
 36#include <boost/serialization/collection_size_type.hpp>
 37#include <boost/serialization/item_version_type.hpp>
 38
 39#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
 40
 41#ifdef BOOST_MSVC
 42#  pragma warning(push)
 43#  pragma warning(disable : 4511 4512)
 44#endif
 45
 46namespace boost {
 47namespace archive {
 48
 49//////////////////////////////////////////////////////////////////////
 50// class basic_binary_oarchive - write serialized objects to a binary output stream
 51// note: this archive has no pretensions to portability.  Archive format
 52// may vary across machine architectures and compilers.  About the only
 53// guarentee is that an archive created with this code will be readable
 54// by a program built with the same tools for the same machne.  This class
 55// does have the virtue of buiding the smalles archive in the minimum amount
 56// of time.  So under some circumstances it may be he right choice.
 57template<class Archive>
 58class basic_binary_oarchive : 
 59    public archive::detail::common_oarchive<Archive>
 60{
 61protected:
 62#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
 63public:
 64#elif defined(BOOST_MSVC)
 65    // for some inexplicable reason insertion of "class" generates compile erro
 66    // on msvc 7.1
 67    friend detail::interface_oarchive<Archive>;
 68#else
 69    friend class detail::interface_oarchive<Archive>;
 70#endif
 71    // any datatype not specifed below will be handled by base class
 72    typedef detail::common_oarchive<Archive> detail_common_oarchive;
 73    template<class T>
 74    void save_override(const T & t, BOOST_PFTO int version){
 75      this->detail_common_oarchive::save_override(t, static_cast<int>(version));
 76    }
 77
 78    // include these to trap a change in binary format which
 79    // isn't specifically handled
 80    BOOST_STATIC_ASSERT(sizeof(tracking_type) == sizeof(bool));
 81    // upto 32K classes
 82    BOOST_STATIC_ASSERT(sizeof(class_id_type) == sizeof(int_least16_t));
 83    BOOST_STATIC_ASSERT(sizeof(class_id_reference_type) == sizeof(int_least16_t));
 84    // upto 2G objects
 85    BOOST_STATIC_ASSERT(sizeof(object_id_type) == sizeof(uint_least32_t));
 86    BOOST_STATIC_ASSERT(sizeof(object_reference_type) == sizeof(uint_least32_t));
 87
 88    // binary files don't include the optional information 
 89    void save_override(const class_id_optional_type & /* t */, int){}
 90
 91    // enable this if we decide to support generation of previous versions
 92    #if 0
 93    void save_override(const boost::archive::version_type & t, int version){
 94        library_version_type lvt = this->get_library_version();
 95        if(boost::archive::library_version_type(7) < lvt){
 96            this->detail_common_oarchive::save_override(t, version);
 97        }
 98        else
 99        if(boost::archive::library_version_type(6) < lvt){
100            const boost::uint_least16_t x = t;
101            * this->This() << x;
102        }
103        else{
104            const unsigned int x = t;
105            * this->This() << x;
106        }
107    }
108    void save_override(const boost::serialization::item_version_type & t, int version){
109        library_version_type lvt = this->get_library_version();
110        if(boost::archive::library_version_type(7) < lvt){
111            this->detail_common_oarchive::save_override(t, version);
112        }
113        else
114        if(boost::archive::library_version_type(6) < lvt){
115            const boost::uint_least16_t x = t;
116            * this->This() << x;
117        }
118        else{
119            const unsigned int x = t;
120            * this->This() << x;
121        }
122    }
123
124    void save_override(class_id_type & t, int version){
125        library_version_type lvt = this->get_library_version();
126        if(boost::archive::library_version_type(7) < lvt){
127            this->detail_common_oarchive::save_override(t, version);
128        }
129        else
130        if(boost::archive::library_version_type(6) < lvt){
131            const boost::int_least16_t x = t;
132            * this->This() << x;
133        }
134        else{
135            const int x = t;
136            * this->This() << x;
137        }
138    }
139    void save_override(class_id_reference_type & t, int version){
140        save_override(static_cast<class_id_type &>(t), version);
141    }
142
143    #endif
144
145    // explicitly convert to char * to avoid compile ambiguities
146    void save_override(const class_name_type & t, int){
147        const std::string s(t);
148        * this->This() << s;
149    }
150
151    #if 0
152    void save_override(const serialization::collection_size_type & t, int){
153        if (get_library_version() < boost::archive::library_version_type(6)){
154            unsigned int x=0;
155            * this->This() >> x;
156            t = serialization::collection_size_type(x);
157        } 
158        else{
159            * this->This() >> t;
160        }
161    }
162    #endif
163    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
164    init();
165
166    basic_binary_oarchive(unsigned int flags) :
167        detail::common_oarchive<Archive>(flags)
168    {}
169};
170
171} // namespace archive
172} // namespace boost
173
174#ifdef BOOST_MSVC
175#pragma warning(pop)
176#endif
177
178#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
179
180#endif // BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP