PageRenderTime 27ms CodeModel.GetById 10ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ Header | 222 lines | 170 code | 23 blank | 29 comment | 17 complexity | 1a9472e359de6ca7a4def8bca8ef31ad MD5 | raw file
  1#ifndef BOOST_ARCHIVE_BASIC_BINARY_IARCHIVE_HPP
  2#define BOOST_ARCHIVE_BASIC_BINARY_IARCHIVE_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_iarchive.hpp
 11//
 12// archives stored as native binary - this should be the fastest way
 13// to archive the state of a group of obects.  It makes no attempt to
 14// convert to any canonical form.
 15
 16// IN GENERAL, ARCHIVES CREATED WITH THIS CLASS WILL NOT BE READABLE
 17// ON PLATFORM APART FROM THE ONE THEY ARE CREATED ON
 18
 19// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
 20// Use, modification and distribution is subject to the Boost Software
 21// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 22// http://www.boost.org/LICENSE_1_0.txt)
 23
 24//  See http://www.boost.org for updates, documentation, and revision history.
 25
 26#include <boost/config.hpp>
 27#include <boost/detail/workaround.hpp>
 28#include <boost/serialization/pfto.hpp>
 29
 30#include <boost/archive/basic_archive.hpp>
 31#include <boost/archive/detail/common_iarchive.hpp>
 32#include <boost/serialization/collection_size_type.hpp>
 33#include <boost/serialization/string.hpp>
 34#include <boost/serialization/item_version_type.hpp>
 35#include <boost/integer_traits.hpp>
 36
 37#ifdef BOOST_MSVC
 38#  pragma warning(push)
 39#  pragma warning(disable : 4511 4512)
 40#endif
 41
 42#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
 43
 44namespace boost { 
 45namespace archive {
 46
 47/////////////////////////////////////////////////////////////////////////
 48// class basic_binary_iarchive - read serialized objects from a input binary stream
 49template<class Archive>
 50class basic_binary_iarchive : 
 51    public detail::common_iarchive<Archive>
 52{
 53protected:
 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_iarchive<Archive>;
 60#else
 61    friend class detail::interface_iarchive<Archive>;
 62#endif
 63    // intermediate level to support override of operators
 64    // fot templates in the absence of partial function 
 65    // template ordering. If we get here pass to base class
 66    // note extra nonsense to sneak it pass the borland compiers
 67    typedef detail::common_iarchive<Archive> detail_common_iarchive;
 68    template<class T>
 69    void load_override(T & t, BOOST_PFTO int version){
 70      this->detail_common_iarchive::load_override(t, static_cast<int>(version));
 71    }
 72
 73    // include these to trap a change in binary format which
 74    // isn't specifically handled
 75    // upto 32K classes
 76    BOOST_STATIC_ASSERT(sizeof(class_id_type) == sizeof(int_least16_t));
 77    BOOST_STATIC_ASSERT(sizeof(class_id_reference_type) == sizeof(int_least16_t));
 78    // upto 2G objects
 79    BOOST_STATIC_ASSERT(sizeof(object_id_type) == sizeof(uint_least32_t));
 80    BOOST_STATIC_ASSERT(sizeof(object_reference_type) == sizeof(uint_least32_t));
 81
 82    // binary files don't include the optional information 
 83    void load_override(class_id_optional_type & /* t */, int){}
 84
 85    void load_override(tracking_type & t, int /*version*/){
 86        library_version_type lvt = this->get_library_version();
 87        if(boost::archive::library_version_type(6) < lvt){
 88            int_least8_t x=0;
 89            * this->This() >> x;
 90            t = boost::archive::tracking_type(x);
 91        }
 92        else{
 93            bool x=0;
 94            * this->This() >> x;
 95            t = boost::archive::tracking_type(x);
 96        }
 97    }
 98    void load_override(class_id_type & t, int version){
 99        library_version_type lvt = this->get_library_version();
100        if(boost::archive::library_version_type(7) < lvt){
101            this->detail_common_iarchive::load_override(t, version);
102        }
103        else
104        if(boost::archive::library_version_type(6) < lvt){
105            int_least16_t x=0;
106            * this->This() >> x;
107            t = boost::archive::class_id_type(x);
108        }
109        else{
110            int x=0;
111            * this->This() >> x;
112            t = boost::archive::class_id_type(x);
113        }
114    }
115    void load_override(class_id_reference_type & t, int version){
116        load_override(static_cast<class_id_type &>(t), version);
117    }
118#if 0
119    void load_override(class_id_reference_type & t, int version){
120        library_version_type lvt = this->get_library_version();
121        if(boost::archive::library_version_type(7) < lvt){
122            this->detail_common_iarchive::load_override(t, version);
123        }
124        else
125        if(boost::archive::library_version_type(6) < lvt){
126            int_least16_t x=0;
127            * this->This() >> x;
128            t = boost::archive::class_id_reference_type(
129                boost::archive::class_id_type(x)
130            );
131        }
132        else{
133            int x=0;
134            * this->This() >> x;
135            t = boost::archive::class_id_reference_type(
136                boost::archive::class_id_type(x)
137            );
138        }
139    }
140#endif
141
142    void load_override(version_type & t, int version){
143        library_version_type lvt = this->get_library_version();
144        if(boost::archive::library_version_type(7) < lvt){
145            this->detail_common_iarchive::load_override(t, version);
146        }
147        else
148        if(boost::archive::library_version_type(6) < lvt){
149            uint_least8_t x=0;
150            * this->This() >> x;
151            t = boost::archive::version_type(x);
152        }
153        else
154        if(boost::archive::library_version_type(5) < lvt){
155            uint_least16_t x=0;
156            * this->This() >> x;
157            t = boost::archive::version_type(x);
158        }
159        else
160        if(boost::archive::library_version_type(2) < lvt){
161            // upto 255 versions
162            unsigned char x=0;
163            * this->This() >> x;
164            t = version_type(x);
165        }
166        else{
167            unsigned int x=0;
168            * this->This() >> x;
169            t = boost::archive::version_type(x);
170        }
171    }
172
173    void load_override(boost::serialization::item_version_type & t, int version){
174        library_version_type lvt = this->get_library_version();
175//        if(boost::archive::library_version_type(7) < lvt){
176        if(boost::archive::library_version_type(6) < lvt){
177            this->detail_common_iarchive::load_override(t, version);
178        }
179        else
180        if(boost::archive::library_version_type(6) < lvt){
181            uint_least16_t x=0;
182            * this->This() >> x;
183            t = boost::serialization::item_version_type(x);
184        }
185        else{
186            unsigned int x=0;
187            * this->This() >> x;
188            t = boost::serialization::item_version_type(x);
189        }
190    }
191
192    void load_override(serialization::collection_size_type & t, int version){
193        if(boost::archive::library_version_type(5) < this->get_library_version()){
194            this->detail_common_iarchive::load_override(t, version);
195        }
196        else{
197            unsigned int x=0;
198            * this->This() >> x;
199            t = serialization::collection_size_type(x);
200        } 
201    }
202
203    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
204    load_override(class_name_type & t, int);
205    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
206    init();
207   
208    basic_binary_iarchive(unsigned int flags) :
209        detail::common_iarchive<Archive>(flags)
210    {}
211};
212
213} // namespace archive
214} // namespace boost
215
216#ifdef BOOST_MSVC
217#pragma warning(pop)
218#endif
219
220#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
221
222#endif // BOOST_ARCHIVE_BASIC_BINARY_IARCHIVE_HPP