]> git.tdb.fi Git - libs/core.git/blob - source/io/console.h
Add move semantics to Variant
[libs/core.git] / source / io / console.h
1 #ifndef MSP_IO_CONSOLE_H_
2 #define MSP_IO_CONSOLE_H_
3
4 #include <msp/core/mspcore_api.h>
5 #include "eventobject.h"
6 #include "handle.h"
7
8 namespace Msp {
9 namespace IO {
10
11 /**
12 Provides access to standard input, output and error streams.  This class can't
13 be instantiated directly - use one of the cin, cout and cerr references
14 instead.
15 */
16 class MSPCORE_API Console: public EventObject
17 {
18 public:
19         enum Stream
20         {
21                 CIN = 0,
22                 COUT = 1,
23                 CERR = 2
24         };
25
26 private:
27         Stream stream;
28         Handle handle;
29
30         Console(Stream);
31         void platform_init();
32 public:
33         ~Console();
34
35         void set_block(bool) override;
36         void set_inherit(bool) override;
37         
38         /** If local echo is enabled, characters will appear on the console as they
39         are typed.  Can only be used on an input Console.  */
40         void set_local_echo(bool);
41
42         /** If line buffering is enabled, input will only be available when a
43         newline is encountered.  On some systems, this may also enable line editing.
44         Can only be used on an input Console.
45         */
46         void set_line_buffer(bool);
47
48         /** Retrieves the size of the Console.  Can only be used on an output
49         Console. */
50         void get_size(unsigned &rows, unsigned &cols);
51
52         /** Redirects input from or output to another I/O object.  This performs a
53         system-level redirect.  Closing the other object won't affect the
54         redirection. */
55         void redirect(Base &);
56
57 protected:
58         std::size_t do_write(const char *, std::size_t) override;
59         std::size_t do_read(char *, std::size_t) override;
60
61 public:
62         const Handle &get_handle(Mode) override;
63         const Handle &get_event_handle() override { return handle; }
64
65         static Console &instance(Stream);
66 };
67
68 // TODO make these inline instead of static when upgrading to C++17.
69 static Console &cin = Console::instance(Console::CIN);
70 static Console &cout = Console::instance(Console::COUT);
71 static Console &cerr = Console::instance(Console::CERR);
72
73 } // namespace IO
74 } // namespace Msp
75
76 #endif