26#ifndef GUL17_HEXDUMP_H_
27#define GUL17_HEXDUMP_H_
68template <
typename T,
typename =
int>
69struct IsHexDumpContainer : std::false_type { };
72struct IsHexDumpContainer <
T,
74 std::is_integral<typename std::iterator_traits<decltype(
75 std::declval<T>().cbegin())>::value_type>::value,
76 decltype(std::declval<T>().cbegin(),
77 std::declval<T>().cend(),
89template <
typename T,
typename =
int>
90struct IsHexDumpIterator : std::false_type { };
93struct IsHexDumpIterator <
T,
95 std::is_integral<typename std::iterator_traits<T>::value_type>::value
96 and not std::is_same<typename std::iterator_traits<T>::iterator_category,
97 std::input_iterator_tag>::value,
98 decltype(std::declval<T>().operator*(),
99 std::declval<T>().operator++(),
102 : std::true_type { };
105struct IsHexDumpIterator <
T,
107 std::is_pointer<T>::value
108 and std::is_integral<typename std::remove_pointer<T>::type>::value,
111 : std::true_type { };
115 typename = std::enable_if_t<std::is_convertible<
117 std::basic_ostream<
typename StreamT::char_type,
118 typename StreamT::traits_type>*>
::value>>
119struct IsHexDumpStream : std::true_type { };
126 typename = std::enable_if_t<detail::IsHexDumpStream<StreamT>::value>,
127 typename = std::enable_if_t<detail::IsHexDumpIterator<IteratorT>::value>>
129 std::string_view
prompt =
"")
131 constexpr auto maxelem = 1000ul * 16;
134 constexpr auto nod =
sizeof(*begin) * 2;
138 const std::string empty(
nod + 1,
' ');
140 dest << std::hex << std::setfill(
'0');
148 for (
size_t j = 0;
j < 16; ++
j) {
150 const unsigned long long ch =
static_cast<
168 const auto c =
static_cast<unsigned char>(*line);
222 typename = std::enable_if_t<detail::IsHexDumpIterator<IteratorT>::value>>
225 std::stringstream
o{ };
226 return detail::hexdump_stream(
o, begin, end,
prompt).str();
239 typename = std::enable_if_t<detail::IsHexDumpContainer<ContainerT>::value>>
242 std::stringstream
o{ };
243 return detail::hexdump_stream(
o,
cont.cbegin(),
cont.cend(),
prompt).str();
259template<
typename IteratorT,
typename ContainerT =
void*>
304 *
this = std::move(
other);
357 return detail::hexdump_stream(
os,
hdp.begin_,
hdp.end_,
hdp.prompt_);
362 std::enable_if_t<!detail::IsHexDumpContainer<ContType>::value,
int> = 0
364 void regenerate_iterators()
noexcept
372 std::enable_if_t<detail::IsHexDumpContainer<ContType>::value,
int> = 0
374 void regenerate_iterators()
noexcept
424 typename = std::enable_if_t<detail::IsHexDumpIterator<IteratorT>::value>>
428 return { begin, end, std::move(
prompt),
nullptr };
440 typename = std::enable_if_t<detail::IsHexDumpContainer<ContainerT>::value>>
444 return {
cont.cbegin(),
cont.cend(), std::move(
prompt),
nullptr };
456 typename = std::enable_if_t<detail::IsHexDumpContainer<ContainerT>::value,
459HexdumpParameterForward<
decltype(std::declval<ContainerT>().cbegin()),
ContainerT>
465 std::forward<ContainerT>(
cont) };
Helper object used to enable a convenient syntax to dump things to a stream.
Definition hexdump.h:260
IteratorT begin_
Iterator to begin of elements to be dumped (in iterator mode)
Definition hexdump.h:263
HexdumpParameterForward & operator=(const HexdumpParameterForward &other)
Copy assignment (automatically updates the begin_ and end_ interator members if the copied object hol...
Definition hexdump.h:311
HexdumpParameterForward(IteratorT begin_it, IteratorT end_it, std::string prompt, ContainerT &&cont)
Construct a hexdump parameter forwarder object.
Definition hexdump.h:282
IteratorT end_
Iterator past end of elements to be dumped (in iterator mode)
Definition hexdump.h:265
std::string prompt_
Possible prompt to prepend to the dump.
Definition hexdump.h:267
HexdumpParameterForward & operator=(HexdumpParameterForward &&other) noexcept
Move assignment (automatically updates the begin_ and end_ interator members if the moved-from object...
Definition hexdump.h:330
ContainerT cont_
A container with the elements to be dumped (in container/temporary mode)
Definition hexdump.h:269
HexdumpParameterForward(HexdumpParameterForward &&other) noexcept
Move constructor (automatically updates the begin_ and end_ interator members if the moved-from objec...
Definition hexdump.h:302
HexdumpParameterForward(const HexdumpParameterForward &other)
Copy constructor (automatically updates the begin_ and end_ interator members if the copied object ho...
Definition hexdump.h:296
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:354
auto constexpr bit_set(unsigned bit) noexcept -> ReturnT
Set a bit in an integral type.
Definition bit_manip.h:124
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:426
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:223
Definition of macros used internally by GUL.
Namespace gul17 contains all functions and classes of the General Utility Library.
Definition doxygen.h:29