46 lines
710 B
C++
46 lines
710 B
C++
//
|
|
// fdostream.hpp
|
|
// libscio
|
|
//
|
|
// Created by Bob Polis at 2020-02-14
|
|
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
|
//
|
|
|
|
#ifndef _fdostream_H_
|
|
#define _fdostream_H_
|
|
|
|
#include <iostream>
|
|
#include <streambuf>
|
|
#include <cstdio>
|
|
|
|
namespace sc {
|
|
|
|
namespace io {
|
|
|
|
class fdoutbuf: public std::streambuf {
|
|
public:
|
|
fdoutbuf(int fd): _fd(fd) {}
|
|
|
|
private:
|
|
int _fd;
|
|
|
|
int_type overflow(int_type c) override;
|
|
std::streamsize xsputn(const char* s, std::streamsize num) override;
|
|
};
|
|
|
|
class fdostream : public std::ostream {
|
|
public:
|
|
fdostream(int fd) : std::ostream(nullptr), _buf(fd) {
|
|
rdbuf(&_buf);
|
|
}
|
|
|
|
private:
|
|
fdoutbuf _buf;
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // _fdostream_H_
|