source: NonGTP/Boost/boost/archive/iterators/base64_from_binary.hpp @ 857

Revision 857, 3.3 KB checked in by igarcia, 19 years ago (diff)
Line 
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) && (_MSC_VER >= 1020)
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 <cassert>
20
21#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
22#include <boost/pfto.hpp>
23
24#include <boost/iterator/transform_iterator.hpp>
25#include <boost/archive/iterators/dataflow_exception.hpp>
26
27namespace boost {
28namespace archive {
29namespace iterators {
30
31/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
32// convert binary integers to base64 characters
33
34namespace detail {
35
36template<class CharType>
37struct from_6_bit {
38    typedef CharType result_type;
39    CharType operator()(CharType t) const{
40        const char * lookup_table =
41            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
42            "abcdefghijklmnopqrstuvwxyz"
43            "0123456789"
44            "+/";
45        assert(t < 64);
46        return lookup_table[t];
47    }
48};
49
50} // namespace detail
51
52// note: what we would like to do is
53// template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
54//  typedef transform_iterator<
55//      from_6_bit<CharType>,
56//      transform_width<Base, 6, sizeof(Base::value_type) * 8, CharType>
57//  > base64_from_binary;
58// but C++ won't accept this.  Rather than using a "type generator" and
59// using a different syntax, make a derivation which should be equivalent.
60//
61// Another issue addressed here is that the transform_iterator doesn't have
62// a templated constructor.  This makes it incompatible with the dataflow
63// ideal.  This is also addressed here.
64
65//template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
66template<
67    class Base,
68    class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
69>
70class base64_from_binary :
71    public transform_iterator<
72        detail::from_6_bit<CharType>,
73        Base
74    >
75{
76    friend class boost::iterator_core_access;
77    typedef transform_iterator<
78        BOOST_DEDUCED_TYPENAME detail::from_6_bit<CharType>,
79        Base
80    > super_t;
81
82public:
83    // make composible buy using templated constructor
84    template<class T>
85    base64_from_binary(BOOST_PFTO_WRAPPER(T) start) :
86        super_t(
87            Base(BOOST_MAKE_PFTO_WRAPPER(static_cast<T>(start))),
88            detail::from_6_bit<CharType>()
89        )
90    {}
91    // intel 7.1 doesn't like default copy constructor
92    base64_from_binary(const base64_from_binary & rhs) :
93        super_t(
94            Base(rhs.base_reference()),
95            detail::from_6_bit<CharType>()
96        )
97    {}
98//    base64_from_binary(){};
99};
100
101} // namespace iterators
102} // namespace archive
103} // namespace boost
104
105#endif // BOOST_ARCHIVE_ITERATORS_BASE64_FROM_BINARY_HPP
Note: See TracBrowser for help on using the repository browser.