]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/console.h
Add move semantics to Variant
[libs/core.git] / source / io / console.h
index 3c0bb71ff3826d23467172a8e86c28f565ae1088..fe777cc04db02e90b88df52730c5f41ec3af513d 100644 (file)
@@ -1,7 +1,9 @@
 #ifndef MSP_IO_CONSOLE_H_
 #define MSP_IO_CONSOLE_H_
 
-#include "base.h"
+#include <msp/core/mspcore_api.h>
+#include "eventobject.h"
+#include "handle.h"
 
 namespace Msp {
 namespace IO {
@@ -11,16 +13,27 @@ Provides access to standard input, output and error streams.  This class can't
 be instantiated directly - use one of the cin, cout and cerr references
 instead.
 */
-class Console: public Base
+class MSPCORE_API Console: public EventObject
 {
+public:
+       enum Stream
+       {
+               CIN = 0,
+               COUT = 1,
+               CERR = 2
+       };
+
 private:
+       Stream stream;
        Handle handle;
 
-       Console(unsigned);
+       Console(Stream);
+       void platform_init();
 public:
        ~Console();
 
-       virtual void set_block(bool);
+       void set_block(bool) override;
+       void set_inherit(bool) override;
        
        /** If local echo is enabled, characters will appear on the console as they
        are typed.  Can only be used on an input Console.  */
@@ -36,19 +49,26 @@ public:
        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);
+       std::size_t do_write(const char *, std::size_t) override;
+       std::size_t do_read(char *, std::size_t) override;
 
 public:
-       virtual Handle get_event_handle();
+       const Handle &get_handle(Mode) override;
+       const Handle &get_event_handle() override { return handle; }
 
-       static Console &instance(unsigned);
+       static Console &instance(Stream);
 };
 
-extern Console &cin;
-extern Console &cout;
-extern Console &cerr;
+// TODO make these inline instead of static when upgrading to C++17.
+static Console &cin = Console::instance(Console::CIN);
+static Console &cout = Console::instance(Console::COUT);
+static Console &cerr = Console::instance(Console::CERR);
 
 } // namespace IO
 } // namespace Msp