Kea 2.2.0
base16_from_binary.h
Go to the documentation of this file.
1#ifndef BOOST_ARCHIVE_ITERATORS_BASE16_FROM_BINARY_HPP
2#define BOOST_ARCHIVE_ITERATORS_BASE16_FROM_BINARY_HPP
3
5// base16_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
15
16#include <cstddef> // size_t
17#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
18#if defined(BOOST_NO_STDC_NAMESPACE)
19namespace std{
20 using ::size_t;
21} // namespace std
22#endif
23
24// See base32hex_from_binary.h for why we need base64_from...hpp here.
25#include <boost/archive/iterators/base64_from_binary.hpp>
26
27namespace boost {
28namespace archive {
29namespace iterators {
30
32// convert binary integers to base16 characters
33
34namespace detail {
35
36template<class CharType>
37struct from_4_bit {
38 typedef CharType result_type;
39 CharType operator()(CharType t) const{
40 const char * lookup_table =
41 "0123456789"
42 "ABCDEF";
43 isc_throw_assert(t < 16);
44 return (lookup_table[static_cast<size_t>(t)]);
45 }
46};
47
48} // namespace detail
49
50// note: what we would like to do is
51// template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
52// typedef transform_iterator<
53// from_4_bit<CharType>,
54// transform_width<Base, 4, sizeof(Base::value_type) * 8, CharType>
55// > base16_from_binary;
56// but C++ won't accept this. Rather than using a "type generator" and
57// using a different syntax, make a derivation which should be equivalent.
58//
59// Another issue addressed here is that the transform_iterator doesn't have
60// a templated constructor. This makes it incompatible with the dataflow
61// ideal. This is also addressed here.
62
63//template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
64template<
65 class Base,
66 class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
67>
69 public transform_iterator<
70 detail::from_4_bit<CharType>,
71 Base
72 >
73{
75 typedef transform_iterator<
76 BOOST_DEDUCED_TYPENAME detail::from_4_bit<CharType>,
77 Base
78 > super_t;
79
80public:
81 // make composable by using templated constructor
82 template<class T>
84 super_t(
85 Base(static_cast<T>(start)),
86 detail::from_4_bit<CharType>()
87 )
88 {}
89 // intel 7.1 doesn't like default copy constructor
91 super_t(
92 Base(rhs.base_reference()),
93 detail::from_4_bit<CharType>()
94 )
95 {}
96// base16_from_binary(){};
97};
98
99} // namespace iterators
100} // namespace archive
101} // namespace boost
102
103#endif // BOOST_ARCHIVE_ITERATORS_BASE16_FROM_BINARY_HPP
base16_from_binary(const base16_from_binary &rhs)
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
Definition: isc_assert.h:18