Branch data Line data Source code
1 : : #ifndef BOOST_ARCHIVE_ITERATORS_BASE32HEX_FROM_BINARY_HPP
2 : : #define BOOST_ARCHIVE_ITERATORS_BASE32HEX_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 : : // base32hex_from_binary.h (derived from boost 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 <cstddef> // size_t
22 : : #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
23 : : #if defined(BOOST_NO_STDC_NAMESPACE)
24 : : namespace std{
25 : : using ::size_t;
26 : : } // namespace std
27 : : #endif
28 : :
29 : : // We use the same boost header files used in "base64_from_". Since the
30 : : // precise path to these headers may vary depending on the boost version we
31 : : // simply include the base64 header here.
32 : : #include <boost/archive/iterators/base64_from_binary.hpp>
33 : :
34 : : namespace boost {
35 : : namespace archive {
36 : : namespace iterators {
37 : :
38 : : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
39 : : // convert binary integers to base32hex characters
40 : :
41 : : namespace detail {
42 : :
43 : : template<class CharType>
44 : : struct from_5_bit {
45 : : typedef CharType result_type;
46 : 0 : CharType operator()(CharType t) const{
47 : : const char * lookup_table =
48 : : "0123456789"
49 : 12812 : "ABCDEFGHIJKLMNOPQRSTUV";
50 [ # # ][ - + ]: 12812 : assert(t < 32);
51 : 0 : return (lookup_table[static_cast<size_t>(t)]);
52 : : }
53 : : };
54 : :
55 : : } // namespace detail
56 : :
57 : : // note: what we would like to do is
58 : : // template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
59 : : // typedef transform_iterator<
60 : : // from_5_bit<CharType>,
61 : : // transform_width<Base, 5, sizeof(Base::value_type) * 8, CharType>
62 : : // > base32hex_from_binary;
63 : : // but C++ won't accept this. Rather than using a "type generator" and
64 : : // using a different syntax, make a derivation which should be equivalent.
65 : : //
66 : : // Another issue addressed here is that the transform_iterator doesn't have
67 : : // a templated constructor. This makes it incompatible with the dataflow
68 : : // ideal. This is also addressed here.
69 : :
70 : : //template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
71 : : template<
72 : : class Base,
73 : : class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
74 : : >
75 : : class base32hex_from_binary :
76 : : public transform_iterator<
77 : : detail::from_5_bit<CharType>,
78 : : Base
79 : : >
80 : : {
81 : : friend class boost::iterator_core_access;
82 : : typedef transform_iterator<
83 : : BOOST_DEDUCED_TYPENAME detail::from_5_bit<CharType>,
84 : : Base
85 : : > super_t;
86 : :
87 : : public:
88 : : // make composible buy using templated constructor
89 : : template<class T>
90 : 1104 : base32hex_from_binary(BOOST_PFTO_WRAPPER(T) start) :
91 : : super_t(
92 : : Base(BOOST_MAKE_PFTO_WRAPPER(static_cast<T>(start))),
93 : : detail::from_5_bit<CharType>()
94 : 2208 : )
95 : 1104 : {}
96 : : // intel 7.1 doesn't like default copy constructor
97 : 6624 : base32hex_from_binary(const base32hex_from_binary & rhs) :
98 : : super_t(
99 : : Base(rhs.base_reference()),
100 : : detail::from_5_bit<CharType>()
101 : 13248 : )
102 : 6624 : {}
103 : : // base32hex_from_binary(){};
104 : : };
105 : :
106 : : } // namespace iterators
107 : : } // namespace archive
108 : : } // namespace boost
109 : :
110 : : #endif // BOOST_ARCHIVE_ITERATORS_BASE32HEX_FROM_BINARY_HPP
|