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