WvStreams
wvtypedencoder.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * An abstraction for encoders that manipulate typed buffers.
6  */
7 #ifndef __WVTYPEDENCODER_H
8 #define __WVTYPEDENCODER_H
9 
10 #include "wvencoder.h"
11 #include "wvbufbase.h"
12 
32 template<class IT, class OT, class S = WvEncoder>
33 class WvTypedEncoder : public S
34 {
35 public:
36  typedef IT IType;
37  typedef OT OType;
38  typedef WvBufBase<IType> IBuffer;
39  typedef WvBufBase<OType> OBuffer;
42 
47  bool encode(IBuffer &inbuf, OBuffer &outbuf, bool flush = false,
48  bool finish = false)
49  {
50  WvBufView inview(inbuf);
51  WvBufView outview(outbuf);
52  return S::encode(inview, outview, flush, finish);
53  }
54 
59  bool flush(IBuffer &inbuf, OBuffer &outbuf, bool finish = false)
60  {
61  WvBufView inview(inbuf);
62  WvBufView outview(outbuf);
63  return S::flush(inview, outview, finish);
64  }
65 
70  bool finish(OBuffer &outbuf)
71  {
72  WvBufView outview(outbuf);
73  return S::finish(outview);
74  }
75 
76  bool encode(WvBuf &inbuf, WvBuf &outbuf,
77  bool flush = false, bool finish = false)
78  {
79  return S::encode(inbuf, outbuf, flush, finish);
80  }
81  bool flush(WvBuf &inbuf, WvBuf &outbuf,
82  bool finish = false)
83  {
84  return S::flush(inbuf, outbuf, finish);
85  }
86  bool finish(WvBuf &outbuf)
87  {
88  return S::finish(outbuf);
89  }
90 
91 protected:
96  virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
97  bool flush) = 0;
98 
103  virtual bool _typedfinish(OBuffer &outbuf)
104  { return true; }
105 
107  virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf,
108  bool flush)
109  {
110  IBufferView inview(inbuf);
111  OBufferView outview(outbuf);
112  return _typedencode(inview, outview, flush);
113  }
114 
116  virtual bool _finish(WvBuf &outbuf)
117  {
118  OBufferView outview(outbuf);
119  return _typedfinish(outview);
120  }
121 };
122 
129 template<class IT, class S>
130 class WvTypedEncoder<IT, unsigned char, S> : public S
131 {
132 public:
133  typedef IT IType;
134  typedef unsigned char OType;
135  typedef WvBufBase<IType> IBuffer;
136  typedef WvBufBase<OType> OBuffer;
139 
144  bool encode(IBuffer &inbuf, OBuffer &outbuf, bool flush = false,
145  bool finish = false)
146  {
147  WvBufView inview(inbuf);
148  return S::encode(inview, outbuf, flush, finish);
149  }
150 
155  bool flush(IBuffer &inbuf, OBuffer &outbuf, bool finish = false)
156  {
157  WvBufView inview(inbuf);
158  return S::flush(inview, outbuf, finish);
159  }
160 
161  bool encode(WvBuf &inbuf, WvBuf &outbuf,
162  bool flush = false, bool finish = false)
163  {
164  return S::encode(inbuf, outbuf, flush, finish);
165  }
166  bool flush(WvBuf &inbuf, WvBuf &outbuf,
167  bool finish = false)
168  {
169  return S::flush(inbuf, outbuf, finish);
170  }
171 
172 protected:
177  virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
178  bool flush) = 0;
179 
184  virtual bool _typedfinish(OBuffer &outbuf)
185  { return true; }
186 
188  virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf,
189  bool flush)
190  {
191  IBufferView inview(inbuf);
192  return _typedencode(inview, outbuf, flush);
193  }
194 
196  virtual bool _finish(WvBuf &outbuf)
197  {
198  return _typedfinish(outbuf);
199  }
200 };
201 
202 
207 template<class S>
208 class WvTypedEncoder<unsigned char, unsigned char, S> : public S
209 {
210 public:
211  typedef unsigned char IType;
212  typedef unsigned char OType;
213  typedef WvBufBase<IType> IBuffer;
214  typedef WvBufBase<OType> OBuffer;
217 
218 protected:
223  virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
224  bool flush) = 0;
225 
230  virtual bool _typedfinish(OBuffer &outbuf)
231  { return true; }
232 
234  virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf,
235  bool flush)
236  {
237  return _typedencode(inbuf, outbuf, flush);
238  }
239 
241  virtual bool _finish(WvBuf &outbuf)
242  {
243  return _typedfinish(outbuf);
244  }
245 };
246 
247 #endif // __WVTYPEDENCODER
WvTypedEncoder< IT, unsigned char, S >::_finish
virtual bool _finish(WvBuf &outbuf)
Wrapper implementation of _finish().
Definition: wvtypedencoder.h:196
WvTypedEncoder< IT, unsigned char, S >::encode
bool encode(IBuffer &inbuf, OBuffer &outbuf, bool flush=false, bool finish=false)
Typed variant of encode().
Definition: wvtypedencoder.h:144
WvTypedEncoder::_finish
virtual bool _finish(WvBuf &outbuf)
Wrapper implementation of _finish().
Definition: wvtypedencoder.h:116
WvTypedEncoder< IT, unsigned char, S >::_typedfinish
virtual bool _typedfinish(OBuffer &outbuf)
Typed variant of _finish().
Definition: wvtypedencoder.h:184
WvTypedEncoder< unsigned char, unsigned char, S >::_typedfinish
virtual bool _typedfinish(OBuffer &outbuf)
Typed variant of _finish().
Definition: wvtypedencoder.h:230
WvTypedEncoder::_typedencode
virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf, bool flush)=0
Typed variant of _encode().
WvBufBase
The generic buffer base type.
Definition: wvbufbase.h:15
WvTypedEncoder::encode
bool encode(IBuffer &inbuf, OBuffer &outbuf, bool flush=false, bool finish=false)
Typed variant of encode().
Definition: wvtypedencoder.h:47
WvBufViewBase
A buffer that provides a read-write view over another buffer with a different datatype.
Definition: wvbufbase.h:1052
WvBufBase< unsigned char >
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
Definition: wvbuf.h:22
WvTypedEncoder< unsigned char, unsigned char, S >::_finish
virtual bool _finish(WvBuf &outbuf)
Wrapper implementation of _finish().
Definition: wvtypedencoder.h:241
WvTypedEncoder< IT, unsigned char, S >::flush
bool flush(IBuffer &inbuf, OBuffer &outbuf, bool finish=false)
Typed variant of flush().
Definition: wvtypedencoder.h:155
WvTypedEncoder::_typedfinish
virtual bool _typedfinish(OBuffer &outbuf)
Typed variant of _finish().
Definition: wvtypedencoder.h:103
WvTypedEncoder::flush
bool flush(IBuffer &inbuf, OBuffer &outbuf, bool finish=false)
Typed variant of flush().
Definition: wvtypedencoder.h:59
WvTypedEncoder
This template facilitates the creation and use of encoders that manipulate typed buffers.
Definition: wvtypedencoder.h:33
WvTypedEncoder::finish
bool finish(OBuffer &outbuf)
Typed variant of finish().
Definition: wvtypedencoder.h:70
WvTypedEncoder::_encode
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)
Wrapper implementation of _encode().
Definition: wvtypedencoder.h:107
WvTypedEncoder< unsigned char, unsigned char, S >::_encode
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)
Wrapper implementation of _encode().
Definition: wvtypedencoder.h:234
WvTypedEncoder< IT, unsigned char, S >::_encode
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)
Wrapper implementation of _encode().
Definition: wvtypedencoder.h:188