/* A ui_file that implements output paging and unfiltered output. */
-class pager_file : public wrapped_file
+class pager_file : public wrapped_file<ui_file_up>
{
public:
/* Create a new pager_file. The new object takes ownership of
STREAM. */
- explicit pager_file (ui_file *stream)
- : wrapped_file (stream)
+ explicit pager_file (ui_file_up stream)
+ : wrapped_file (std::move (stream))
{
}
- ~pager_file ()
- {
- delete m_stream;
- }
-
DISABLE_COPY_AND_ASSIGN (pager_file);
void write (const char *buf, long length_buf) override;
#endif
/* Create tui output streams. */
- tui_stdout = new pager_file (new tui_file (stdout, true));
+ tui_stdout = new pager_file (std::make_unique<tui_file> (stdout, true));
tui_stderr = new tui_file (stderr, false);
tui_stdlog = new timestamped_file (tui_stderr);
tui_out = new cli_ui_out (tui_stdout, 0);
void do_write (const char *buf, long len) override;
};
-/* A base class for ui_file types that wrap another ui_file. */
+/* A base class for ui_file types that wrap another ui_file. The
+ precise underlying ui_file type is a template parameter, so that
+ either owning or non-owning wrappers can be made. */
+template<typename T>
class wrapped_file : public ui_file
{
public:
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)
+ explicit wrapped_file (T stream)
+ : m_stream (std::move (stream))
{
}
/* The underlying stream. */
- ui_file *m_stream;
+ T m_stream;
};
/* A ui_file that optionally puts a timestamp at the start of each
line of output. */
-class timestamped_file : public wrapped_file
+class timestamped_file : public wrapped_file<ui_file *>
{
public:
explicit timestamped_file (ui_file *stream)
Note that this only really handles ASCII output correctly. */
-class tab_expansion_file : public wrapped_file
+class tab_expansion_file : public wrapped_file<ui_file *>
{
public:
errstream (errstream_),
input_fd (fileno (instream)),
m_input_interactive_p (ISATTY (instream)),
- m_gdb_stdout (new pager_file (new stdio_file (outstream))),
+ m_gdb_stdout (new pager_file (std::make_unique<stdio_file> (outstream))),
m_gdb_stdin (new stdio_file (instream)),
m_gdb_stderr (new stderr_file (errstream)),
m_gdb_stdlog (new timestamped_file (m_gdb_stderr)),
test_pager ()
{
string_file *strfile = new string_file ();
- pager_file pager (strfile);
+ pager_file pager { ui_file_up (strfile) };
/* Make sure the pager is disabled. */
scoped_restore save_enabled