Collage
0.6.1
|
00001 00002 /* Copyright (c) 2012, Daniel Nachbaur <danielnachbaur@googlemail.com> 00003 * 2012, Stefan Eilemann <eile@eyescale.ch> 00004 * 00005 * This library is free software; you can redistribute it and/or modify it under 00006 * the terms of the GNU Lesser General Public License version 2.1 as published 00007 * by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this library; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00017 */ 00018 00019 // Based on portable_oarchive.hpp 00020 // https://github.com/boost-vault/serialization/eos_portable_archive.zip 00021 // Copyright Christian Pfligersdorffer, 2007. All rights reserved. 00022 // 00023 // Distributed under the Boost Software License, Version 1.0. (See 00024 // accompanying file LICENSE_1_0.txt or copy at 00025 // http://www.boost.org/LICENSE_1_0.txt) 00026 00027 #ifndef CO_DATAOSTREAMARCHIVE_H 00028 #define CO_DATAOSTREAMARCHIVE_H 00029 00030 #include <co/api.h> 00031 #include <co/dataOStream.h> 00032 #include <co/dataStreamArchiveException.h> 00033 00034 #include <boost/archive/basic_binary_oarchive.hpp> 00035 #include <boost/archive/detail/register_archive.hpp> 00036 #include <boost/serialization/is_bitwise_serializable.hpp> 00037 00038 #include <boost/spirit/home/support/detail/endian.hpp> 00039 #include <boost/spirit/home/support/detail/math/fpclassify.hpp> 00040 00041 #include <boost/type_traits/is_integral.hpp> 00042 #include <boost/type_traits/is_signed.hpp> 00043 #include <boost/type_traits/is_floating_point.hpp> 00044 00045 00046 namespace co 00047 { 00048 00050 class DataOStreamArchive 00051 : public boost::archive::basic_binary_oarchive< DataOStreamArchive > 00052 { 00053 typedef boost::archive::basic_binary_oarchive< DataOStreamArchive > Super; 00054 00055 public: 00057 CO_API DataOStreamArchive( DataOStream& stream ); 00058 00060 CO_API void save_binary( const void* data, std::size_t size ); 00061 00063 template< typename T > 00064 void save_array( const boost::serialization::array< T >& a, unsigned int ); 00065 00067 struct use_array_optimization 00068 { 00069 template< class T > 00070 struct apply 00071 : public boost::serialization::is_bitwise_serializable< T > {}; 00072 }; 00073 00074 private: 00075 friend class boost::archive::save_access; 00076 00083 CO_API void save( bool b ); 00084 00086 template< class C, class T, class A > 00087 void save( const std::basic_string< C, T, A >& s ); 00088 00096 template< typename T > 00097 typename boost::enable_if< boost::is_integral<T> >::type save( const T& t ); 00098 00126 template< typename T > 00127 typename boost::enable_if< boost::is_floating_point<T> >::type 00128 save( const T& t ); 00129 00130 #if BOOST_VERSION >= 104400 00131 // in boost 1.44 version_type was splitted into library_version_type and 00132 // item_version_type, plus a whole bunch of additional strong typedefs 00133 CO_API void save( const boost::archive::library_version_type& version ); 00134 CO_API void save( const boost::archive::class_id_type& class_id ); 00135 CO_API void save( const boost::serialization::item_version_type& class_id ); 00136 CO_API 00137 void save( const boost::serialization::collection_size_type& class_id ); 00138 CO_API void save( const boost::archive::object_id_type& object_id ); 00139 CO_API void save( const boost::archive::version_type& version ); 00140 #endif 00141 00142 CO_API void _saveSignedChar( const signed char& c ); 00143 00144 DataOStream& _stream; 00145 }; 00146 00147 #include "dataOStreamArchive.ipp" // template implementation 00148 00149 } 00150 00151 BOOST_SERIALIZATION_REGISTER_ARCHIVE(co::DataOStreamArchive) 00152 BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(co::DataOStreamArchive) 00153 00154 #endif //CO_DATAOSTREAMARCHIVE_H