All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions
icarus::ns::util::details Namespace Reference

Classes

struct  BitObjHolder
 An object wrapping some data (copy), with a tag type. More...
 
struct  BinObjTag
 Tag object for BinObj. More...
 
struct  BinObj
 Holder for data to be presented in binary format (base 2). More...
 
struct  HexObjTag
 
struct  HexObj
 Holder for data to be presented in hexadecimal format (base 16). More...
 
struct  HexDumper
 Wrapper to have data printed as hexadecimal dump. More...
 
struct  ZeroPadder
 A wrapper padding the dump of its data with zeroes (or C). More...
 
struct  Blanks
 An object representing N characters of value C. More...
 

Functions

template<typename T >
constexpr T fourMSBmask ()
 Returns a bit mask of type T with the four most significant bits set. More...
 
template<typename T >
void printHex (std::ostream &out, T value)
 Prints a zero-padded integral value into out. More...
 
template<unsigned int N, char C = ' '>
std::ostream & operator<< (std::ostream &out, Blanks< N, C >)
 Dumps N characters of value C to out stream. More...
 
template<typename T , unsigned int Bits>
std::ostream & operator<< (std::ostream &out, BinObj< T, Bits > const &data)
 Dumps data bit by bit into out stream. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &out, HexObj< T > const &data)
 Dumps data nibble by nibble into out stream. More...
 
template<typename Atom >
std::ostream & operator<< (std::ostream &out, HexDumper< Atom > const &data)
 Dumps data in a hexadecimal table. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &out, ZeroPadder< T > const &data)
 Dumps a value padding with 0 via ZeroPadder wrapper. More...
 

Function Documentation

template<typename T >
constexpr T icarus::ns::util::details::fourMSBmask ( )

Returns a bit mask of type T with the four most significant bits set.

template<unsigned int N, char C = ' '>
std::ostream & icarus::ns::util::details::operator<< ( std::ostream &  out,
Blanks< N, C >   
)

Dumps N characters of value C to out stream.

Definition at line 390 of file BinaryDumpUtils.h.

391 {
392  for (unsigned int i = 0U; i < N; ++i) out.put(C);
393  return out;
394 } // icarus::ns::util::details::operator<< (icarus::ns::util::details::Blanks)
process_name largeant stream1 can override from command line with o or output physics producers generator N
template<typename T , unsigned int Bits>
std::ostream & icarus::ns::util::details::operator<< ( std::ostream &  out,
BinObj< T, Bits > const &  data 
)

Dumps data bit by bit into out stream.

Parameters
outoutput stream
datadata wrapper with information on how many bits to dump
Returns
the output stream out

Parameters of the dump are read from the data wrapper. The dump is in format (Bits) bbb bbbb bbbb ... (Bits is the number of bits, and b are bit values, 0 or 1, the first being the most significant bit).

Definition at line 400 of file BinaryDumpUtils.h.

401 {
402  static_assert(std::is_integral_v<T>);
403  static_assert(Bits > 0U);
404 
405  unsigned int bitsLeft = data.bits;
406  T mask = T{ 1 } << (bitsLeft - 1);
407  out << "(" << bitsLeft << ") ";
408  while (mask) {
409  out << ((data.data & mask)? '1': '0');
410  mask >>= 1;
411  if (--bitsLeft == 0) break;
412  if ((bitsLeft & 0x03) == 0x00) out << ' ';
413  } // while
414  return out;
415 } // icarus::ns::util::details::operator<< (icarus::ns::util::details::BinObj)
constexpr mask_t< EnumType > mask(EnumType bit, OtherBits...otherBits)
Returns a mask with all specified bits set.
template<typename T >
std::ostream & icarus::ns::util::details::operator<< ( std::ostream &  out,
HexObj< T > const &  data 
)

Dumps data nibble by nibble into out stream.

Parameters
outoutput stream
datadata wrapper
Returns
the output stream out

The value in data is printed in hexadecimal format, including all its bits. The STL std::hex mode of a stream may be more convenient, but it's sticky:

using namespace icarus::ns::util;
std::cout << 36 << std::endl; // "36"
std::cout << details::HexObj{ 36 } << std::endl; // 00000024
std::cout << 36 << std::endl; // "36"
std::cout << std::hex << 36 << std::endl; // "24"
std::cout << 36 << std::endl; // "24" (std::hex is sticky)

Parameters of the dump are read from the data wrapper. The dump is in format (Bits) bbb bbbb bbbb ... (Bits is the number of bits, and b are bit values, 0 or 1, the first being the most significant bit).

Definition at line 421 of file BinaryDumpUtils.h.

422  { printHex(out, data.data); return out; }
void printHex(std::ostream &out, T value)
Prints a zero-padded integral value into out.
template<typename Atom >
std::ostream & icarus::ns::util::details::operator<< ( std::ostream &  out,
HexDumper< Atom > const &  data 
)

Dumps data in a hexadecimal table.

Parameters
outoutput stream
datadata wrapper with information on how to dump it
Returns
the output stream out

Wrapped data is printed in a table: address of the first Atom of data, a separator |, a sequence of as many atom values as specified in data.columns, in hexadecimal format and zero-padded, and another separator |. If there are 6 or more columns, a larger space indentation is inserted between the two central columns. The table is written on a new line, and the line is ended after the table.

Definition at line 428 of file BinaryDumpUtils.h.

429 {
430 
431  static constexpr std::size_t AtomChars = sizeof(Atom) * 2;
432  static constexpr Blanks<AtomChars> BlankAtom;
433 
434  auto const printAtoms = [&out]
435  (Atom const* ptr, Atom const* const ptrend, std::ptrdiff_t columns)
436  {
437  /*
438  FormatFlagsGuard const outGuard { out };
439  out.setf(std::ios_base::hex, std::ios_base::basefield);
440  out.unsetf(std::ios_base::showbase);
441  out.fill('0');
442  */
443  Atom const* cend = ptr + columns;
444  while (ptr != cend) {
445  out << ' ';
446  if (ptr < ptrend) {
447  // out << std::setw(AtomChars) << *ptr;
448  printHex(out, *ptr);
449  }
450  else out << BlankAtom;
451  ++ptr;
452  } // while
453  return ptr;
454  };
455 
456  Atom const* ptr = data.data;
457  Atom const* const ptrend = ptr + data.size;
458 
459  FormatFlagsGuard const outGuard { out };
460  out.fill('0');
461 
462  auto const halfColumns = data.columns / 2;
463  while (ptr < ptrend) {
464 
465  out << "\n" << std::setw(8) << ((void*) ptr) << " |";
466 
467  ptr = printAtoms(ptr, ptrend, data.columns - halfColumns);
468  if (data.columns >= 6U) out << ' ';
469  ptr = printAtoms(ptr, ptrend, halfColumns);
470  out << " |";
471 
472  } // while
473 
474  out << '\n';
475 
476  return out;
477 } // operator<< (HexDumper)
void printHex(std::ostream &out, T value)
Prints a zero-padded integral value into out.
auto cend(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:579
template<typename T >
std::ostream & icarus::ns::util::details::operator<< ( std::ostream &  out,
ZeroPadder< T > const &  data 
)

Dumps a value padding with 0 via ZeroPadder wrapper.

Definition at line 483 of file BinaryDumpUtils.h.

484 {
485  FormatFlagsGuard ffg { out };
486  out.fill(data.pad);
487  return out << std::setw(data.field) << data.data;
488 } // icarus::ns::util::details::operator<< (ZeroPadder)
template<typename T >
void icarus::ns::util::details::printHex ( std::ostream &  out,
value 
)

Prints a zero-padded integral value into out.

Definition at line 372 of file BinaryDumpUtils.h.

372  {
373  static_assert(std::is_integral_v<T>, "Only integral types are supported.");
374 
375  // we actually store the null character at the end; it does not really matter
376  constexpr const char HexChars[17U] = "0123456789ABCDEF";
377 
378  // print nibble by nibble, no spaces, starting from the most significant
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];
383  } // while
384 } // icarus::ns::util::details::printHex()
temporary value