00001
00002
00003
00004
00005
00006
00007
#ifndef __WVTYPEDENCODER_H
00008
#define __WVTYPEDENCODER_H
00009
00010
#include "wvbufbase.h"
00011
#include "wvencoder.h"
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00043
00044
00045
00046
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
00055
00056
00057
00058
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
00066
00067
00068
00069
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:
00092
00093
00094
00095
00096
virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
00097
bool flush) = 0;
00098
00099
00100
00101
00102
00103 virtual bool _typedfinish(
OBuffer &outbuf)
00104 {
return true; }
00105
00106
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
00115
00116 virtual bool _finish(
WvBuf &outbuf)
00117 {
00118
OBufferView outview(outbuf);
00119
return _typedfinish(outview);
00120 }
00121 };
00122
00123
00124
00125
00126
00127
00128
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
00140
00141
00142
00143
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
00151
00152
00153
00154
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:
00173
00174
00175
00176
00177
virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
00178
bool flush) = 0;
00179
00180
00181
00182
00183
00184 virtual bool _typedfinish(
OBuffer &outbuf)
00185 {
return true; }
00186
00187
00188 virtual bool _encode(
WvBuf &inbuf,
WvBuf &outbuf,
00189
bool flush)
00190 {
00191
IBufferView inview(inbuf);
00192
return _typedencode(inview, outbuf, flush);
00193 }
00194
00195
00196 virtual bool _finish(
WvBuf &outbuf)
00197 {
00198
return _typedfinish(outbuf);
00199 }
00200 };
00201
00202
00203
00204
00205
00206
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:
00219
00220
00221
00222
00223
virtual bool _typedencode(
IBuffer &inbuf,
OBuffer &outbuf,
00224
bool flush) = 0;
00225
00226
00227
00228
00229
00230 virtual bool _typedfinish(
OBuffer &outbuf)
00231 {
return true; }
00232
00233
00234 virtual bool _encode(
WvBuf &inbuf,
WvBuf &outbuf,
00235
bool flush)
00236 {
00237
return _typedencode(inbuf, outbuf, flush);
00238 }
00239
00240
00241 virtual bool _finish(
WvBuf &outbuf)
00242 {
00243
return _typedfinish(outbuf);
00244 }
00245 };
00246
00247
#endif // __WVTYPEDENCODER