4 #include <sigc++/sigc++.h>
13 Common interface for all I/O objects.
15 A derived class must call set_events(P_NONE) before it is destroyed to avoid
16 leaving stale pointers in an EventDispatcher.
21 /** Emitted when there is no more data to be read. */
22 sigc::signal<void> signal_end_of_file;
24 /** Emitted when there is a nonlinearity in I/O (such as a file being
25 seeked) and any data buffered by upper layers needs to be flushed. */
26 sigc::signal<void> signal_flush_required;
28 /** Emitted when the object is deleted. Mainly for use by
30 sigc::signal<void> signal_deleted;
39 Base &operator=(const Base &);
43 /** Sets blocking mode. When blocking is enabled, most operations won't
44 return until they can make progress. When blocking is disabled, these
45 operations may return immediately with a return code indicating that nothing
48 Blocking is enabled by default. */
49 virtual void set_block(bool) { }
51 /** Returns the current mode flags. */
52 Mode get_mode() const { return mode; }
55 void check_access(Mode) const;
57 virtual unsigned do_write(const char *, unsigned) = 0;
58 virtual unsigned do_read(char *, unsigned) = 0;
61 /** Writes data from a buffer. Subject to blocking. Returns the number of
62 bytes written, which may be zero for a non-blockin operation. */
63 unsigned write(const char *b, unsigned c) { return do_write(b, c); }
65 /** Writes a string. This is identical to calling
66 write(s.data(), s.size()). */
67 unsigned write(const std::string &s) { return do_write(s.data(), s.size()); }
69 /** Writes a single character. This is identical to calling
71 virtual unsigned put(char c) { return do_write(&c, 1); }
73 /** Reads data into a buffer. Subject to blocking. Returns the number of
74 bytes read, which may be zero for a non-blocking operation. */
75 unsigned read(char *b, unsigned c) { return do_read(b, c); }
77 /** Reads characters up to the next linefeed or end-of-file. The linefeed
78 is not included in the line. Returns true if a line was successfully read,
80 virtual bool getline(std::string &);
82 /** Reads a single character. Returns -1 if no character was available due
83 to end-of-file or non-blocking operation. */
90 /** Returns the end-of-file flag. */
91 bool eof() const { return eof_flag; }
93 /** Returns the system-level handle for the object. Used by Console to
94 perform redirections. */
95 virtual const Handle &get_handle(Mode);