#ifndef FDISTREAM_H_ #define FDISTREAM_H_ #include #include "fdiobuf.hpp" // @exclude namespace sc { namespace io { class fdistream : public std::istream { public: fdistream() : std::istream(&_inbuf), _inbuf(-1) {} fdistream(int fd) : std::istream(&_inbuf), _inbuf(fd) {} // no copying fdistream(const fdistream&) = delete; fdistream& operator=(const fdistream&) = delete; // moving allowed fdistream(fdistream&& other); fdistream& operator=(fdistream&& other); // cleanup: fdistream is RAII class for open file descriptor virtual ~fdistream(); int fd() const { return _inbuf.fd(); } void fd(int fd) { _inbuf.fd(fd); } bool is_open() const { return _inbuf.fd() != -1; } void close(); protected: fdiobuf _inbuf; }; } } #endif // FDISTREAM_H_