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
32template<class IT, class OT, class S = WvEncoder>
33class WvTypedEncoder : public S
34{
35public:
36 typedef IT IType;
37 typedef OT OType;
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
91protected:
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
129template<class IT, class S>
130class WvTypedEncoder<IT, unsigned char, S> : public S
131{
132public:
133 typedef IT IType;
134 typedef unsigned char OType;
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
172protected:
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
207template<class S>
208class WvTypedEncoder<unsigned char, unsigned char, S> : public S
209{
210public:
211 typedef unsigned char IType;
212 typedef unsigned char OType;
217
218protected:
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
The generic buffer base type.
Definition wvbufbase.h:587
A buffer that provides a read-write view over another buffer with a different datatype.
Definition wvbufbase.h:1053
bool flush(IBuffer &inbuf, OBuffer &outbuf, bool finish=false)
Typed variant of flush().
virtual bool _finish(WvBuf &outbuf)
Wrapper implementation of _finish().
virtual bool _typedfinish(OBuffer &outbuf)
Typed variant of _finish().
bool encode(IBuffer &inbuf, OBuffer &outbuf, bool flush=false, bool finish=false)
Typed variant of encode().
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)
Wrapper implementation of _encode().
virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf, bool flush)=0
Typed variant of _encode().
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)
Wrapper implementation of _encode().
virtual bool _finish(WvBuf &outbuf)
Wrapper implementation of _finish().
virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf, bool flush)=0
Typed variant of _encode().
virtual bool _typedfinish(OBuffer &outbuf)
Typed variant of _finish().
This template facilitates the creation and use of encoders that manipulate typed buffers.
bool flush(IBuffer &inbuf, OBuffer &outbuf, bool finish=false)
Typed variant of flush().
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)
Wrapper implementation of _encode().
virtual bool _typedfinish(OBuffer &outbuf)
Typed variant of _finish().
virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf, bool flush)=0
Typed variant of _encode().
bool encode(IBuffer &inbuf, OBuffer &outbuf, bool flush=false, bool finish=false)
Typed variant of encode().
virtual bool _finish(WvBuf &outbuf)
Wrapper implementation of _finish().
bool finish(OBuffer &outbuf)
Typed variant of finish().