libscio/fdstream.cpp

89 lines
1.8 KiB
C++
Raw Normal View History

2020-04-25 17:42:26 +02:00
//
// 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 --------------------------------------------------------------
2020-04-25 17:42:26 +02:00
sc::io::fdostream::~fdostream() {
close();
}
void sc::io::fdostream::close() {
2020-04-25 17:42:26 +02:00
if (_outbuf.fd() != -1) {
::close(_outbuf.fd());
2020-04-25 18:13:53 +02:00
_outbuf.fd(-1);
2020-04-25 17:42:26 +02:00
}
}
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 --------------------------------------------------------------
2020-04-25 17:42:26 +02:00
sc::io::fdistream::~fdistream() {
close();
}
void sc::io::fdistream::close() {
2020-04-25 17:42:26 +02:00
if (_inbuf.fd() != -1) {
::close(_inbuf.fd());
2020-04-25 18:13:53 +02:00
_inbuf.fd(-1);
2020-04-25 17:42:26 +02:00
}
}
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 ---------------------------------------------------------------
2020-04-25 17:42:26 +02:00
sc::io::fdstream::~fdstream() {
close();
}
void sc::io::fdstream::close() {
2020-04-25 17:42:26 +02:00
if (_iobuf.fd() != -1) {
::close(_iobuf.fd());
2020-04-25 18:13:53 +02:00
_iobuf.fd(-1);
2020-04-25 17:42:26 +02:00
}
}
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;
}