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 "dataIStreamArchive.h"
21 :
22 : #include "dataIStream.h"
23 : #include "dataStreamArchive.h"
24 :
25 : #include <boost/archive/detail/archive_serializer_map.hpp>
26 : #include <boost/archive/impl/archive_serializer_map.ipp>
27 :
28 : namespace boost
29 : {
30 : namespace archive
31 : {
32 : template class CO_API detail::archive_serializer_map< co::DataIStreamArchive >;
33 : }
34 : }
35 :
36 : namespace co
37 : {
38 :
39 6 : DataIStreamArchive::DataIStreamArchive( DataIStream& stream )
40 : : Super( 0 )
41 6 : , _stream( stream )
42 : {
43 : using namespace boost::archive;
44 :
45 6 : if( _loadSignedChar() != magicByte )
46 0 : throw archive_exception( archive_exception::invalid_signature );
47 : else
48 : {
49 : #if BOOST_VERSION < 104400
50 : version_type libraryVersion;
51 : #else
52 6 : library_version_type libraryVersion;
53 : #endif
54 6 : operator>>( libraryVersion );
55 :
56 6 : if( libraryVersion > BOOST_ARCHIVE_VERSION( ))
57 0 : throw archive_exception( archive_exception::unsupported_version );
58 : else
59 6 : set_library_version( libraryVersion );
60 : }
61 6 : }
62 :
63 11 : void DataIStreamArchive::load_binary( void* data, std::size_t size )
64 : {
65 11 : _stream >> Array< void >( data, size );
66 11 : }
67 :
68 1 : void DataIStreamArchive::load( bool& b )
69 : {
70 1 : switch( signed char c = _loadSignedChar( ))
71 : {
72 : case 0:
73 1 : b = false;
74 1 : break;
75 : case 1:
76 0 : b = _loadSignedChar();
77 0 : break;
78 : default:
79 0 : throw DataStreamArchiveException( c );
80 : }
81 1 : }
82 :
83 : #if BOOST_VERSION >= 104400
84 6 : void DataIStreamArchive::load( boost::archive::library_version_type& version )
85 : {
86 6 : load((boost::uint_least16_t&)(version));
87 6 : }
88 :
89 0 : void DataIStreamArchive::load( boost::archive::class_id_type& class_id )
90 : {
91 0 : load((boost::uint_least16_t&)(class_id));
92 0 : }
93 :
94 0 : void DataIStreamArchive::load(
95 : boost::serialization::item_version_type& version )
96 : {
97 0 : load((boost::uint_least32_t&)(version));
98 0 : }
99 :
100 1 : void DataIStreamArchive::load(
101 : boost::serialization::collection_size_type& version )
102 : {
103 1 : load((boost::uint_least32_t&)(version));
104 1 : }
105 :
106 0 : void DataIStreamArchive::load( boost::archive::object_id_type& object_id )
107 : {
108 0 : load((boost::uint_least32_t&)(object_id));
109 0 : }
110 :
111 1 : void DataIStreamArchive::load( boost::archive::version_type& version )
112 : {
113 1 : load((boost::uint_least32_t&)(version));
114 1 : }
115 : #endif
116 :
117 20 : signed char DataIStreamArchive::_loadSignedChar()
118 : {
119 : signed char c;
120 20 : _stream >> c;
121 20 : return c;
122 : }
123 :
124 60 : }
|