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