00001 // This file may be redistributed and modified only under the terms of 00002 // the GNU Lesser General Public License (See COPYING for details). 00003 // Copyright (C) 2000-2001 Michael Day, Stefanus Du Toit 00004 00005 #ifndef ATLAS_FILTER_H 00006 #define ATLAS_FILTER_H 00007 00008 #include <iostream> 00009 #include <string> 00010 00011 namespace Atlas { 00012 00027 class Filter 00028 { 00029 public: 00030 00031 Filter(Filter* = 0); 00032 virtual ~Filter(); 00033 00034 virtual void begin() = 0; 00035 virtual void end() = 0; 00036 00037 virtual std::string encode(const std::string&) = 0; 00038 virtual std::string decode(const std::string&) = 0; 00039 00040 enum Type 00041 { 00042 CHECKSUM, 00043 COMPRESSION, 00044 ENCRYPTION 00045 }; 00046 00047 protected: 00048 00049 Filter* m_next; 00050 }; 00051 00052 typedef int int_type; 00053 00054 class filterbuf : public std::streambuf { 00055 00056 public: 00057 00058 filterbuf(std::streambuf& buffer, 00059 Filter& filter) 00060 : m_streamBuffer(buffer), m_filter(filter) 00061 { 00062 setp(m_outBuffer, m_outBuffer + (m_outBufferSize - 1)); 00063 setg(m_inBuffer + m_inPutback, m_inBuffer + m_inPutback, 00064 m_inBuffer + m_inPutback); 00065 } 00066 00067 virtual ~filterbuf(); 00068 00069 protected: 00070 static const int m_outBufferSize = 10; 00071 char m_outBuffer[m_outBufferSize]; 00072 00073 static const int m_inBufferSize = 10; 00074 static const int m_inPutback = 4; 00075 char m_inBuffer[m_inBufferSize]; 00076 00077 int flushOutBuffer() 00078 { 00079 int num = pptr() - pbase(); 00080 std::string encoded = m_filter.encode(std::string(pbase(), pptr())); 00081 m_streamBuffer.sputn(encoded.c_str(), (long) encoded.size()); 00082 pbump(-num); 00083 return num; 00084 } 00085 00086 virtual int_type overflow(int_type c); 00087 virtual int_type underflow(); 00088 virtual int sync(); 00089 00090 private: 00091 00092 std::streambuf& m_streamBuffer; 00093 Filter& m_filter; 00094 }; 00095 00096 } // Atlas namespace 00097 00098 #endif
Copyright 2000-2004 the respective authors.
This document can be licensed under the terms of the GNU Free Documentation License or the GNU General Public License and may be freely distributed under the terms given by one of these licenses.