libscio/fdstream.cpp

89 lines
1.8 KiB
C++

//
// fdstream.cpp
// libscio
//
// Created by Bob Polis at 2020-04-25
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "libscio.hpp"
#include <unistd.h>
// fdostream --------------------------------------------------------------
sc::io::fdostream::~fdostream() {
close();
}
void sc::io::fdostream::close() {
if (_outbuf.fd() != -1) {
::close(_outbuf.fd());
_outbuf.fd(-1);
}
}
sc::io::fdostream::fdostream(sc::io::fdostream&& other) : std::ostream(&_outbuf) {
_outbuf.fd(other._outbuf.fd());
other._outbuf.fd(-1);
}
sc::io::fdostream& sc::io::fdostream::operator=(sc::io::fdostream&& other) {
if (this != &other) {
_outbuf.fd(other._outbuf.fd());
other._outbuf.fd(-1);
}
return *this;
}
// fdistream --------------------------------------------------------------
sc::io::fdistream::~fdistream() {
close();
}
void sc::io::fdistream::close() {
if (_inbuf.fd() != -1) {
::close(_inbuf.fd());
_inbuf.fd(-1);
}
}
sc::io::fdistream::fdistream(sc::io::fdistream&& other) : std::istream(&_inbuf) {
_inbuf.fd(other._inbuf.fd());
other._inbuf.fd(-1);
}
sc::io::fdistream& sc::io::fdistream::operator=(sc::io::fdistream&& other) {
if (this != &other) {
_inbuf.fd(other._inbuf.fd());
other._inbuf.fd(-1);
}
return *this;
}
// fdstream ---------------------------------------------------------------
sc::io::fdstream::~fdstream() {
close();
}
void sc::io::fdstream::close() {
if (_iobuf.fd() != -1) {
::close(_iobuf.fd());
_iobuf.fd(-1);
}
}
sc::io::fdstream::fdstream(sc::io::fdstream&& other) : std::iostream(&_iobuf) {
_iobuf.fd(other._iobuf.fd());
other._iobuf.fd(-1);
}
sc::io::fdstream& sc::io::fdstream::operator=(sc::io::fdstream&& other) {
if (this != &other) {
_iobuf.fd(other._iobuf.fd());
other._iobuf.fd(-1);
}
return *this;
}