• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef BOOST_ARCHIVE_ITERATORS_BASE64_FROM_BINARY_HPP
2 #define BOOST_ARCHIVE_ITERATORS_BASE64_FROM_BINARY_HPP
3 
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER)
6 # pragma once
7 #endif
8 
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // base64_from_binary.hpp
11 
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 // Use, modification and distribution is subject to the Boost Software
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
16 
17 //  See http://www.boost.org for updates, documentation, and revision history.
18 
19 #include <boost/assert.hpp>
20 
21 #include <cstddef> // size_t
22 #if defined(BOOST_NO_STDC_NAMESPACE)
23 namespace std{
24     using ::size_t;
25 } // namespace std
26 #endif
27 
28 #include <boost/iterator/transform_iterator.hpp>
29 #include <boost/archive/iterators/dataflow_exception.hpp>
30 
31 namespace boost {
32 namespace archive {
33 namespace iterators {
34 
35 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
36 // convert binary integers to base64 characters
37 
38 namespace detail {
39 
40 template<class CharType>
41 struct from_6_bit {
42     typedef CharType result_type;
operator ()boost::archive::iterators::detail::from_6_bit43     CharType operator()(CharType t) const{
44         static const char * lookup_table =
45             "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
46             "abcdefghijklmnopqrstuvwxyz"
47             "0123456789"
48             "+/";
49         BOOST_ASSERT(t < 64);
50         return lookup_table[static_cast<size_t>(t)];
51     }
52 };
53 
54 } // namespace detail
55 
56 // note: what we would like to do is
57 // template<class Base, class CharType = typename Base::value_type>
58 //  typedef transform_iterator<
59 //      from_6_bit<CharType>,
60 //      transform_width<Base, 6, sizeof(Base::value_type) * 8, CharType>
61 //  > base64_from_binary;
62 // but C++ won't accept this.  Rather than using a "type generator" and
63 // using a different syntax, make a derivation which should be equivalent.
64 //
65 // Another issue addressed here is that the transform_iterator doesn't have
66 // a templated constructor.  This makes it incompatible with the dataflow
67 // ideal.  This is also addressed here.
68 
69 //template<class Base, class CharType = typename Base::value_type>
70 template<
71     class Base,
72     class CharType = typename boost::iterator_value<Base>::type
73 >
74 class base64_from_binary :
75     public transform_iterator<
76         detail::from_6_bit<CharType>,
77         Base
78     >
79 {
80     friend class boost::iterator_core_access;
81     typedef transform_iterator<
82         typename detail::from_6_bit<CharType>,
83         Base
84     > super_t;
85 
86 public:
87     // make composible buy using templated constructor
88     template<class T>
base64_from_binary(T start)89     base64_from_binary(T start) :
90         super_t(
91             Base(static_cast< T >(start)),
92             detail::from_6_bit<CharType>()
93         )
94     {}
95     // intel 7.1 doesn't like default copy constructor
base64_from_binary(const base64_from_binary & rhs)96     base64_from_binary(const base64_from_binary & rhs) :
97         super_t(
98             Base(rhs.base_reference()),
99             detail::from_6_bit<CharType>()
100         )
101     {}
102 //    base64_from_binary(){};
103 };
104 
105 } // namespace iterators
106 } // namespace archive
107 } // namespace boost
108 
109 #endif // BOOST_ARCHIVE_ITERATORS_BASE64_FROM_BINARY_HPP
110