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 object is deleted. Mainly for use by
29 sigc::signal<void> signal_deleted;
38 Base &operator=(const Base &);
42 /** Sets blocking mode. When blocking is enabled, most operations won't
43 return until they can make progress. When blocking is disabled, these
44 operations may return immediately with a return code indicating that nothing
47 Blocking is enabled by default. */
48 virtual void set_block(bool) { }
50 /** Returns the current mode flags. */
51 Mode get_mode() const { return mode; }
54 void check_access(Mode) const;
56 virtual unsigned do_write(const char *, unsigned) = 0;
57 virtual unsigned do_read(char *, unsigned) = 0;
60 /** Writes data from a buffer. Subject to blocking. Returns the number of
61 bytes written, which may be zero for a non-blockin operation. */
62 unsigned write(const char *b, unsigned c) { return do_write(b, c); }
64 /** Writes a string. This is identical to calling
65 write(s.data(), s.size()). */
66 unsigned write(const std::string &s) { return do_write(s.data(), s.size()); }
68 /** Writes a single character. This is identical to calling
70 virtual unsigned put(char c) { return do_write(&c, 1); }
72 /** Reads data into a buffer. Subject to blocking. Returns the number of
73 bytes read, which may be zero for a non-blocking operation. */
74 unsigned read(char *b, unsigned c) { return do_read(b, c); }
76 /** Reads characters up to the next linefeed or end-of-file. The linefeed
77 is not included in the line. Returns true if a line was successfully read,
79 virtual bool getline(std::string &);
81 /** Reads a single character. Returns -1 if no character was available due
82 to end-of-file or non-blocking operation. */
89 /** Returns the end-of-file flag. */
90 bool eof() const { return eof_flag; }