Atlas-C++
Filter.h
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-2001 Michael Day, Stefanus Du Toit
4 
5 // $Id$
6 
7 #ifndef ATLAS_FILTER_H
8 #define ATLAS_FILTER_H
9 
10 #include <iostream>
11 #include <string>
12 
13 namespace Atlas {
14 
29 class Filter
30 {
31  public:
32 
33  Filter(Filter* = 0);
34  virtual ~Filter();
35 
36  virtual void begin() = 0;
37  virtual void end() = 0;
38 
39  virtual std::string encode(const std::string&) = 0;
40  virtual std::string decode(const std::string&) = 0;
41 
42  enum Type
43  {
44  CHECKSUM,
45  COMPRESSION,
46  ENCRYPTION
47  };
48 
49  protected:
50 
51  Filter* m_next;
52 };
53 
54 typedef int int_type;
55 
56 class filterbuf : public std::streambuf {
57 
58 public:
59 
60  filterbuf(std::streambuf& buffer,
61  Filter& filter)
62  : m_streamBuffer(buffer), m_filter(filter)
63  {
64  setp(m_outBuffer, m_outBuffer + (m_outBufferSize - 1));
65  setg(m_inBuffer + m_inPutback, m_inBuffer + m_inPutback,
66  m_inBuffer + m_inPutback);
67  }
68 
69  virtual ~filterbuf();
70 
71 protected:
72  static const int m_outBufferSize = 10;
73  char m_outBuffer[m_outBufferSize];
74 
75  static const int m_inBufferSize = 10;
76  static const int m_inPutback = 4;
77  char m_inBuffer[m_inBufferSize];
78 
79  int flushOutBuffer()
80  {
81  int num = pptr() - pbase();
82  std::string encoded = m_filter.encode(std::string(pbase(), pptr()));
83  m_streamBuffer.sputn(encoded.c_str(), (long) encoded.size());
84  pbump(-num);
85  return num;
86  }
87 
88  virtual int_type overflow(int_type c);
89  virtual int_type underflow();
90  virtual int sync();
91 
92 private:
93 
94  std::streambuf& m_streamBuffer;
95  Filter& m_filter;
96 };
97 
98 } // Atlas namespace
99 
100 #endif
The Atlas namespace.
Definition: Bridge.h:20
Atlas stream filter.
Definition: Filter.h:29
Definition: Filter.h:56

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.