8 #ifndef ICARUSALG_UTILITIES_BINARYDUMPUTILS_H
9 #define ICARUSALG_UTILITIES_BINARYDUMPUTILS_H
15 #include <type_traits>
20 namespace icarus::ns::util::details {
45 template <
typename Tag,
typename T,
unsigned int const Bits = (8*sizeof(T))>
48 static constexpr
unsigned int bits { Bits };
56 template <
typename T,
unsigned int const Bits = (8*sizeof(T))>
62 template <
typename T,
unsigned int const Bits = (8*sizeof(T))>
79 template <
typename Atom>
100 template <
typename T,
char Fill = '0'>
107 : data(data), field(field),
pad(
pad) {}
113 template <
unsigned int N,
char C = ' '>
122 template <
typename T>
126 template <
typename T>
133 template <
unsigned int N,
char C = ' '>
134 std::ostream& operator<< (std::ostream& out, Blanks<N, C>);
148 template <
typename T,
unsigned int Bits>
149 std::ostream& operator<< (std::ostream& out, BinObj<T, Bits>
const& data);
175 template <
typename T>
176 std::ostream& operator<< (std::ostream& out, HexObj<T>
const& data);
193 template <
typename Atom>
194 std::ostream& operator<< (std::ostream& out, HexDumper<Atom>
const& data);
197 template <
typename T>
198 std::ostream& operator<< (std::ostream& out, ZeroPadder<T>
const& data);
203 namespace icarus::ns::util {
205 template <
typename IOS>
235 template <
typename T>
253 template <std::
size_t Bits,
typename T>
291 template <
typename Atom>
293 (Atom
const* data, std::size_t
size,
unsigned int columns = 16U);
317 template <
typename T>
351 template <
typename IOS>
353 static_assert(!std::is_const_v<IOS>);
357 typename IOS::char_type
const fill;
371 template <
typename T>
373 static_assert(std::is_integral_v<T>,
"Only integral types are supported.");
376 constexpr
const char HexChars[17U] =
"0123456789ABCDEF";
379 std::size_t nibblesLeft =
sizeof(
value) * 2U;
380 while (nibblesLeft--) {
381 std::size_t
const digit = (value >> (nibblesLeft * 4U)) & 0xF;
382 out << HexChars[digit];
388 template <
unsigned int N,
char C >
389 std::ostream& icarus::ns::util::details::operator<<
392 for (
unsigned int i = 0U; i <
N; ++i) out.put(C);
398 template <
typename T,
unsigned int Bits>
399 std::ostream& icarus::ns::util::details::operator<<
402 static_assert(std::is_integral_v<T>);
403 static_assert(Bits > 0U);
405 unsigned int bitsLeft = data.bits;
406 T
mask = T{ 1 } << (bitsLeft - 1);
407 out <<
"(" << bitsLeft <<
") ";
409 out << ((data.data &
mask)?
'1':
'0');
411 if (--bitsLeft == 0)
break;
412 if ((bitsLeft & 0x03) == 0x00) out <<
' ';
419 template <
typename T>
420 std::ostream& icarus::ns::util::details::operator<<
422 {
printHex(out, data.data);
return out; }
426 template <
typename Atom>
427 std::ostream& icarus::ns::util::details::operator<<
431 static constexpr std::size_t AtomChars =
sizeof(Atom) * 2;
434 auto const printAtoms = [&out]
435 (Atom
const* ptr, Atom
const*
const ptrend, std::ptrdiff_t columns)
443 Atom
const*
cend = ptr + columns;
444 while (ptr != cend) {
450 else out << BlankAtom;
456 Atom
const* ptr = data.data;
457 Atom
const*
const ptrend = ptr + data.size;
462 auto const halfColumns = data.columns / 2;
463 while (ptr < ptrend) {
465 out <<
"\n" << std::setw(8) << ((
void*) ptr) <<
" |";
467 ptr = printAtoms(ptr, ptrend, data.columns - halfColumns);
468 if (data.columns >= 6U) out <<
' ';
469 ptr = printAtoms(ptr, ptrend, halfColumns);
481 template <
typename T>
482 std::ostream& icarus::ns::util::details::operator<<
487 return out << std::setw(data.field) << data.data;
493 template <
typename T>
497 template <std::
size_t Bits,
typename T>
499 {
return details::BinObj<T, Bits>{ std::move(
value) }; }
503 template <
typename Atom>
505 (Atom
const* data, std::size_t
size,
unsigned int columns )
506 -> details::HexDumper<Atom>
507 {
return details::HexDumper<Atom>{ data,
size, columns }; }
511 template <
typename T>
513 -> details::ZeroPadder<T>
514 {
return details::ZeroPadder<T>{ data,
field, pad }; }
519 #endif // ICARUSALG_UTILITIES_BINARYDUMPUTILS_H
An object wrapping some data (copy), with a tag type.
details::HexDumper< Atom > hexdump(Atom const *data, std::size_t size, unsigned int columns=16U)
Returns a wrapper to print the specified data in hex dump format.
std::size_t size(FixedBins< T, C > const &) noexcept
HexDumper(Atom const *data, std::size_t size, unsigned int columns=16U)
void printHex(std::ostream &out, T value)
Prints a zero-padded integral value into out.
unsigned int const columns
auto cend(FixedBins< T, C > const &) noexcept
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
constexpr mask_t< EnumType > mask(EnumType bit, OtherBits...otherBits)
Returns a mask with all specified bits set.
Holder for data to be presented in binary format (base 2).
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo W echo The symbol is a weak symbol that has not been specifically echo tagged as a weak object symbol When a weak defined symbol echo is linked with a normal defined the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo echo The symbol is a stabs symbol in an a out object file In echo this the next values printed are the stabs other field
Holder for data to be presented in hexadecimal format (base 16).
Wrapper to have data printed as hexadecimal dump.
constexpr T fourMSBmask()
Returns a bit mask of type T with the four most significant bits set.
ZeroPadder(T data, unsigned int field, char pad=Fill)
An object representing N characters of value C.
process_name largeant stream1 can override from command line with o or output physics producers generator N
details::ZeroPadder< T > zeropad(T data, unsigned int field, char pad= '0')
Returns a wrapper to print the specified data with a field width.
constexpr BitObjHolder(T data)
A wrapper padding the dump of its data with zeroes (or C).
static constexpr unsigned int bits