Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:33:01

0001 #ifndef BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP
0002 #define BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP
0003 
0004 // MS compatible compilers support #pragma once
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0010 // basic_binary_oarchive.hpp
0011 
0012 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
0013 // Use, modification and distribution is subject to the Boost Software
0014 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0015 // http://www.boost.org/LICENSE_1_0.txt)
0016 
0017 //  See http://www.boost.org for updates, documentation, and revision history.
0018 
0019 // archives stored as native binary - this should be the fastest way
0020 // to archive the state of a group of objects.  It makes no attempt to
0021 // convert to any canonical form.
0022 
0023 // IN GENERAL, ARCHIVES CREATED WITH THIS CLASS WILL NOT BE READABLE
0024 // ON PLATFORM APART FROM THE ONE THEY ARE CREATE ON
0025 
0026 #include <boost/assert.hpp>
0027 #include <boost/config.hpp>
0028 #include <boost/detail/workaround.hpp>
0029 
0030 #include <boost/integer.hpp>
0031 #include <boost/integer_traits.hpp>
0032 
0033 #include <boost/archive/detail/common_oarchive.hpp>
0034 #include <boost/serialization/string.hpp>
0035 #include <boost/serialization/collection_size_type.hpp>
0036 #include <boost/serialization/item_version_type.hpp>
0037 
0038 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
0039 
0040 #ifdef BOOST_MSVC
0041 #  pragma warning(push)
0042 #  pragma warning(disable : 4511 4512)
0043 #endif
0044 
0045 namespace boost {
0046 namespace archive {
0047 
0048 namespace detail {
0049     template<class Archive> class interface_oarchive;
0050 } // namespace detail
0051 
0052 //////////////////////////////////////////////////////////////////////
0053 // class basic_binary_oarchive - write serialized objects to a binary output stream
0054 // note: this archive has no pretensions to portability.  Archive format
0055 // may vary across machine architectures and compilers.  About the only
0056 // guarantee is that an archive created with this code will be readable
0057 // by a program built with the same tools for the same machine.  This class
0058 // does have the virtue of building the smallest archive in the minimum amount
0059 // of time.  So under some circumstances it may be he right choice.
0060 template<class Archive>
0061 class BOOST_SYMBOL_VISIBLE basic_binary_oarchive :
0062     public detail::common_oarchive<Archive>
0063 {
0064 #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
0065 public:
0066 #else
0067 protected:
0068     #if BOOST_WORKAROUND(BOOST_MSVC, < 1500)
0069         // for some inexplicable reason insertion of "class" generates compile erro
0070         // on msvc 7.1
0071         friend detail::interface_oarchive<Archive>;
0072     #else
0073         friend class detail::interface_oarchive<Archive>;
0074     #endif
0075 #endif
0076     // any datatype not specified below will be handled by base class
0077     typedef detail::common_oarchive<Archive> detail_common_oarchive;
0078     template<class T>
0079     void save_override(const T & t){
0080       this->detail_common_oarchive::save_override(t);
0081     }
0082 
0083     // include these to trap a change in binary format which
0084     // isn't specifically handled
0085     BOOST_STATIC_ASSERT(sizeof(tracking_type) == sizeof(bool));
0086     // upto 32K classes
0087     BOOST_STATIC_ASSERT(sizeof(class_id_type) == sizeof(int_least16_t));
0088     BOOST_STATIC_ASSERT(sizeof(class_id_reference_type) == sizeof(int_least16_t));
0089     // upto 2G objects
0090     BOOST_STATIC_ASSERT(sizeof(object_id_type) == sizeof(uint_least32_t));
0091     BOOST_STATIC_ASSERT(sizeof(object_reference_type) == sizeof(uint_least32_t));
0092 
0093     // binary files don't include the optional information
0094     void save_override(const class_id_optional_type & /* t */){}
0095 
0096     // enable this if we decide to support generation of previous versions
0097     #if 0
0098     void save_override(const boost::archive::version_type & t){
0099         library_version_type lvt = this->get_library_version();
0100         if(boost::serialization::library_version_type(7) < lvt){
0101             this->detail_common_oarchive::save_override(t);
0102         }
0103         else
0104         if(boost::serialization::library_version_type(6) < lvt){
0105             const boost::uint_least16_t x = t;
0106             * this->This() << x;
0107         }
0108         else{
0109             const unsigned int x = t;
0110             * this->This() << x;
0111         }
0112     }
0113     void save_override(const boost::serialization::item_version_type & t){
0114         library_version_type lvt = this->get_library_version();
0115         if(boost::serialization::library_version_type(7) < lvt){
0116             this->detail_common_oarchive::save_override(t);
0117         }
0118         else
0119         if(boost::serialization::library_version_type(6) < lvt){
0120             const boost::uint_least16_t x = t;
0121             * this->This() << x;
0122         }
0123         else{
0124             const unsigned int x = t;
0125             * this->This() << x;
0126         }
0127     }
0128 
0129     void save_override(class_id_type & t){
0130         library_version_type lvt = this->get_library_version();
0131         if(boost::serialization::library_version_type(7) < lvt){
0132             this->detail_common_oarchive::save_override(t);
0133         }
0134         else
0135         if(boost::serialization::library_version_type(6) < lvt){
0136             const boost::int_least16_t x = t;
0137             * this->This() << x;
0138         }
0139         else{
0140             const int x = t;
0141             * this->This() << x;
0142         }
0143     }
0144     void save_override(class_id_reference_type & t){
0145         save_override(static_cast<class_id_type &>(t));
0146     }
0147 
0148     #endif
0149 
0150     // explicitly convert to char * to avoid compile ambiguities
0151     void save_override(const class_name_type & t){
0152         const std::string s(t);
0153         * this->This() << s;
0154     }
0155 
0156     #if 0
0157     void save_override(const serialization::collection_size_type & t){
0158         if (get_library_version() < boost::serialization::library_version_type(6)){
0159             unsigned int x=0;
0160             * this->This() >> x;
0161             t = serialization::collection_size_type(x);
0162         }
0163         else{
0164             * this->This() >> t;
0165         }
0166     }
0167     #endif
0168     BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0169     init();
0170 
0171     basic_binary_oarchive(unsigned int flags) :
0172         detail::common_oarchive<Archive>(flags)
0173     {}
0174 };
0175 
0176 } // namespace archive
0177 } // namespace boost
0178 
0179 #ifdef BOOST_MSVC
0180 #pragma warning(pop)
0181 #endif
0182 
0183 #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
0184 
0185 #endif // BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP