Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:29

0001 #ifndef BOOST_ARCHIVE_BINARY_IPRIMITIVE_HPP
0002 #define BOOST_ARCHIVE_BINARY_IPRIMITIVE_HPP
0003 
0004 // MS compatible compilers support #pragma once
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 #if defined(_MSC_VER)
0010 #pragma warning( disable : 4800 )
0011 #endif
0012 
0013 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0014 // basic_binary_iprimitive.hpp
0015 //
0016 // archives stored as native binary - this should be the fastest way
0017 // to archive the state of a group of objects.  It makes no attempt to
0018 // convert to any canonical form.
0019 
0020 // IN GENERAL, ARCHIVES CREATED WITH THIS CLASS WILL NOT BE READABLE
0021 // ON PLATFORM APART FROM THE ONE THEY ARE CREATED ON
0022 
0023 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
0024 // Use, modification and distribution is subject to the Boost Software
0025 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0026 // http://www.boost.org/LICENSE_1_0.txt)
0027 
0028 //  See http://www.boost.org for updates, documentation, and revision history.
0029 
0030 #include <iosfwd>
0031 #include <boost/assert.hpp>
0032 #include <locale>
0033 #include <cstring> // std::memcpy
0034 #include <cstddef> // std::size_t
0035 #include <streambuf> // basic_streambuf
0036 #include <string>
0037 
0038 #include <boost/config.hpp>
0039 #if defined(BOOST_NO_STDC_NAMESPACE)
0040 namespace std{
0041     using ::memcpy;
0042     using ::size_t;
0043 } // namespace std
0044 #endif
0045 
0046 #include <boost/cstdint.hpp>
0047 #include <boost/serialization/throw_exception.hpp>
0048 #include <boost/integer.hpp>
0049 #include <boost/integer_traits.hpp>
0050 
0051 #include <boost/serialization/is_bitwise_serializable.hpp>
0052 #include <boost/serialization/array_wrapper.hpp>
0053 
0054 #include <boost/archive/basic_streambuf_locale_saver.hpp>
0055 #include <boost/archive/codecvt_null.hpp>
0056 #include <boost/archive/archive_exception.hpp>
0057 #include <boost/archive/detail/auto_link_archive.hpp>
0058 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
0059 
0060 namespace boost {
0061 namespace archive {
0062 
0063 /////////////////////////////////////////////////////////////////////////////
0064 // class binary_iarchive - read serialized objects from a input binary stream
0065 template<class Archive, class Elem, class Tr>
0066 class BOOST_SYMBOL_VISIBLE basic_binary_iprimitive {
0067 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
0068     friend class load_access;
0069 protected:
0070 #else
0071 public:
0072 #endif
0073     std::basic_streambuf<Elem, Tr> & m_sb;
0074     // return a pointer to the most derived class
0075     Archive * This(){
0076         return static_cast<Archive *>(this);
0077     }
0078 
0079     #ifndef BOOST_NO_STD_LOCALE
0080     // note order! - if you change this, libstd++ will fail!
0081     // a) create new locale with new codecvt facet
0082     // b) save current locale
0083     // c) change locale to new one
0084     // d) use stream buffer
0085     // e) change locale back to original
0086     // f) destroy new codecvt facet
0087     boost::archive::codecvt_null<Elem> codecvt_null_facet;
0088     basic_streambuf_locale_saver<Elem, Tr> locale_saver;
0089     std::locale archive_locale;
0090     #endif
0091 
0092     // main template for serialization of primitive types
0093     template<class T>
0094     void load(T & t){
0095         load_binary(& t, sizeof(T));
0096     }
0097 
0098     /////////////////////////////////////////////////////////
0099     // fundamental types that need special treatment
0100 
0101     // trap usage of invalid uninitialized boolean
0102     void load(bool & t){
0103         load_binary(& t, sizeof(t));
0104         int i = t;
0105         BOOST_ASSERT(0 == i || 1 == i);
0106         (void)i; // warning suppression for release builds.
0107     }
0108     BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0109     load(std::string &s);
0110     #ifndef BOOST_NO_STD_WSTRING
0111     BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0112     load(std::wstring &ws);
0113     #endif
0114     BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0115     load(char * t);
0116     BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0117     load(wchar_t * t);
0118 
0119     BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0120     init();
0121     BOOST_ARCHIVE_OR_WARCHIVE_DECL
0122     basic_binary_iprimitive(
0123         std::basic_streambuf<Elem, Tr> & sb,
0124         bool no_codecvt
0125     );
0126     BOOST_ARCHIVE_OR_WARCHIVE_DECL
0127     ~basic_binary_iprimitive();
0128 public:
0129     // we provide an optimized load for all fundamental types
0130     // typedef serialization::is_bitwise_serializable<mpl::_1>
0131     // use_array_optimization;
0132     struct use_array_optimization {
0133         template <class T>
0134         #if defined(BOOST_NO_DEPENDENT_NESTED_DERIVATIONS)
0135             struct apply {
0136                 typedef typename boost::serialization::is_bitwise_serializable< T >::type type;
0137             };
0138         #else
0139             struct apply : public boost::serialization::is_bitwise_serializable< T > {};
0140         #endif
0141     };
0142 
0143     // the optimized load_array dispatches to load_binary
0144     template <class ValueType>
0145     void load_array(serialization::array_wrapper<ValueType>& a, unsigned int)
0146     {
0147       load_binary(a.address(),a.count()*sizeof(ValueType));
0148     }
0149 
0150     void
0151     load_binary(void *address, std::size_t count);
0152 };
0153 
0154 template<class Archive, class Elem, class Tr>
0155 inline void
0156 basic_binary_iprimitive<Archive, Elem, Tr>::load_binary(
0157     void *address,
0158     std::size_t count
0159 ){
0160     // note: an optimizer should eliminate the following for char files
0161     BOOST_ASSERT(
0162         static_cast<std::streamsize>(count / sizeof(Elem))
0163         <= boost::integer_traits<std::streamsize>::const_max
0164     );
0165     std::streamsize s = static_cast<std::streamsize>(count / sizeof(Elem));
0166     std::streamsize scount = m_sb.sgetn(
0167         static_cast<Elem *>(address),
0168         s
0169     );
0170     if(scount != s)
0171         boost::serialization::throw_exception(
0172             archive_exception(archive_exception::input_stream_error)
0173         );
0174     // note: an optimizer should eliminate the following for char files
0175     BOOST_ASSERT(count % sizeof(Elem) <= boost::integer_traits<std::streamsize>::const_max);
0176     s = static_cast<std::streamsize>(count % sizeof(Elem));
0177     if(0 < s){
0178 //        if(is.fail())
0179 //            boost::serialization::throw_exception(
0180 //                archive_exception(archive_exception::stream_error)
0181 //        );
0182         Elem t;
0183         scount = m_sb.sgetn(& t, 1);
0184         if(scount != 1)
0185             boost::serialization::throw_exception(
0186                 archive_exception(archive_exception::input_stream_error)
0187             );
0188         std::memcpy(static_cast<char*>(address) + (count - s), &t, static_cast<std::size_t>(s));
0189     }
0190 }
0191 
0192 } // namespace archive
0193 } // namespace boost
0194 
0195 #include <boost/archive/detail/abi_suffix.hpp> // pop pragmas
0196 
0197 #endif // BOOST_ARCHIVE_BINARY_IPRIMITIVE_HPP