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)
183WvPassthroughEncoder::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;
254bool 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();
void merge(Buffer &inbuf, size_t count)
Efficiently moves count bytes from the specified buffer into this one.
void zap()
Clears the buffer.
size_t used() const
Returns the number of elements in the buffer currently available for reading.
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
WvString getstr()
Returns the entire buffer as a null-terminated WvString.
The const in place raw memory buffer type.
A raw memory read-only buffer backed by a constant WvString.
virtual WvString _geterror() const
Returns the error message, if any.
size_t buffered()
Returns true if there is data in an internal buffer.
bool get_autofree(WvEncoder *enc) const
Gets the autofree state of a particular encoder in the chain.
bool continue_encode(WvBuf &inbuf, WvBuf &outbuf)
"Continues" encoding a buffer.
void unlink(WvEncoder *enc)
Unlinks the encoder from the chain.
WvEncoderChain()
Creates an initially empty chain of encoders.
void zap()
Clears the encoder chain.
void set_autofree(WvEncoder *enc, bool autofree)
Sets the autofree state of a particular encoder in the chain.
virtual ~WvEncoderChain()
Destroys the encoder chain.
virtual bool _reset()
Resets the chain of encoders.
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Passes the data through the entire chain of encoders.
void prepend(WvEncoder *enc, bool autofree)
Prepends an encoder to the head of the chain.
void append(WvEncoder *enc, bool autofree)
Appends an encoder to the tail of the chain.
virtual bool _isfinished() const
Returns true if the encoder can no longer encode data.
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 finish(WvBuf &outbuf)
Tells the encoder that NO MORE DATA will ever be encoded.
bool isok() const
Returns true if the encoder has not encountered an error.
bool reset()
Asks an encoder to reset itself to its initial state at creation time, if supported.
WvString strflushstr(WvStringParm instr, bool finish=false)
Flushes data through the encoder from a string to a string.
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.
void seterror(WvStringParm message)
Sets an error condition, then setnotok().
virtual ~WvEncoder()
Destroys the encoder.
virtual bool _finish(WvBuf &outbuf)
Template method implementation of finish().
bool flushbufmem(WvBuf &inbuf, void *outmem, size_t *outlen, bool finish=false)
Flushes data through the encoder from a buffer to memory.
bool encodebufmem(WvBuf &inbuf, void *outmem, size_t *outlen, bool flush=false, bool finish=false)
Encodes data from a buffer 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.
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.
bool flushstrbuf(WvStringParm instr, WvBuf &outbuf, bool finish=false)
Flushes data through the encoder from a string to a buffer.
WvEncoder()
Creates a new WvEncoder.
bool encodebufstr(WvBuf &inbuf, WvString &outstr, bool flush=false, bool finish=false)
Encodes data from a buffer to a string.
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
bool flushstrmem(WvStringParm instr, void *outmem, size_t *outlen, bool finish=false)
Flushes data through the encoder from a string to memory.
bool flushstrstr(WvStringParm instr, WvString &outstr, bool finish=false)
Flushes data through the encoder from a string to a string.
virtual WvString _geterror() const
Template method implementation of geterror().
WvString strflushmem(const void *inmem, size_t inlen, bool finish=false)
Flushes data through the encoder from memory to a string.
bool flushbufstr(WvBuf &inbuf, WvString &outstr, bool finish=false)
Flushes data through the encoder from a buffer to a string.
void setfinished()
Sets 'finished' to true explicitly.
virtual bool _reset()
Template method implementation of reset().
WvString geterror() const
Returns an error message if any is available.
WvString strflushbuf(WvBuf &inbuf, bool finish=false)
Flushes data through the encoder from a buffer to a string.
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)=0
Template method implementation of encode().
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
The in place raw memory buffer type.
A buffer that is always empty.
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Template method implementation of encode().
virtual bool _reset()
Template method implementation of reset().
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Template method implementation of encode().
virtual bool _reset()
Template method implementation of reset().
WvString is an implementation of a simple and efficient printable-string class.