#ifndef PORTABLE_IARCHIVE_HPP #define PORTABLE_IARCHIVE_HPP /* Copyright (c) 2007 Andrew Molloy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include "../Endianness.h" namespace BeeLib { namespace archive { template class portable_iarchive : public boost::archive::binary_iarchive_impl > { typedef portable_iarchive derived_t; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else friend class boost::archive::basic_binary_iarchive; friend class boost::archive::basic_binary_iprimitive; friend class boost::archive::load_access; #endif // default fall through for any types not specified here template void load(T & t){ boost::archive::binary_iarchive_impl::load(t); } // handle integer types void load(int16 &t) { this->load_binary(&t, sizeof(int16)); t = swapBytes(t); } void load(uint16 &t) { this->load_binary(&t, sizeof(uint16)); t = swapBytes(t); } void load(int32 &t) { this->load_binary(&t, sizeof(int32)); t = swapBytes(t); } void load(uint32 &t) { this->load_binary(&t, sizeof(uint32)); t = swapBytes(t); } void load(int64 &t) { this->load_binary(&t, sizeof(int64)); t = swapBytes(t); } void load(uint64 &t) { this->load_binary(&t, sizeof(uint64)); t = swapBytes(t); } void load(float &t) { BOOST_STATIC_ASSERT(sizeof(float) == 4); this->load_binary(&t, sizeof(float)); t = swapBytes(t); } void load(double &t) { BOOST_STATIC_ASSERT(sizeof(double) == 8); this->load_binary(&t, sizeof(double)); t = swapBytes(t); } public: portable_iarchive(std::istream & is, unsigned flags = 0) : boost::archive::binary_iarchive_impl( is, flags | boost::archive::no_header // skip default header checking ) { // use our own header checking if(0 != (flags & boost::archive::no_header)){ this->boost::archive::basic_binary_iarchive::init(); // skip the following for "portable" binary archives // boost::archive::basic_binary_oprimitive::init(); } } }; } } // explicitly instantiate for this type of text stream #include #include #include namespace boost { namespace archive { // Big Endian template class basic_binary_iarchive > ; template class basic_binary_iprimitive, std::istream> ; template class binary_iarchive_impl > ; template class detail::archive_pointer_iserializer > ; // Little Endian template class basic_binary_iarchive > ; template class basic_binary_iprimitive, std::istream> ; template class binary_iarchive_impl > ; template class detail::archive_pointer_iserializer > ; } // namespace archive } // namespace boost #define BOOST_ARCHIVE_CUSTOM_IARCHIVE_TYPES portable_iarchive #endif // PORTABLE_BINARY_IARCHIVE_HPP