2

I am looking for a library - or a piece-of-a-library - for printing the contents of arrays of elements of simple types to an output stream. Its basic use is debugging code which processes very large vectors (of ints, floats, doubles, chars) - I want to be able to inspect the output to figure out what's wrong, when its wrong. The printout should basically be similar to what the od utility does, but with a lot more bells and whistles:

  • A configurable number elements per line.
  • Optional row 'headers' (index of first element in row)
  • Optional row Column 'header' (index delta from the base row index)
  • Configurable 'adornments' - borders, spaces, coloring etc.
  • Ability to only show a specified segment of the array
  • Ability to lay out some header information nicely (e.g. wrap it at same length as table)
  • Ability to print only a specified subrange(s) of the array (like the Print only These Pages dialog option in LibreOffice Writer / MS Word)
  • Ability to display those elements (or lines) whose values match certain patterns
  • Ability to account for terminal width (wrapping, auto-selecting elements per line, auto-selecting number of digits etc.)
  • Relatively easy-to-use API; if I have to jump through hoops I'd probably just write it myself.
  • Support for Escaping characters
  • Support for multiple character sets (e.g. ASCII and UCS-16, say).
  • Some kind of colorization support when printing to an actual console.

Not all of those are required, but the more of those there are, the better.

This kind of functionality seems very trivial, I'm sure it's been (re)implemented a zillion times. The question is - where?

PS - A C-language library might do but I'd rather find something C++ish.

  • It has been implemented lots of times - in just about every debuggers data view control. – Steve Barnes Nov 22 '15 at 7:17
  • @SteveBarnes: So, you're suggesting I look at the sources of gdb and lldb? – einpoklum - reinstate Monica Nov 22 '15 at 9:05
  • If you have to build the functionality, permanently into your code - otherwise just run under a debugger while you are trying to address issues. – Steve Barnes Nov 22 '15 at 13:32
  • @SteveBarnes: I do have to build it; We're talking about a situation in which I don't know when something will show up in memory; and I need to dump multiple arrays; and then I want to be able to grep a bunch of things in the dump, etc. etc. Anyway, do you have more specific directions or should I just rummage through the sources? – einpoklum - reinstate Monica Nov 22 '15 at 17:02
  • @SteveBarnes: So, gdb has this as part of its overall internal reflection system, which means unless I borrow it entirely I don't get much. – einpoklum - reinstate Monica Dec 22 '15 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.