Kea  2.1.7-git
base32hex_from_binary.h
Go to the documentation of this file.
1 #ifndef BOOST_ARCHIVE_ITERATORS_BASE32HEX_FROM_BINARY_HPP
2 #define BOOST_ARCHIVE_ITERATORS_BASE32HEX_FROM_BINARY_HPP
3 
5 // base32hex_from_binary.h (derived from boost base64_from_binary.hpp)
6 
7 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
8 // Use, modification and distribution is subject to the Boost Software
9 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 
12 // See http://www.boost.org for updates, documentation, and revision history.
13 
14 #include <exceptions/isc_assert.h>
15 
16 #include <cstddef> // size_t
17 #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
18 #if defined(BOOST_NO_STDC_NAMESPACE)
19 namespace std{
20  using ::size_t;
21 } // namespace std
22 #endif
23 
24 // We use the same boost header files used in "base64_from_". Since the
25 // precise path to these headers may vary depending on the boost version we
26 // simply include the base64 header here.
27 #include <boost/archive/iterators/base64_from_binary.hpp>
28 
29 namespace boost {
30 namespace archive {
31 namespace iterators {
32 
34 // convert binary integers to base32hex characters
35 
36 namespace detail {
37 
38 template<class CharType>
39 struct from_5_bit {
40  typedef CharType result_type;
41  CharType operator()(CharType t) const{
42  const char * lookup_table =
43  "0123456789"
44  "ABCDEFGHIJKLMNOPQRSTUV";
45  isc_throw_assert(t < 32);
46  return (lookup_table[static_cast<size_t>(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_5_bit<CharType>,
56 // transform_width<Base, 5, sizeof(Base::value_type) * 8, CharType>
57 // > base32hex_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>
66 template<
67  class Base,
68  class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
69 >
71  public transform_iterator<
72  detail::from_5_bit<CharType>,
73  Base
74  >
75 {
76  friend class boost::iterator_core_access;
77  typedef transform_iterator<
78  BOOST_DEDUCED_TYPENAME detail::from_5_bit<CharType>,
79  Base
80  > super_t;
81 
82 public:
83  // make composable by using templated constructor
84  template<class T>
86  super_t(
87  Base(static_cast<T>(start)),
88  detail::from_5_bit<CharType>()
89  )
90  {}
91  // intel 7.1 doesn't like default copy constructor
93  super_t(
94  Base(rhs.base_reference()),
95  detail::from_5_bit<CharType>()
96  )
97  {}
98 // base32hex_from_binary(){};
99 };
100 
101 } // namespace iterators
102 } // namespace archive
103 } // namespace boost
104 
105 #endif // BOOST_ARCHIVE_ITERATORS_BASE32HEX_FROM_BINARY_HPP
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
Definition: isc_assert.h:18
STL namespace.
base32hex_from_binary(const base32hex_from_binary &rhs)