1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
// This file may be redistributed and modified only under the terms of
// the GNU Lesser General Public License (See COPYING for details).
// Copyright (C) 2000 Michael Day
#include <Atlas/Filter.h>
namespace Atlas {
Filter::Filter(Filter* next)
: m_next(next)
{
}
Filter::~Filter()
{
delete m_next;
}
filterbuf::~filterbuf()
{
sync();
}
int_type filterbuf::overflow(int_type c)
{
if (c != EOF) {
*pptr() = (char) c;
pbump(1);
}
if (flushOutBuffer() == EOF) {
return EOF;
}
return c;
}
int_type filterbuf::underflow()
{
if (gptr() < egptr()) return *gptr();
int numPutback = gptr() - eback();
if (numPutback > m_inPutback) numPutback = m_inPutback;
std::memcpy(m_outBuffer + (m_inPutback - numPutback),
gptr() - numPutback,
(unsigned long) numPutback);
int num;
// FIXME
// Here we need to actually
// * get data from m_streamBuffer
// * encode it with m_filter
// * put _that_ into the buffer
//
// Currently it just fetches it and places it straight in the
// buffer.
// The problem is the limited size of the buffer with the
// Filter::decode operation not having any kind of size
// limitation.
num = m_streamBuffer.sgetn(m_inBuffer + m_inPutback,
m_inBufferSize - m_inPutback);
if (num <= 0) return EOF;
setg(m_inBuffer + (m_inPutback - numPutback),
m_inBuffer + m_inPutback,
m_inBuffer + m_inPutback + num);
return *gptr();
}
int filterbuf::sync()
{
if (flushOutBuffer() == EOF) return -1;
return 0;
}
} // namespace Atlas
|