LCOV - code coverage report
Current view: top level - util/encode - binary_from_base32hex.h (source / functions) Hit Total Coverage
Test: report.info Lines: 10 10 100.0 %
Date: 2012-05-15 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 8 75.0 %

           Branch data     Line data    Source code
       1                 :            : #ifndef BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE32HEX_HPP
       2                 :            : #define BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE32HEX_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                 :            : // binary_from_base32hex.h (derived from boost binary_from_base64.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                 :            : // We use the same boost header files used in "_from_base64".  Since the
      22                 :            : // precise path to these headers may vary depending on the boost version we
      23                 :            : // simply include the base64 header here.
      24                 :            : #include <boost/archive/iterators/binary_from_base64.hpp>
      25                 :            : 
      26                 :            : #include <exceptions/exceptions.h>
      27                 :            : 
      28                 :            : namespace boost { 
      29                 :            : namespace archive {
      30                 :            : namespace iterators {
      31                 :            : 
      32                 :            : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
      33                 :            : // convert base32hex characters to binary data
      34                 :            : 
      35                 :            : namespace detail {
      36                 :            : 
      37                 :            : template<class CharType>
      38                 :            : struct to_5_bit {
      39                 :            :     typedef CharType result_type;
      40                 :      32774 :     CharType operator()(CharType t) const{
      41                 :            :         const char lookup_table[] = {
      42                 :            :             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 00-0f
      43                 :            :             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 10-1f
      44                 :            :             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 20-2f
      45                 :            :              0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, // 30-3f
      46                 :            :             -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, // 40-4f
      47                 :            :             25,26,27,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 50-5f
      48                 :            :             -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, // 60-6f
      49                 :            :             25,26,27,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1  // 70-7f
      50                 :      32774 :         };
      51                 :            :         // metrowerks trips this assertion - how come?
      52                 :            :         #if ! defined(__MWERKS__)
      53                 :            :         BOOST_STATIC_ASSERT(0x80 == sizeof(lookup_table));
      54                 :            :         #endif
      55                 :      32774 :         signed char value = -1;
      56         [ +  + ]:      32774 :         if((unsigned)t < sizeof(lookup_table))
      57                 :      32134 :             value = lookup_table[(unsigned)t];
      58         [ +  + ]:      32774 :         if(-1 == value) { 
      59 [ +  - ][ +  - ]:       1962 :             isc_throw(isc::BadValue,
      60                 :            :                       "attempt to decode a value not in base32hex char set");
      61                 :            :         }
      62                 :      31793 :         return (value);
      63                 :            :     }
      64                 :            : };
      65                 :            : 
      66                 :            : } // namespace detail
      67                 :            : 
      68                 :            : // note: what we would like to do is
      69                 :            : // template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
      70                 :            : //  typedef transform_iterator<
      71                 :            : //      from_5_bit<CharType>,
      72                 :            : //      transform_width<Base, 5, sizeof(Base::value_type) * 8, CharType>
      73                 :            : //  > base32hex_from_binary;
      74                 :            : // but C++ won't accept this.  Rather than using a "type generator" and
      75                 :            : // using a different syntax, make a derivation which should be equivalent.
      76                 :            : //
      77                 :            : // Another issue addressed here is that the transform_iterator doesn't have
      78                 :            : // a templated constructor.  This makes it incompatible with the dataflow
      79                 :            : // ideal.  This is also addressed here.
      80                 :            : 
      81                 :            : template<
      82                 :            :     class Base, 
      83                 :            :     class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
      84                 :            : >
      85                 :            : class binary_from_base32hex : public
      86                 :            :     transform_iterator<
      87                 :            :         detail::to_5_bit<CharType>,
      88                 :            :         Base
      89                 :            :     >
      90                 :            : {
      91                 :            :     friend class boost::iterator_core_access;
      92                 :            :     typedef transform_iterator<
      93                 :            :         detail::to_5_bit<CharType>,
      94                 :            :         Base
      95                 :            :     > super_t;
      96                 :            : public:
      97                 :            :     // make composible buy using templated constructor
      98                 :            :     template<class T>
      99                 :            :     binary_from_base32hex(BOOST_PFTO_WRAPPER(T)  start) :
     100                 :            :         super_t(
     101                 :            :             Base(BOOST_MAKE_PFTO_WRAPPER(static_cast<T>(start))), 
     102                 :            :             detail::to_5_bit<CharType>()
     103                 :       4080 :         )
     104                 :            :     {}
     105                 :            :     // intel 7.1 doesn't like default copy constructor
     106                 :            :     binary_from_base32hex(const binary_from_base32hex & rhs) : 
     107                 :            :         super_t(
     108                 :            :             Base(rhs.base_reference()),
     109                 :            :             detail::to_5_bit<CharType>()
     110                 :      18300 :         )
     111                 :            :     {}
     112                 :            : //    binary_from_base32hex(){};
     113                 :            : };
     114                 :            : 
     115                 :            : } // namespace iterators
     116                 :            : } // namespace archive
     117                 :            : } // namespace boost
     118                 :            : 
     119                 :            : #endif // BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE32HEX_HPP
     120                 :            : 
     121                 :            : // Local Variables: 
     122                 :            : // mode: c++
     123                 :            : // End: 

Generated by: LCOV version 1.9