Kea 2.5.4
binary_from_base16.h
Go to the documentation of this file.
1#ifndef BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE16_HPP
2#define BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE16_HPP
3
5// binary_from_base16.h (derived from boost binary_from_base64.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 <cassert>
15
16// See binary_from_base32hex.h for why we need _from_base64.hpp here.
17#include <boost/archive/iterators/binary_from_base64.hpp>
18
20
21namespace boost {
22namespace archive {
23namespace iterators {
24
26// convert base16 characters to binary data
27
28namespace detail {
29
30template<class CharType>
31struct to_4_bit {
32 typedef CharType result_type;
33 CharType operator()(CharType t) const{
34 const signed char lookup_table[] = {
35 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 00-0f
36 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 10-1f
37 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 20-2f
38 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, // 30-3f
39 -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 40-4f
40 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 50-5f
41 -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 60-6f
42 };
43 BOOST_STATIC_ASSERT(0x70 == sizeof(lookup_table));
44 signed char value = -1;
45 if((unsigned)t < sizeof(lookup_table))
46 value = lookup_table[(unsigned)t];
47 if(-1 == value) {
49 "attempt to decode a value not in base16 char set");
50 }
51 return (value);
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_4_bit<CharType>,
61// transform_width<Base, 4, sizeof(Base::value_type) * 8, CharType>
62// > base16_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
70template<
71 class Base,
72 class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
73>
74class binary_from_base16 : public
75 transform_iterator<
76 detail::to_4_bit<CharType>,
77 Base
78 >
79{
81 typedef transform_iterator<
83 Base
84 > super_t;
85public:
86 // make composable by using templated constructor
87 template<class T>
89 super_t(
90 Base(static_cast<T>(start)),
91 detail::to_4_bit<CharType>()
92 )
93 {}
94 // intel 7.1 doesn't like default copy constructor
96 super_t(
97 Base(rhs.base_reference()),
98 detail::to_4_bit<CharType>()
99 )
100 {}
101// binary_from_base16(){};
102};
103
104} // namespace iterators
105} // namespace archive
106} // namespace boost
107
108#endif // BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE16_HPP
109
110// Local Variables:
111// mode: c++
112// End:
binary_from_base16(const binary_from_base16 &rhs)
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.