26 return WvString::null;
32 return "unknown encoder error";
37 bool flush,
bool _finish)
44 success =
finish(outbuf) && success;
71 seterror(
"reset not supported by encoder");
92 outstr.append(outbuf.
getstr());
98 bool flush,
bool finish)
102 outstr.append(outbuf.
getstr());
124 WvBuf &outbuf,
bool finish)
133 void *outmem,
size_t *outlen,
bool finish)
141 void *outmem,
size_t *outlen,
bool flush,
bool finish)
145 *outlen = outbuf.
used();
151 void *outmem,
size_t *outlen,
bool finish)
183 WvPassthroughEncoder::WvPassthroughEncoder()
220 ChainElemList::Iter it(
const_cast<ChainElemList&
>(encoders));
221 for (it.rewind(); it.next(); )
222 if (!it->enc->isok())
230 ChainElemList::Iter it(
const_cast<ChainElemList&
>(encoders));
231 for (it.rewind(); it.next(); )
232 if (it->enc->isfinished())
240 ChainElemList::Iter it(
const_cast<ChainElemList&
>(encoders));
241 for (it.rewind(); it.next(); )
243 WvString message = it->enc->geterror();
244 if (!!message)
return message;
246 return WvString::null;
254 bool WvEncoderChain::do_encode(
WvBuf &in,
WvBuf &out, ChainElem *start_after,
255 bool flush,
bool finish)
259 ChainElemList::Iter it(encoders);
261 if (start_after) it.find(start_after);
262 last_run = start_after;
263 for (; it.cur() && it.next(); )
265 if (!it->enc->encode(*tmpin, it->out,
flush))
267 if (
finish && !it->enc->finish(it->out))
279 return do_encode(in, out, NULL,
flush,
false);
286 return do_encode(empty, out, NULL,
true,
true);
294 return do_encode(in, out, last_run,
false,
false);
301 ChainElemList::Iter it(encoders);
302 for (it.rewind(); it.next(); )
305 if (!it->enc->reset())
314 encoders.append(
new ChainElem(enc, autofree),
true);
320 encoders.prepend(
new ChainElem(enc, autofree),
true);
326 ChainElemList::Iter i(encoders);
327 for (i.rewind(); i.next(); )
328 if (i->enc == enc && i.get_autofree())
336 ChainElemList::Iter i(encoders);
341 for (i.rewind(); i.next(); )
347 i.set_autofree(
true);
351 i.set_autofree(
false);
358 for (i.rewind(); i.next(); )
360 i.set_autofree(
false);
367 ChainElemList::Iter it(encoders);
368 for (it.rewind(); it.next(); )
383 ChainElemList::Iter it(encoders);
384 for (it.rewind(); it.next(); )
385 used += it().out.used();
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Template method implementation of encode().
virtual bool _isok() const
Returns true if the encoder has not encountered an error.
virtual bool _finish(WvBuf &out)
Finishes the chain of encoders.
bool flushmemmem(const void *inmem, size_t inlen, void *outmem, size_t *outlen, bool finish=false)
Flushes data through the encoder from memory to memory.
void zap()
Clears the encoder chain.
virtual bool _reset()
Template method implementation of reset().
void append(WvEncoder *enc, bool autofree)
Appends an encoder to the tail of the chain.
WvString getstr()
Returns the entire buffer as a null-terminated WvString.
WvEncoderChain()
Creates an initially empty chain of encoders.
WvString strflushstr(WvStringParm instr, bool finish=false)
Flushes data through the encoder from a string to a string.
virtual bool _isfinished() const
Returns true if the encoder can no longer encode data.
WvString strflushmem(const void *inmem, size_t inlen, bool finish=false)
Flushes data through the encoder from memory to a string.
A raw memory read-only buffer backed by a constant WvString.
bool encode(WvBuf &inbuf, WvBuf &outbuf, bool flush=false, bool finish=false)
Reads data from the input buffer, encodes it, and writes the result to the output buffer.
WvString is an implementation of a simple and efficient printable-string class.
bool flushstrbuf(WvStringParm instr, WvBuf &outbuf, bool finish=false)
Flushes data through the encoder from a string to a buffer.
bool encodebufstr(WvBuf &inbuf, WvString &outstr, bool flush=false, bool finish=false)
Encodes data from a buffer to a string.
virtual bool _reset()
Resets the chain of encoders.
virtual ~WvEncoder()
Destroys the encoder.
The in place raw memory buffer type.
WvEncoder()
Creates a new WvEncoder.
size_t buffered()
Returns true if there is data in an internal buffer.
void set_autofree(WvEncoder *enc, bool autofree)
Sets the autofree state of a particular encoder in the chain.
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)=0
Template method implementation of encode().
bool continue_encode(WvBuf &inbuf, WvBuf &outbuf)
"Continues" encoding a buffer.
bool flushbufmem(WvBuf &inbuf, void *outmem, size_t *outlen, bool finish=false)
Flushes data through the encoder from a buffer to memory.
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
void zap()
Clears the buffer.
WvString strflushbuf(WvBuf &inbuf, bool finish=false)
Flushes data through the encoder from a buffer to a string.
WvString geterror() const
Returns an error message if any is available.
bool isok() const
Returns true if the encoder has not encountered an error.
The const in place raw memory buffer type.
bool finish(WvBuf &outbuf)
Tells the encoder that NO MORE DATA will ever be encoded.
bool flushstrstr(WvStringParm instr, WvString &outstr, bool finish=false)
Flushes data through the encoder from a string to a string.
void unlink(WvEncoder *enc)
Unlinks the encoder from the chain.
bool flushbufstr(WvBuf &inbuf, WvString &outstr, bool finish=false)
Flushes data through the encoder from a buffer to a string.
A buffer that is always empty.
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
void prepend(WvEncoder *enc, bool autofree)
Prepends an encoder to the head of the chain.
void setfinished()
Sets 'finished' to true explicitly.
size_t used() const
Returns the number of elements in the buffer currently available for reading.
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Template method implementation of encode().
virtual WvString _geterror() const
Template method implementation of geterror().
virtual bool _reset()
Template method implementation of reset().
bool flushstrmem(WvStringParm instr, void *outmem, size_t *outlen, bool finish=false)
Flushes data through the encoder from a string to memory.
bool flushmembuf(const void *inmem, size_t inlen, WvBuf &outbuf, bool finish=false)
Flushes data through the encoder from memory to a buffer.
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Passes the data through the entire chain of encoders.
void merge(Buffer &inbuf, size_t count)
Efficiently moves count bytes from the specified buffer into this one.
bool encodebufmem(WvBuf &inbuf, void *outmem, size_t *outlen, bool flush=false, bool finish=false)
Encodes data from a buffer to memory.
void seterror(WvStringParm message)
Sets an error condition, then setnotok().
virtual bool _finish(WvBuf &outbuf)
Template method implementation of finish().
virtual ~WvEncoderChain()
Destroys the encoder chain.
bool get_autofree(WvEncoder *enc) const
Gets the autofree state of a particular encoder in the chain.
virtual bool _reset()
Template method implementation of reset().
bool reset()
Asks an encoder to reset itself to its initial state at creation time, if supported.
virtual WvString _geterror() const
Returns the error message, if any.