Collage  1.0.1
Object-Oriented C++ Network Library
dataIStreamArchive.h
1 
2 /* Copyright (c) 2012, Daniel Nachbaur <danielnachbaur@googlemail.com>
3  * 2012, Stefan Eilemann <eile@eyescale.ch>
4  *
5  * This file is part of Collage <https://github.com/Eyescale/Collage>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 2.1 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 // Based on portable_iarchive.hpp
22 // https://github.com/boost-vault/serialization/eos_portable_archive.zip
23 // Copyright Christian Pfligersdorffer, 2007. All rights reserved.
24 //
25 // Distributed under the Boost Software License, Version 1.0. (See
26 // accompanying file LICENSE_1_0.txt or copy at
27 // http://www.boost.org/LICENSE_1_0.txt)
28 
29 #ifndef CO_DATAISTREAMARCHIVE_H
30 #define CO_DATAISTREAMARCHIVE_H
31 
32 #include <co/api.h>
33 #include <co/types.h>
34 
35 #pragma warning( push )
36 #pragma warning( disable: 4800 )
37 #include <boost/archive/basic_binary_iarchive.hpp>
38 #pragma warning( pop )
39 #include <boost/archive/detail/register_archive.hpp>
40 #include <boost/archive/shared_ptr_helper.hpp>
41 #include <boost/serialization/is_bitwise_serializable.hpp>
42 
43 #include <boost/spirit/home/support/detail/endian.hpp>
44 #include <boost/spirit/home/support/detail/math/fpclassify.hpp>
45 
46 #include <boost/type_traits/is_integral.hpp>
47 #include <boost/type_traits/is_unsigned.hpp>
48 #include <boost/type_traits/is_floating_point.hpp>
49 
50 #include <boost/utility/enable_if.hpp>
51 
52 namespace co
53 {
56  : public boost::archive::basic_binary_iarchive< DataIStreamArchive >
57  , public boost::archive::detail::shared_ptr_helper
58 {
59  typedef boost::archive::basic_binary_iarchive< DataIStreamArchive > Super;
60 
61 public:
63  CO_API DataIStreamArchive( DataIStream& stream );
64 
66  CO_API void load_binary( void* data, std::size_t size );
67 
69  template< typename T >
70  void load_array( boost::serialization::array< T >& a, unsigned int );
71 
74  {
75  template< class T >
76  struct apply
77  : public boost::serialization::is_bitwise_serializable< T > {};
78  };
79 
80 private:
81  friend class boost::archive::load_access;
82 
90  CO_API void load( bool& b );
91 
93  template< class C, class T, class A >
94  void load( std::basic_string< C, T, A >& s );
95 
103  template< typename T >
104  typename boost::enable_if< boost::is_integral<T> >::type load( T& t );
105 
133  template< typename T >
134  typename boost::enable_if< boost::is_floating_point<T> >::type load( T& t );
135 
136 #if BOOST_VERSION >= 104400
137  // in boost 1.44 version_type was splitted into library_version_type and
138  // item_version_type, plus a whole bunch of additional strong typedefs
139  CO_API void load( boost::archive::library_version_type& version );
140  CO_API void load( boost::archive::class_id_type& class_id );
141  CO_API void load( boost::serialization::item_version_type& version );
142  CO_API void load( boost::serialization::collection_size_type& version );
143  CO_API void load( boost::archive::object_id_type& object_id );
144  CO_API void load( boost::archive::version_type& version );
145 #endif
146 
147  CO_API signed char _loadSignedChar();
148 
149  DataIStream& _stream;
150 };
151 
152 }
153 
154 #include "dataIStreamArchive.ipp" // template implementation
155 
156 // contains load_override impl for class_name_type
157 #include <boost/archive/impl/basic_binary_iarchive.ipp>
158 
159 BOOST_SERIALIZATION_REGISTER_ARCHIVE(co::DataIStreamArchive)
160 BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(co::DataIStreamArchive)
161 
162 #endif //CO_DATAISTREAMARCHIVE_H
CO_API DataIStreamArchive(DataIStream &stream)
Construct a new deserialization archive.
A boost.serialization input archive reading from a co::DataIStream.
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:40