Files
libscio/src/fdistream.hpp
Bob Polis 8bfa172675 Split sources, made separate headers
Makefile will autogenerate library header, excluding lines containing "@exclude"
2022-12-14 16:58:05 +01:00

38 lines
1.0 KiB
C++

#ifndef FDISTREAM_H_
#define FDISTREAM_H_
#include <iostream>
#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_