Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:29

0001 #ifndef BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE64_HPP
0002 #define BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE64_HPP
0003 
0004 // MS compatible compilers support #pragma once
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0010 // binary_from_base64.hpp
0011 
0012 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
0013 // Use, modification and distribution is subject to the Boost Software
0014 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0015 // http://www.boost.org/LICENSE_1_0.txt)
0016 
0017 //  See http://www.boost.org for updates, documentation, and revision history.
0018 
0019 #include <boost/assert.hpp>
0020 
0021 #include <boost/serialization/throw_exception.hpp>
0022 #include <boost/static_assert.hpp>
0023 
0024 #include <boost/iterator/transform_iterator.hpp>
0025 #include <boost/archive/iterators/dataflow_exception.hpp>
0026 
0027 namespace boost {
0028 namespace archive {
0029 namespace iterators {
0030 
0031 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0032 // convert base64 characters to binary data
0033 
0034 namespace detail {
0035 
0036 template<class CharType>
0037 struct to_6_bit {
0038     typedef CharType result_type;
0039     CharType operator()(CharType t) const{
0040         static const signed char lookup_table[] = {
0041             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0042             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0043             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
0044             52,53,54,55,56,57,58,59,60,61,-1,-1,-1, 0,-1,-1, // render '=' as 0
0045             -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
0046             15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
0047             -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
0048             41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1
0049         };
0050         // metrowerks trips this assertion - how come?
0051         #if ! defined(__MWERKS__)
0052         BOOST_STATIC_ASSERT(128 == sizeof(lookup_table));
0053         #endif
0054         signed char value = -1;
0055         if((unsigned)t <= 127)
0056             value = lookup_table[(unsigned)t];
0057         if(-1 == value)
0058             boost::serialization::throw_exception(
0059                 dataflow_exception(dataflow_exception::invalid_base64_character)
0060             );
0061         return value;
0062     }
0063 };
0064 
0065 } // namespace detail
0066 
0067 // note: what we would like to do is
0068 // template<class Base, class CharType = typename Base::value_type>
0069 //  typedef transform_iterator<
0070 //      from_6_bit<CharType>,
0071 //      transform_width<Base, 6, sizeof(Base::value_type) * 8, CharType>
0072 //  > base64_from_binary;
0073 // but C++ won't accept this.  Rather than using a "type generator" and
0074 // using a different syntax, make a derivation which should be equivalent.
0075 //
0076 // Another issue addressed here is that the transform_iterator doesn't have
0077 // a templated constructor.  This makes it incompatible with the dataflow
0078 // ideal.  This is also addressed here.
0079 
0080 template<
0081     class Base,
0082     class CharType = typename boost::iterator_value<Base>::type
0083 >
0084 class binary_from_base64 : public
0085     transform_iterator<
0086         detail::to_6_bit<CharType>,
0087         Base
0088     >
0089 {
0090     friend class boost::iterator_core_access;
0091     typedef transform_iterator<
0092         detail::to_6_bit<CharType>,
0093         Base
0094     > super_t;
0095 public:
0096     // make composable by using templated constructor
0097     template<class T>
0098     binary_from_base64(T  start) :
0099         super_t(
0100             Base(static_cast< T >(start)),
0101             detail::to_6_bit<CharType>()
0102         )
0103     {}
0104     // intel 7.1 doesn't like default copy constructor
0105     binary_from_base64(const binary_from_base64 & rhs) :
0106         super_t(
0107             Base(rhs.base_reference()),
0108             detail::to_6_bit<CharType>()
0109         )
0110     {}
0111 //    binary_from_base64(){};
0112 };
0113 
0114 } // namespace iterators
0115 } // namespace archive
0116 } // namespace boost
0117 
0118 #endif // BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE64_HPP