4 #include <sigc++/sigc++.h>
12 Common interface for all I/O objects.
14 A derived class must call set_events(P_NONE) before it is destroyed to avoid
15 leaving stale pointers in an EventDispatcher.
20 /** Emitted when there is no more data to be read. */
21 sigc::signal<void> signal_end_of_file;
23 /** Emitted when there is a nonlinearity in I/O (such as a file being
24 seeked) and any data buffered by upper layers needs to be flushed. */
25 sigc::signal<void> signal_flush_required;
27 /** Emitted when the I/O object has closed. */
28 sigc::signal<void> signal_closed;
30 /** Emitted when the object is deleted. Mainly for use by
32 sigc::signal<void> signal_deleted;
41 Base &operator=(const Base &);
45 /** Sets blocking mode. When blocking is enabled, most operations won't
46 return until they can make progress. When blocking is disabled, these
47 operations may return immediately with a return code indicating that nothing
50 Blocking is enabled by default. */
51 virtual void set_block(bool) { }
53 /** Returns the current mode flags. */
54 Mode get_mode() const { return mode; }
57 void check_access(Mode) const;
59 virtual unsigned do_write(const char *, unsigned) = 0;
60 virtual unsigned do_read(char *, unsigned) = 0;
63 /** Writes data from a buffer. Subject to blocking. Returns the number of
64 bytes written, which may be zero for a non-blockin operation. */
65 unsigned write(const char *b, unsigned c) { return do_write(b, c); }
67 /** Writes a string. This is identical to calling
68 write(s.data(), s.size()). */
69 unsigned write(const std::string &s) { return do_write(s.data(), s.size()); }
71 /** Writes a single character. This is identical to calling
73 virtual unsigned put(char c) { return do_write(&c, 1); }
75 /** Reads data into a buffer. Subject to blocking. Returns the number of
76 bytes read, which may be zero for a non-blocking operation. */
77 unsigned read(char *b, unsigned c) { return do_read(b, c); }
79 /** Reads characters up to the next linefeed or end-of-file. The linefeed
80 is not included in the line. Returns true if a line was successfully read,
82 virtual bool getline(std::string &);
84 /** Reads a single character. Returns -1 if no character was available due
85 to end-of-file or non-blocking operation. */
92 /** Returns the end-of-file flag. */
93 bool eof() const { return eof_flag; }