implemented fdinbuf and fdistream

This commit is contained in:
Bob Polis 2020-02-22 21:18:53 +01:00
parent 7bcf15bd28
commit 250e5cbf46
2 changed files with 47 additions and 3 deletions

View File

@ -7,3 +7,29 @@
//
#include "libscio.hpp"
#ifdef _MSC_VER
#include <io.h>
#else
#include <unistd.h>
#endif
using namespace sc::io;
std::streambuf::int_type fdinbuf::uflow() {
return _ch;
}
std::streambuf::int_type fdinbuf::underflow() {
char c;
int num = read(_fd, &c, 1);
if (num <= 0) {
_ch = EOF;
}
_ch = c;
return _ch;
}
std::streamsize fdinbuf::xsgetn(char* s, std::streamsize n) {
return read(_fd, s, n);
}

View File

@ -32,26 +32,44 @@ namespace sc {
class fdostream : public std::ostream {
public:
fdostream(int fd) : std::ostream(&_buf), _buf(fd) {}
fdostream(int fd) : std::ostream(&_outbuf), _outbuf(fd) {}
protected:
fdoutbuf _buf;
fdoutbuf _outbuf;
};
class fdinbuf : public std::streambuf {
public:
fdinbuf(int fd) : _fd(fd) {}
protected:
int _fd;
int_type _ch {EOF};
int_type uflow() override;
int_type underflow() override;
std::streamsize xsgetn(char* s, std::streamsize n) override;
};
class fdistream : public std::istream {
public:
fdistream(int fd) : std::istream(&_inbuf), _inbuf(fd) {}
protected:
fdinbuf _inbuf;
};
class fdstream : public fdostream, public fdistream {
public:
fdstream(int fd) : fdostream(fd), fdistream(fd) {}
};
class socketstream : public fdstream {
public:
socketstream(int fd) : fdstream(fd) {}
//void make_server(const std::string& address, int port);
//void connect(const std::string& address, int port);
};
struct float_80 {