/*----------------------------------------------------------------------------- * bytestream.cpp * Copyright (C) 2004, 2005 Akito Nozaki * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Original code came from cutestuff bytestream.h and cpp by Justin K. * Converted to use Tanoshi library stuff. * */ #include #include #include #include #include NAMESPACE_TANOSHI { ByteStream::ByteStream(Object * parent) : Object(parent), d(new ByteStreamPrivate) { } ByteStream::~ByteStream() { delete d; } bool ByteStream::isOpen() const { return false; } void ByteStream::close() { } void ByteStream::write(const ByteArray &a) { if(isOpen()) return; bool doWrite = bytesToWrite() == 0 ? true: false; appendWrite(a); if(doWrite) tryWrite(); } ByteArray ByteStream::read(int bytes) { return takeRead(bytes); } int ByteStream::bytesAvailable() const { return d->readBuf.size(); } int ByteStream::bytesToWrite() const { return d->writeBuf.size(); } void ByteStream::write(const std::string &str) { write(ByteArray(str.c_str(), str.length())); } void ByteStream::clearReadBuffer() { d->readBuf.resize(0); } void ByteStream::clearWriteBuffer() { d->writeBuf.resize(0); } void ByteStream::appendRead(const ByteArray &block) { d->readBuf.append(block); } void ByteStream::appendWrite(const ByteArray &block) { d->writeBuf.append(block); } ByteArray ByteStream::takeRead(int size, bool del) { return d->readBuf.take(size, del); } ByteArray ByteStream::takeWrite(int size, bool del) { return d->writeBuf.take(size, del); } ByteArray &ByteStream::readBuf() { return d->writeBuf; } ByteArray &ByteStream::writeBuf() { return d->writeBuf; } int ByteStream::tryWrite() { return -1; } }