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.
22 Emitted when there is data available for reading. If all data is not read,
23 the signal is emitted again immediately.
25 sigc::signal<void> signal_data_available;
28 Emitted when there is no more data to be read.
30 sigc::signal<void> signal_end_of_file;
33 Emitted when there is a nonlinearity in I/O (such as a file being seeked)
34 and any data buffered by upper layers needs to be flushed.
36 sigc::signal<void> signal_flush_required;
39 Emitted when the I/O object has closed.
41 sigc::signal<void> signal_closed;
44 Emitted when the mask of interesting events changes. Mainly for use by
47 sigc::signal<void, PollEvent> signal_events_changed;
50 Emitted when the object is deleted. Mainly for use by EventDispatcher.
52 sigc::signal<void> signal_deleted;
55 Sets blocking mode. When blocking is enabled, most operations won't return
56 until they can make progress. When blocking is disabled, these operations
57 may return immediately with a return code indicating that nothing was done.
59 Blocking is enabled by default.
61 virtual void set_block(bool) { }
64 Returns the current mode flags.
66 Mode get_mode() const { return mode; }
69 Writes data from a buffer. Subject to blocking.
71 @param b Buffer to write from
72 @param c Number of bytes to write
74 @return Number of bytes written
76 unsigned write(const char *b, unsigned c) { return do_write(b, c); }
79 Writes a string. This is identical to calling write(s.data(), s.size()).
81 unsigned write(const std::string &s) { return do_write(s.data(), s.size()); }
84 Writes a single character. This is identical to calling write(&c, 1).
86 virtual unsigned put(char c) { return do_write(&c, 1); }
89 Reads data into a buffer. Subject to blocking.
91 @param b Buffer to read into
92 @param c Maximum number of bytes to read
94 @return Number of bytes read
96 unsigned read(char *b, unsigned c) { return do_read(b, c); }
99 Reads characters up to the next linefeed or end-of-file. The linefeed is not
100 included in the line.
102 @param line String to put the characters into
104 @return Whether anything was read
106 virtual bool getline(std::string &);
109 Reads a single character.
111 @return A character, or -1 if none were available
116 Returns the end-of-file flag.
118 bool eof() const { return eof_flag; }
121 Returns a mask of the currently interesting events. Used by EventDispatcher.
123 PollEvent get_events() const { return events; }
126 Returns a handle for polling. Should throw if the object does not have an
129 virtual Handle get_event_handle() =0;
132 Notifies the object of an event. Used by EventDispatcher.
134 void event(PollEvent);
143 void set_events(PollEvent);
144 virtual void on_event(PollEvent) { }
145 virtual unsigned do_write(const char *, unsigned) =0;
146 virtual unsigned do_read(char *, unsigned) =0;
149 Base &operator=(const Base &);