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