Atlas-C++
|
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 // $Id$ 00006 00007 #ifndef ATLAS_FILTER_H 00008 #define ATLAS_FILTER_H 00009 00010 #include <iostream> 00011 #include <string> 00012 00013 namespace Atlas { 00014 00029 class Filter 00030 { 00031 private: 00032 Filter(const Filter &); // unimplemented 00033 Filter & operator=(const Filter &); // unimplemented 00034 public: 00035 00036 Filter(Filter* = 0); 00037 virtual ~Filter(); 00038 00039 virtual void begin() = 0; 00040 virtual void end() = 0; 00041 00042 virtual std::string encode(const std::string&) = 0; 00043 virtual std::string decode(const std::string&) = 0; 00044 00045 enum Type 00046 { 00047 CHECKSUM, 00048 COMPRESSION, 00049 ENCRYPTION 00050 }; 00051 00052 protected: 00053 00054 Filter* m_next; 00055 }; 00056 00057 typedef int int_type; 00058 00059 class filterbuf : public std::streambuf { 00060 00061 public: 00062 00063 filterbuf(std::streambuf& buffer, 00064 Filter& filter) 00065 : m_streamBuffer(buffer), m_filter(filter) 00066 { 00067 setp(m_outBuffer, m_outBuffer + (m_outBufferSize - 1)); 00068 setg(m_inBuffer + m_inPutback, m_inBuffer + m_inPutback, 00069 m_inBuffer + m_inPutback); 00070 } 00071 00072 virtual ~filterbuf(); 00073 00074 protected: 00075 static const int m_outBufferSize = 10; 00076 char m_outBuffer[m_outBufferSize]; 00077 00078 static const int m_inBufferSize = 10; 00079 static const int m_inPutback = 4; 00080 char m_inBuffer[m_inBufferSize]; 00081 00082 int flushOutBuffer() 00083 { 00084 int num = pptr() - pbase(); 00085 std::string encoded = m_filter.encode(std::string(pbase(), pptr())); 00086 m_streamBuffer.sputn(encoded.c_str(), (long) encoded.size()); 00087 pbump(-num); 00088 return num; 00089 } 00090 00091 virtual int_type overflow(int_type c); 00092 virtual int_type underflow(); 00093 virtual int sync(); 00094 00095 private: 00096 00097 std::streambuf& m_streamBuffer; 00098 Filter& m_filter; 00099 }; 00100 00101 } // Atlas namespace 00102 00103 #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.