Collage  1.3.0
High-performance C++ library for developing object-oriented distributed applications.
dataOStreamArchive.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_oarchive.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_DATAOSTREAMARCHIVE_H
30 #define CO_DATAOSTREAMARCHIVE_H
31 
32 #include <co/api.h>
33 #include <co/dataOStream.h>
34 #include <co/dataStreamArchiveException.h>
35 
36 #include <boost/version.hpp>
37 
38 #include <boost/archive/basic_binary_oarchive.hpp>
39 #include <boost/archive/detail/register_archive.hpp>
40 #include <boost/serialization/is_bitwise_serializable.hpp>
41 #if BOOST_VERSION >= 104400
42 # include <boost/serialization/item_version_type.hpp>
43 #endif
44 
45 #include <boost/spirit/home/support/detail/endian.hpp>
46 #include <boost/spirit/home/support/detail/math/fpclassify.hpp>
47 
48 #include <boost/type_traits/is_integral.hpp>
49 #include <boost/type_traits/is_signed.hpp>
50 #include <boost/type_traits/is_floating_point.hpp>
51 
52 
53 namespace co
54 {
55 
58  : public boost::archive::basic_binary_oarchive< DataOStreamArchive >
59 {
60  typedef boost::archive::basic_binary_oarchive< DataOStreamArchive > Super;
61 
62 public:
64  CO_API explicit DataOStreamArchive( DataOStream& stream );
65 
67  CO_API void save_binary( const void* data, std::size_t size );
68 
70  template< typename T >
71  void save_array( const boost::serialization::array< T >& a, unsigned int );
72 
75  {
76  template< class T >
77  struct apply
78  : public boost::serialization::is_bitwise_serializable< T > {};
79  };
80 
81 private:
82  friend class boost::archive::save_access;
83 
90  CO_API void save( bool b );
91 
93  template< class C, class T, class A >
94  void save( const std::basic_string< C, T, A >& s );
95 
103  template< typename T >
104  typename boost::enable_if< boost::is_integral<T> >::type save( const T& t );
105 
133  template< typename T >
134  typename boost::enable_if< boost::is_floating_point<T> >::type
135  save( const T& t );
136 
137 #if BOOST_VERSION >= 104400
138  // in boost 1.44 version_type was splitted into library_version_type and
139  // item_version_type, plus a whole bunch of additional strong typedefs
140  CO_API void save( const boost::archive::library_version_type& version );
141  CO_API void save( const boost::archive::class_id_type& class_id );
142  CO_API void save( const boost::serialization::item_version_type& class_id );
143  CO_API
144  void save( const boost::serialization::collection_size_type& class_id );
145  CO_API void save( const boost::archive::object_id_type& object_id );
146  CO_API void save( const boost::archive::version_type& version );
147 #endif
148 
149  CO_API void _saveSignedChar( const signed char& c );
150 
151  DataOStream& _stream;
152 };
153 
154 #include "dataOStreamArchive.ipp" // template implementation
155 
156 }
157 
158 BOOST_SERIALIZATION_REGISTER_ARCHIVE(co::DataOStreamArchive)
159 BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(co::DataOStreamArchive)
160 
161 #endif //CO_DATAOSTREAMARCHIVE_H
Defines export visibility macros for library Collage.
A boost.serialization output archive writing to a co::DataOStream.
CO_API DataOStreamArchive(DataOStream &stream)
Construct a new serialization archive.
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:48
Object-oriented network library.
Definition: barrier.h:27