Add new timestamped_file class

This adds a "timestamped_file" subclass of ui_file.  This class adds a
timestamp to its output when appropriate.  That is, it follows the
rule already used in vfprintf_unfiltered of adding a timestamp at most
once per write.

The new class is not yet used.
This commit is contained in:
Tom Tromey 2021-12-31 11:44:19 -07:00
parent 8b1931b394
commit 3c6c449e30
4 changed files with 57 additions and 1 deletions

View file

@ -364,4 +364,28 @@ public:
void puts (const char *linebuffer) override;
};
/* A ui_file that optionally puts a timestamp at the start of each
line of output. */
class timestamped_file : public ui_file
{
public:
explicit timestamped_file (ui_file *stream)
: m_stream (stream)
{
}
DISABLE_COPY_AND_ASSIGN (timestamped_file);
void write (const char *buf, long len) override;
private:
/* Output is sent here. */
ui_file *m_stream;
/* True if the next output should be timestamped. */
bool m_needs_timestamp = true;
};
#endif