diff options
author | Tom Tromey <tom@tromey.com> | 2022-04-05 07:44:59 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-04-05 14:46:14 -0600 |
commit | c269d90a4905f313c538ed1caf182b8d48ff1f30 (patch) | |
tree | 54dd3c55151325710c29f0be05d74611caf22ca3 /gdb/ui-file.h | |
parent | 4815d6125ec580cc02a1094d61b8c9d1cc83c0a1 (diff) | |
download | fsf-binutils-gdb-c269d90a4905f313c538ed1caf182b8d48ff1f30.zip fsf-binutils-gdb-c269d90a4905f313c538ed1caf182b8d48ff1f30.tar.gz fsf-binutils-gdb-c269d90a4905f313c538ed1caf182b8d48ff1f30.tar.bz2 |
Introduce wrapped_file
Simon pointed out that timestamped_file probably needed to implement a
few more methods. This patch introduces a new file-wrapping file that
forwards most of its calls, making it simpler to implement new such
files. It also converts timestamped_file and pager_file to use it.
Regression tested on x86-64 Fedora 34.
Diffstat (limited to 'gdb/ui-file.h')
-rw-r--r-- | gdb/ui-file.h | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/gdb/ui-file.h b/gdb/ui-file.h index bffdeaa..4c9ce1a 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -391,32 +391,74 @@ public: } }; -/* A ui_file that optionally puts a timestamp at the start of each - line of output. */ +/* A base class for ui_file types that wrap another ui_file. */ -class timestamped_file : public ui_file +class wrapped_file : public ui_file { public: - explicit timestamped_file (ui_file *stream) - : m_stream (stream) - { - } + + bool isatty () override + { return m_stream->isatty (); } + + bool term_out () override + { return m_stream->term_out (); } bool can_emit_style_escape () override { return m_stream->can_emit_style_escape (); } + void flush () override + { m_stream->flush (); } + + void wrap_here (int indent) override + { m_stream->wrap_here (indent); } + + void emit_style_escape (const ui_file_style &style) override + { m_stream->emit_style_escape (style); } + + /* Rest the current output style to the empty style. */ + void reset_style () override + { m_stream->reset_style (); } + + int fd () const override + { return m_stream->fd (); } + + void puts_unfiltered (const char *str) override + { m_stream->puts_unfiltered (str); } + void write_async_safe (const char *buf, long length_buf) override { return m_stream->write_async_safe (buf, length_buf); } +protected: + + /* Note that this class does not assume ownership of the stream. + However, a subclass may choose to, by adding a 'delete' to its + destructor. */ + explicit wrapped_file (ui_file *stream) + : m_stream (stream) + { + } + + /* The underlying stream. */ + ui_file *m_stream; +}; + +/* A ui_file that optionally puts a timestamp at the start of each + line of output. */ + +class timestamped_file : public wrapped_file +{ +public: + explicit timestamped_file (ui_file *stream) + : wrapped_file (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; }; |