LCOV - code coverage report
Current view: top level - util/encode - base16_from_binary.h (source / functions) Hit Total Coverage
Test: report.info Lines: 8 10 80.0 %
Date: 2012-05-15 Functions: 2 3 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 4 25.0 %

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

Generated by: LCOV version 1.9