}
}
+const Handle &Base::get_handle(Mode)
+{
+ throw logic_error("Base::get_handle");
+}
+
} // namespace IO
} // namespace Msp
#define MSP_IO_BASE_H_
#include <sigc++/sigc++.h>
+#include "handle.h"
#include "mode.h"
#include "poll.h"
public:
/** Returns the end-of-file flag. */
bool eof() const { return eof_flag; }
+
+ /** Returns the system-level handle for the object. Used by Console to
+ perform redirections. */
+ virtual const Handle &get_handle(Mode);
};
} // namespace IO
#ifndef WIN32
#include <errno.h>
+#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#endif
}
+void Console::redirect(Base &other)
+{
+ Handle other_handle = other.get_handle(mode&M_RDWR);
+#ifdef WIN32
+ SetStdHandle(stream_to_sys(stream), *other_handle);
+#else
+ dup2(*other_handle, *handle);
+#endif
+}
+
unsigned Console::do_write(const char *buf, unsigned len)
{
check_access(M_WRITE);
Console. */
void get_size(unsigned &rows, unsigned &cols);
+ /** Redirects input from or output to another I/O object. This performs a
+ system-level redirect. Closing the other object won't affect the
+ redirection. */
+ void redirect(Base &);
+
protected:
virtual unsigned do_write(const char *, unsigned);
virtual unsigned do_read(char *, unsigned);