23#ifndef GUL17_HEXDUMP_H_ 
   24#define GUL17_HEXDUMP_H_ 
   65template <
typename T, 
typename = 
int>
 
   66struct IsHexDumpContainer : std::false_type { };
 
   69struct IsHexDumpContainer <
T,
 
   71        std::is_integral<typename std::iterator_traits<decltype(
 
   72                                    std::declval<T>().cbegin())>::value_type>::value,
 
   73        decltype(std::declval<T>().cbegin(),
 
   74                    std::declval<T>().cend(),
 
   86template <
typename T, 
typename = 
int>
 
   87struct IsHexDumpIterator : std::false_type { };
 
   90struct IsHexDumpIterator <
T,
 
   92        std::is_integral<typename std::iterator_traits<T>::value_type>::value
 
   93            and not std::is_same<typename std::iterator_traits<T>::iterator_category,
 
   94                    std::input_iterator_tag>::value,
 
   95        decltype(std::declval<T>().operator*(),
 
   96                    std::declval<T>().operator++(),
 
  102struct IsHexDumpIterator <
T,
 
  104        std::is_pointer<T>::value
 
  105        and std::is_integral<typename std::remove_pointer<T>::type>::value,
 
  108    : std::true_type { };
 
  112    typename = std::enable_if_t<std::is_convertible<
 
  114        std::basic_ostream<
typename StreamT::char_type,
 
  115                            typename StreamT::traits_type>*>
::value>>
 
  116struct IsHexDumpStream : std::true_type { };
 
  123    typename = std::enable_if_t<detail::IsHexDumpStream<StreamT>::value>,
 
  124    typename = std::enable_if_t<detail::IsHexDumpIterator<IteratorT>::value>>
 
  126    std::string_view 
prompt = 
"")
 
  128    constexpr auto maxelem = 1000ul * 16; 
 
  131    constexpr auto nod = 
sizeof(*begin) * 2;
 
  135    const std::string empty(
nod + 1, 
' ');
 
  137    dest << std::hex << std::setfill(
'0');
 
  145        for (
size_t j = 0; 
j < 16; ++
j) {
 
  147                const unsigned long long ch = 
static_cast< 
  165                const auto c = 
static_cast<unsigned char>(*line);
 
  219    typename = std::enable_if_t<detail::IsHexDumpIterator<IteratorT>::value>>
 
  222    std::stringstream 
o{ };
 
  223    return detail::hexdump_stream(
o, begin, end, 
prompt).str();
 
 
  236    typename = std::enable_if_t<detail::IsHexDumpContainer<ContainerT>::value>>
 
  239    std::stringstream 
o{ };
 
  240    return detail::hexdump_stream(
o, 
cont.cbegin(), 
cont.cend(), 
prompt).str();
 
 
  256template<
typename IteratorT, 
typename ContainerT = 
void*>
 
  301        *
this = std::move(
other);
 
 
  354        return detail::hexdump_stream(
os, 
hdp.begin_, 
hdp.end_, 
hdp.prompt_);
 
 
  359        std::enable_if_t<!detail::IsHexDumpContainer<ContType>::value, 
int> = 0
 
  361    void regenerate_iterators() 
noexcept 
  369        std::enable_if_t<detail::IsHexDumpContainer<ContType>::value, 
int> = 0
 
  371    void regenerate_iterators() 
noexcept 
 
  421    typename = std::enable_if_t<detail::IsHexDumpIterator<IteratorT>::value>>
 
  425    return { begin, end, std::move(
prompt), 
nullptr };
 
 
  437    typename = std::enable_if_t<detail::IsHexDumpContainer<ContainerT>::value>>
 
  441    return { 
cont.cbegin(), 
cont.cend(), std::move(
prompt), 
nullptr };
 
 
  453    typename = std::enable_if_t<detail::IsHexDumpContainer<ContainerT>::value,
 
  456HexdumpParameterForward<
decltype(std::declval<ContainerT>().cbegin()), 
ContainerT>
 
  462             std::forward<ContainerT>(
cont) };
 
 
Helper object used to enable a convenient syntax to dump things to a stream.
Definition hexdump.h:257
 
IteratorT begin_
Iterator to begin of elements to be dumped (in iterator mode)
Definition hexdump.h:260
 
HexdumpParameterForward & operator=(const HexdumpParameterForward &other)
Copy assignment (automatically updates the begin_ and end_ interator members if the copied object hol...
Definition hexdump.h:308
 
HexdumpParameterForward(IteratorT begin_it, IteratorT end_it, std::string prompt, ContainerT &&cont)
Construct a hexdump parameter forwarder object.
Definition hexdump.h:279
 
IteratorT end_
Iterator past end of elements to be dumped (in iterator mode)
Definition hexdump.h:262
 
std::string prompt_
Possible prompt to prepend to the dump.
Definition hexdump.h:264
 
HexdumpParameterForward & operator=(HexdumpParameterForward &&other) noexcept
Move assignment (automatically updates the begin_ and end_ interator members if the moved-from object...
Definition hexdump.h:327
 
ContainerT cont_
A container with the elements to be dumped (in container/temporary mode)
Definition hexdump.h:266
 
HexdumpParameterForward(HexdumpParameterForward &&other) noexcept
Move constructor (automatically updates the begin_ and end_ interator members if the moved-from objec...
Definition hexdump.h:299
 
HexdumpParameterForward(const HexdumpParameterForward &other)
Copy constructor (automatically updates the begin_ and end_ interator members if the copied object ho...
Definition hexdump.h:293
 
friend std::ostream & operator<<(std::ostream &os, const HexdumpParameterForward< IteratorT, ContainerT > &hdp)
Overload of std::ostream's operator<< to enable a convenient syntax to dump things to a stream.
Definition hexdump.h:351
 
auto constexpr bit_set(unsigned bit) noexcept -> ReturnT
Set a bit in an integral type.
Definition bit_manip.h:121
 
HexdumpParameterForward< const IteratorT > hexdump_stream(const IteratorT &begin, const IteratorT &end, std::string prompt="")
Generate a hexdump of a data range that can be efficiently written to a stream using operator<<.
Definition hexdump.h:423
 
std::string hexdump(IteratorT begin, IteratorT end, std::string_view prompt="")
Generate a hexdump of a data range and return it as a string.
Definition hexdump.h:220
 
Definition of macros used internally by GUL.
 
Namespace gul17 contains all functions and classes of the General Utility Library.
Definition doxygen.h:26