From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 8A51E3858C50; Tue, 5 Apr 2022 20:55:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A51E3858C50 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Introduce wrapped_file X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 4815d6125ec580cc02a1094d61b8c9d1cc83c0a1 X-Git-Newrev: c269d90a4905f313c538ed1caf182b8d48ff1f30 Message-Id: <20220405205523.8A51E3858C50@sourceware.org> Date: Tue, 5 Apr 2022 20:55:23 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Apr 2022 20:55:23 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc269d90a4905= f313c538ed1caf182b8d48ff1f30 commit c269d90a4905f313c538ed1caf182b8d48ff1f30 Author: Tom Tromey Date: Tue Apr 5 07:44:59 2022 -0600 Introduce wrapped_file =20 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. =20 Regression tested on x86-64 Fedora 34. Diff: --- gdb/pager.h | 32 +++++++----------------------- gdb/ui-file.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++------= ---- 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/gdb/pager.h b/gdb/pager.h index 0151a283629..d2a3a2b8ec8 100644 --- a/gdb/pager.h +++ b/gdb/pager.h @@ -23,16 +23,21 @@ =20 /* A ui_file that implements output paging and unfiltered output. */ =20 -class pager_file : public ui_file +class pager_file : public wrapped_file { public: /* Create a new pager_file. The new object takes ownership of STREAM. */ explicit pager_file (ui_file *stream) - : m_stream (stream) + : wrapped_file (stream) { } =20 + ~pager_file () + { + delete m_stream; + } + DISABLE_COPY_AND_ASSIGN (pager_file); =20 void write (const char *buf, long length_buf) override; @@ -44,31 +49,11 @@ public: m_stream->write_async_safe (buf, length_buf); } =20 - bool term_out () override - { - return m_stream->term_out (); - } - - bool isatty () override - { - return m_stream->isatty (); - } - - bool can_emit_style_escape () override - { - return m_stream->can_emit_style_escape (); - } - void emit_style_escape (const ui_file_style &style) override; void reset_style () override; =20 void flush () override; =20 - int fd () const override - { - return m_stream->fd (); - } - void wrap_here (int indent) override; =20 void puts_unfiltered (const char *str) override @@ -98,9 +83,6 @@ private: /* The style applied at the time that wrap_here was called. */ ui_file_style m_wrap_style; =20 - /* The unfiltered output stream. */ - ui_file_up m_stream; - /* This is temporarily set when paging. This will cause some methods to change their behavior to ignore the wrap buffer. */ bool m_paging =3D false; diff --git a/gdb/ui-file.h b/gdb/ui-file.h index bffdeaa28c4..4c9ce1aaa0c 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -391,32 +391,74 @@ public: } }; =20 -/* 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. */ =20 -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 (); } =20 bool can_emit_style_escape () override { return m_stream->can_emit_style_escape (); } =20 + 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); } =20 +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); =20 void write (const char *buf, long len) override; =20 private: =20 - /* Output is sent here. */ - ui_file *m_stream; - /* True if the next output should be timestamped. */ bool m_needs_timestamp =3D true; };