1

Often when writing file writers or parsers in c++, I would like to monitor the writer/parser's progress through the file as it gets written/read. To this end, I was thinking of implementing something like:

ostream_monitor my_monitor(&my_output_stream, &cout);
my_monitor << my_variable;

This would have the effect of outputting my_variable to my_output_stream, and also to cout, so I can see it.

Likewise, it'd be nice to have an input version of the same:

istream_monitor my_monitor(&my_input_stream, &cout);
my_monitor >> my_variable;

This would read the next token off of my_input_stream, and use it to set my_variable, but also output any read characters to cout, so I can see the stream as it gets read.

I could go ahead and try to make subclasses of std::istream and std::ostream which do this, but it seems like potentially a lot of engineering for a debug tool that may or may not be useful. I am therefore prompted to ask:

What do you do to monitor the progress of a parser through a file? I am interested in hearing any solutions that seem simpler to implement than the one above.

SuperElectric
  • 17,548
  • 10
  • 52
  • 69

1 Answers1

1

Seems like boost.IOStreams' tee_device, and possibly tee_filter, can be used to quickly implement what I describe above: How can I compose output streams, so output goes multiple places at once?

Community
  • 1
  • 1
SuperElectric
  • 17,548
  • 10
  • 52
  • 69