00001
00002
00003
00004
00005
00006
00007 #ifndef __WVTYPEDENCODER_H
00008 #define __WVTYPEDENCODER_H
00009
00010 #include "wvbufbase.h"
00011 #include "wvencoder.h"
00012
00032 template<class IT, class OT, class S = WvEncoder>
00033 class WvTypedEncoder : public S
00034 {
00035 public:
00036 typedef IT IType;
00037 typedef OT OType;
00038 typedef WvBufBase<IType> IBuffer;
00039 typedef WvBufBase<OType> OBuffer;
00040 typedef WvBufViewBase<IType> IBufferView;
00041 typedef WvBufViewBase<OType> OBufferView;
00042
00047 bool encode(IBuffer &inbuf, OBuffer &outbuf, bool flush = false,
00048 bool finish = false)
00049 {
00050 WvBufView inview(inbuf);
00051 WvBufView outview(outbuf);
00052 return S::encode(inview, outview, flush, finish);
00053 }
00054
00059 bool flush(IBuffer &inbuf, OBuffer &outbuf, bool finish = false)
00060 {
00061 WvBufView inview(inbuf);
00062 WvBufView outview(outbuf);
00063 return S::flush(inview, outview, finish);
00064 }
00065
00070 bool finish(OBuffer &outbuf)
00071 {
00072 WvBufView outview(outbuf);
00073 return S::finish(outview);
00074 }
00075
00076 bool encode(WvBuf &inbuf, WvBuf &outbuf,
00077 bool flush = false, bool finish = false)
00078 {
00079 return S::encode(inbuf, outbuf, flush, finish);
00080 }
00081 bool flush(WvBuf &inbuf, WvBuf &outbuf,
00082 bool finish = false)
00083 {
00084 return S::flush(inbuf, outbuf, finish);
00085 }
00086 bool finish(WvBuf &outbuf)
00087 {
00088 return S::finish(outbuf);
00089 }
00090
00091 protected:
00096 virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
00097 bool flush) = 0;
00098
00103 virtual bool _typedfinish(OBuffer &outbuf)
00104 { return true; }
00105
00107 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf,
00108 bool flush)
00109 {
00110 IBufferView inview(inbuf);
00111 OBufferView outview(outbuf);
00112 return _typedencode(inview, outview, flush);
00113 }
00114
00116 virtual bool _finish(WvBuf &outbuf)
00117 {
00118 OBufferView outview(outbuf);
00119 return _typedfinish(outview);
00120 }
00121 };
00122
00129 template<class IT, class S>
00130 class WvTypedEncoder<IT, unsigned char, S> : public S
00131 {
00132 public:
00133 typedef IT IType;
00134 typedef unsigned char OType;
00135 typedef WvBufBase<IType> IBuffer;
00136 typedef WvBufBase<OType> OBuffer;
00137 typedef WvBufViewBase<IType> IBufferView;
00138 typedef WvBufViewBase<OType> OBufferView;
00139
00144 bool encode(IBuffer &inbuf, OBuffer &outbuf, bool flush = false,
00145 bool finish = false)
00146 {
00147 WvBufView inview(inbuf);
00148 return S::encode(inview, outbuf, flush, finish);
00149 }
00150
00155 bool flush(IBuffer &inbuf, OBuffer &outbuf, bool finish = false)
00156 {
00157 WvBufView inview(inbuf);
00158 return S::flush(inview, outbuf, finish);
00159 }
00160
00161 bool encode(WvBuf &inbuf, WvBuf &outbuf,
00162 bool flush = false, bool finish = false)
00163 {
00164 return S::encode(inbuf, outbuf, flush, finish);
00165 }
00166 bool flush(WvBuf &inbuf, WvBuf &outbuf,
00167 bool finish = false)
00168 {
00169 return S::flush(inbuf, outbuf, finish);
00170 }
00171
00172 protected:
00177 virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
00178 bool flush) = 0;
00179
00184 virtual bool _typedfinish(OBuffer &outbuf)
00185 { return true; }
00186
00188 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf,
00189 bool flush)
00190 {
00191 IBufferView inview(inbuf);
00192 return _typedencode(inview, outbuf, flush);
00193 }
00194
00196 virtual bool _finish(WvBuf &outbuf)
00197 {
00198 return _typedfinish(outbuf);
00199 }
00200 };
00201
00202
00207 template<class S>
00208 class WvTypedEncoder<unsigned char, unsigned char, S> : public S
00209 {
00210 public:
00211 typedef unsigned char IType;
00212 typedef unsigned char OType;
00213 typedef WvBufBase<IType> IBuffer;
00214 typedef WvBufBase<OType> OBuffer;
00215 typedef WvBufViewBase<IType> IBufferView;
00216 typedef WvBufViewBase<OType> OBufferView;
00217
00218 protected:
00223 virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
00224 bool flush) = 0;
00225
00230 virtual bool _typedfinish(OBuffer &outbuf)
00231 { return true; }
00232
00234 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf,
00235 bool flush)
00236 {
00237 return _typedencode(inbuf, outbuf, flush);
00238 }
00239
00241 virtual bool _finish(WvBuf &outbuf)
00242 {
00243 return _typedfinish(outbuf);
00244 }
00245 };
00246
00247 #endif // __WVTYPEDENCODER