Chris@16: #ifndef BOOST_ARCHIVE_ITERATORS_BASE64_FROM_BINARY_HPP Chris@16: #define BOOST_ARCHIVE_ITERATORS_BASE64_FROM_BINARY_HPP Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // base64_from_binary.hpp Chris@16: Chris@16: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: Chris@16: #include Chris@16: Chris@16: #include // size_t Chris@16: #if defined(BOOST_NO_STDC_NAMESPACE) Chris@16: namespace std{ Chris@16: using ::size_t; Chris@16: } // namespace std Chris@16: #endif Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace archive { Chris@16: namespace iterators { Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // convert binary integers to base64 characters Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: struct from_6_bit { Chris@16: typedef CharType result_type; Chris@16: CharType operator()(CharType t) const{ Chris@16: const char * lookup_table = Chris@16: "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Chris@16: "abcdefghijklmnopqrstuvwxyz" Chris@16: "0123456789" Chris@16: "+/"; Chris@16: BOOST_ASSERT(t < 64); Chris@16: return lookup_table[static_cast(t)]; Chris@16: } Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: // note: what we would like to do is Chris@101: // template Chris@16: // typedef transform_iterator< Chris@16: // from_6_bit, Chris@16: // transform_width Chris@16: // > base64_from_binary; Chris@16: // but C++ won't accept this. Rather than using a "type generator" and Chris@16: // using a different syntax, make a derivation which should be equivalent. Chris@16: // Chris@16: // Another issue addressed here is that the transform_iterator doesn't have Chris@16: // a templated constructor. This makes it incompatible with the dataflow Chris@16: // ideal. This is also addressed here. Chris@16: Chris@101: //template Chris@16: template< Chris@16: class Base, Chris@101: class CharType = typename boost::iterator_value::type Chris@16: > Chris@16: class base64_from_binary : Chris@16: public transform_iterator< Chris@16: detail::from_6_bit, Chris@16: Base Chris@16: > Chris@16: { Chris@16: friend class boost::iterator_core_access; Chris@16: typedef transform_iterator< Chris@101: typename detail::from_6_bit, Chris@16: Base Chris@16: > super_t; Chris@16: Chris@16: public: Chris@16: // make composible buy using templated constructor Chris@16: template Chris@16: base64_from_binary(BOOST_PFTO_WRAPPER(T) start) : Chris@16: super_t( Chris@16: Base(BOOST_MAKE_PFTO_WRAPPER(static_cast< T >(start))), Chris@16: detail::from_6_bit() Chris@16: ) Chris@16: {} Chris@16: // intel 7.1 doesn't like default copy constructor Chris@16: base64_from_binary(const base64_from_binary & rhs) : Chris@16: super_t( Chris@16: Base(rhs.base_reference()), Chris@16: detail::from_6_bit() Chris@16: ) Chris@16: {} Chris@16: // base64_from_binary(){}; Chris@16: }; Chris@16: Chris@16: } // namespace iterators Chris@16: } // namespace archive Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_ARCHIVE_ITERATORS_BASE64_FROM_BINARY_HPP