LCOV - code coverage report
Current view: top level - util/encode - binary_from_base16.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_BASE16_HPP
       2                 :            : #define BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE16_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_base16.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                 :            : // See binary_from_base32hex.h for why we need _from_base64.hpp here.
      22                 :            : #include <boost/archive/iterators/binary_from_base64.hpp>
      23                 :            : 
      24                 :            : #include <exceptions/exceptions.h>
      25                 :            : 
      26                 :            : namespace boost { 
      27                 :            : namespace archive {
      28                 :            : namespace iterators {
      29                 :            : 
      30                 :            : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
      31                 :            : // convert base16 characters to binary data
      32                 :            : 
      33                 :            : namespace detail {
      34                 :            : 
      35                 :            : template<class CharType>
      36                 :            : struct to_4_bit {
      37                 :            :     typedef CharType result_type;
      38                 :      26291 :     CharType operator()(CharType t) const{
      39                 :            :         const char lookup_table[] = {
      40                 :            :             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 00-0f
      41                 :            :             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 10-1f
      42                 :            :             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 20-2f
      43                 :            :              0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, // 30-3f
      44                 :            :             -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 40-4f
      45                 :            :             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 50-5f
      46                 :            :             -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1  // 60-6f
      47                 :      26291 :         };
      48                 :            :         // metrowerks trips this assertion - how come?
      49                 :            :         #if ! defined(__MWERKS__)
      50                 :            :         BOOST_STATIC_ASSERT(0x70 == sizeof(lookup_table));
      51                 :            :         #endif
      52                 :      26291 :         signed char value = -1;
      53         [ +  + ]:      26291 :         if((unsigned)t < sizeof(lookup_table))
      54                 :      26146 :             value = lookup_table[(unsigned)t];
      55         [ +  + ]:      26291 :         if(-1 == value) { 
      56 [ +  - ][ +  - ]:        464 :             isc_throw(isc::BadValue,
      57                 :            :                       "attempt to decode a value not in base16 char set");
      58                 :            :         }
      59                 :      26059 :         return (value);
      60                 :            :     }
      61                 :            : };
      62                 :            : 
      63                 :            : } // namespace detail
      64                 :            : 
      65                 :            : // note: what we would like to do is
      66                 :            : // template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
      67                 :            : //  typedef transform_iterator<
      68                 :            : //      from_4_bit<CharType>,
      69                 :            : //      transform_width<Base, 4, sizeof(Base::value_type) * 8, CharType>
      70                 :            : //  > base16_from_binary;
      71                 :            : // but C++ won't accept this.  Rather than using a "type generator" and
      72                 :            : // using a different syntax, make a derivation which should be equivalent.
      73                 :            : //
      74                 :            : // Another issue addressed here is that the transform_iterator doesn't have
      75                 :            : // a templated constructor.  This makes it incompatible with the dataflow
      76                 :            : // ideal.  This is also addressed here.
      77                 :            : 
      78                 :            : template<
      79                 :            :     class Base, 
      80                 :            :     class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
      81                 :            : >
      82                 :            : class binary_from_base16 : public
      83                 :            :     transform_iterator<
      84                 :            :         detail::to_4_bit<CharType>,
      85                 :            :         Base
      86                 :            :     >
      87                 :            : {
      88                 :            :     friend class boost::iterator_core_access;
      89                 :            :     typedef transform_iterator<
      90                 :            :         detail::to_4_bit<CharType>,
      91                 :            :         Base
      92                 :            :     > super_t;
      93                 :            : public:
      94                 :            :     // make composible buy using templated constructor
      95                 :            :     template<class T>
      96                 :            :     binary_from_base16(BOOST_PFTO_WRAPPER(T)  start) :
      97                 :            :         super_t(
      98                 :            :             Base(BOOST_MAKE_PFTO_WRAPPER(static_cast<T>(start))), 
      99                 :            :             detail::to_4_bit<CharType>()
     100                 :       2906 :         )
     101                 :            :     {}
     102                 :            :     // intel 7.1 doesn't like default copy constructor
     103                 :            :     binary_from_base16(const binary_from_base16 & rhs) : 
     104                 :            :         super_t(
     105                 :            :             Base(rhs.base_reference()),
     106                 :            :             detail::to_4_bit<CharType>()
     107                 :      16200 :         )
     108                 :            :     {}
     109                 :            : //    binary_from_base16(){};
     110                 :            : };
     111                 :            : 
     112                 :            : } // namespace iterators
     113                 :            : } // namespace archive
     114                 :            : } // namespace boost
     115                 :            : 
     116                 :            : #endif // BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE16_HPP
     117                 :            : 
     118                 :            : // Local Variables: 
     119                 :            : // mode: c++
     120                 :            : // End: 

Generated by: LCOV version 1.9