Line data Source code
1 :
2 : /* Copyright (c) 2012, Daniel Nachbaur <danielnachbaur@googlemail.com>
3 : *
4 : * This file is part of Collage <https://github.com/Eyescale/Collage>
5 : *
6 : * This library is free software; you can redistribute it and/or modify it under
7 : * the terms of the GNU Lesser General Public License version 2.1 as published
8 : * by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful, but WITHOUT
11 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 : * details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with this library; if not, write to the Free Software Foundation, Inc.,
17 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #include "dataOStreamArchive.h"
21 : #include "dataStreamArchive.h"
22 :
23 : #include <boost/archive/detail/archive_serializer_map.hpp>
24 : #include <boost/archive/impl/archive_serializer_map.ipp>
25 :
26 : namespace boost
27 : {
28 : namespace archive
29 : {
30 : template class CO_API detail::archive_serializer_map<co::DataOStreamArchive>;
31 : }
32 : }
33 :
34 : namespace co
35 : {
36 :
37 6 : DataOStreamArchive::DataOStreamArchive( DataOStream& stream )
38 : : Super( 0 )
39 6 : , _stream( stream )
40 : {
41 : // write our minimalistic header (magic byte plus version)
42 : // the boost archives write a string instead - by calling
43 : // boost::archive::basic_binary_oarchive<derived_t>::init()
44 6 : _saveSignedChar( magicByte );
45 :
46 : using namespace boost::archive;
47 :
48 : #if BOOST_VERSION < 104400
49 : const version_type libraryVersion( BOOST_ARCHIVE_VERSION( ));
50 : #else
51 6 : const library_version_type libraryVersion( BOOST_ARCHIVE_VERSION( ));
52 : #endif
53 6 : operator<<( libraryVersion );
54 6 : }
55 :
56 11 : void DataOStreamArchive::save_binary( const void* data, std::size_t size )
57 : {
58 11 : _stream << Array< const void >( data, size );
59 11 : }
60 :
61 2 : void DataOStreamArchive::save( bool b )
62 : {
63 2 : _saveSignedChar( b );
64 2 : if( b )
65 0 : _saveSignedChar( 'T' );
66 2 : }
67 :
68 : #if BOOST_VERSION >= 104400
69 6 : void DataOStreamArchive::save(
70 : const boost::archive::library_version_type& version )
71 : {
72 6 : save((boost::uint_least16_t)(version));
73 6 : }
74 :
75 0 : void DataOStreamArchive::save( const boost::archive::class_id_type& class_id )
76 : {
77 0 : save((boost::uint_least16_t)(class_id));
78 0 : }
79 :
80 0 : void DataOStreamArchive::save(
81 : const boost::serialization::item_version_type& class_id )
82 : {
83 0 : save((boost::uint_least32_t)(class_id));
84 0 : }
85 :
86 1 : void DataOStreamArchive::save(
87 : const boost::serialization::collection_size_type& class_id )
88 : {
89 1 : save((boost::uint_least32_t)(class_id));
90 1 : }
91 :
92 0 : void DataOStreamArchive::save( const boost::archive::object_id_type& object_id )
93 : {
94 0 : save((boost::uint_least32_t)(object_id));
95 0 : }
96 :
97 1 : void DataOStreamArchive::save( const boost::archive::version_type& version )
98 : {
99 1 : save((boost::uint_least32_t)(version));
100 1 : }
101 : #endif
102 :
103 20 : void DataOStreamArchive::_saveSignedChar( const signed char& c )
104 : {
105 20 : _stream << c;
106 20 : }
107 :
108 60 : }
|