Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

WvEncoderChain Class Reference

#include <wvencoder.h>

Inherits WvEncoder.

Collaboration diagram for WvEncoderChain:

[legend]
List of all members.

Detailed Description

An encoder chain owns a list of encoders that are used in sequence to transform data from a source buffer to a target buffer.

Supports reset() if all the encoders it contains also support reset().

Definition at line 549 of file wvencoder.h.

Public Member Functions

 WvEncoderChain ()
 Creates an initially empty chain of encoders.

virtual ~WvEncoderChain ()
 Destroys the encoder chain.

void append (WvEncoder *enc, bool auto_free)
 Appends an encoder to the tail of the chain.

void prepend (WvEncoder *enc, bool auto_free)
 Prepends an encoder to the head of the chain.

void unlink (WvEncoder *enc)
 Unlinks the encoder from the chain.

void zap ()
 Clears the encoder chain.

bool isok () const
 Returns true if the encoder has not encountered an error.

bool isfinished () const
 Returns true if the encoder can no longer encode data.

WvString geterror () const
 Returns an error message if any is available.

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.

bool flush (WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
 Flushes the encoder and optionally finishes it.

bool finish (WvBuf &outbuf)
 Tells the encoder that NO MORE DATA will ever be encoded.

bool reset ()
 Asks an encoder to reset itself to its initial state at creation time, if supported.

bool flushstrbuf (WvStringParm instr, WvBuf &outbuf, bool finish=false)
 Flushes data through the encoder from a string to a buffer.

bool flushstrstr (WvStringParm instr, WvString &outstr, bool finish=false)
 Flushes data through the encoder from a string to a string.

bool encodebufstr (WvBuf &inbuf, WvString &outstr, bool flush=false, bool finish=false)
 Encodes data from a buffer to a string.

bool flushbufstr (WvBuf &inbuf, WvString &outstr, bool finish=false)
 Flushes data through the encoder from a buffer to a string.

WvString strflushstr (WvStringParm instr, bool finish=false)
 Flushes data through the encoder from a string to a string.

WvString strflushbuf (WvBuf &inbuf, bool finish=false)
 Flushes data through the encoder from a buffer to a string.

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 encodebufmem (WvBuf &inbuf, void *outmem, size_t *outlen, bool flush=false, bool finish=false)
 Encodes data from a buffer to memory.

bool flushbufmem (WvBuf &inbuf, void *outmem, size_t *outlen, bool finish=false)
 Flushes data through the encoder from a buffer to memory.

bool flushstrmem (WvStringParm instr, void *outmem, size_t *outlen, bool finish=false)
 Flushes data through the encoder from a string to memory.

WvString strflushmem (const void *inmem, size_t inlen, bool finish=false)
 Flushes data through the encoder from memory to a string.


Protected Member Functions

virtual bool _isok () const
 Returns true if the encoder has not encountered an error.

virtual bool _isfinished () const
 Returns true if the encoder can no longer encode data.

virtual WvString _geterror () const
 Returns the error message, if any.

virtual bool _encode (WvBuf &in, WvBuf &out, bool flush)
 Passes the data through the entire chain of encoders.

virtual bool _finish (WvBuf &out)
 Finishes the chain of encoders.

virtual bool _reset ()
 Resets the chain of encoders.

void setnotok ()
 Sets 'okay' to false explicitly.

void seterror (WvStringParm message)
 Sets an error condition, then setnotok().

void seterror (WVSTRING_FORMAT_DECL)
 Sets an error condition, then setnotok().

void setfinished ()
 Sets 'finished' to true explicitly.


Protected Attributes

bool okay
bool finished
WvString errstr


Constructor & Destructor Documentation

WvEncoderChain::WvEncoderChain  ) 
 

Creates an initially empty chain of encoders.

Definition at line 205 of file wvencoder.cc.

WvEncoderChain::~WvEncoderChain  )  [virtual]
 

Destroys the encoder chain.

Destroys any encoders that were added with auto_free == true.

Definition at line 210 of file wvencoder.cc.


Member Function Documentation

bool WvEncoderChain::_encode WvBuf in,
WvBuf out,
bool  flush
[protected, virtual]
 

Passes the data through the entire chain of encoders.

Returns: true iff all encoders return true.

Implements WvEncoder.

Definition at line 262 of file wvencoder.cc.

References WvEncoder::encode(), WvBufBaseCommonImpl< unsigned char >::merge(), and WvBuf.

bool WvEncoderChain::_finish WvBuf out  )  [protected, virtual]
 

Finishes the chain of encoders.

Invokes finish() on the first encoder in the chain, then flush() on the second encoder if new data was generated, then finish() on the second encoder, and so on until all encoders have been flushed and finished (assuming the first encoder had already been flushed).

Returns: true iff all encoders return true.

Reimplemented from WvEncoder.

Definition at line 302 of file wvencoder.cc.

References WvBufBaseCommonImpl< unsigned char >::merge(), WvBufBaseCommonImpl< unsigned char >::used(), and WvBuf.

WvString WvEncoderChain::_geterror  )  const [protected, virtual]
 

Returns the error message, if any.

WvEncoderChain is special in that it may transition from !geterror() = false to !geterror() = true if the offending encoders are removed from the list.

Returns: the first non-null error message in the chain

Reimplemented from WvEncoder.

Definition at line 243 of file wvencoder.cc.

bool WvEncoderChain::_isfinished  )  const [protected, virtual]
 

Returns true if the encoder can no longer encode data.

WvEncoderChain is special in that it may transition from isfinished() == true to isfinished() == false if the offending encoders are removed from the list, but not if finish() is called.

Returns: false iff all encoders return isfinished() == false

Reimplemented from WvEncoder.

Definition at line 229 of file wvencoder.cc.

bool WvEncoderChain::_isok  )  const [protected, virtual]
 

Returns true if the encoder has not encountered an error.

WvEncoderChain is special in that it may transition from isok() == false to isok() == true if the offending encoders are removed from the list.

Returns: true iff all encoders return isok() == true

See also:
WvEncoder::_isok

Reimplemented from WvEncoder.

Definition at line 215 of file wvencoder.cc.

bool WvEncoderChain::_reset  )  [protected, virtual]
 

Resets the chain of encoders.

Resets all of the encoders in the chain and discards any pending buffered input. Preserves the list of encoders.

Returns: true iff all encoders return true.

Reimplemented from WvEncoder.

Definition at line 352 of file wvencoder.cc.

void WvEncoderChain::append WvEncoder enc,
bool  auto_free
 

Appends an encoder to the tail of the chain.

"enc" is the encoder "auto_free" is if true, takes ownership of the encoder

Definition at line 367 of file wvencoder.cc.

Referenced by WvBlowfishStream::WvBlowfishStream(), WvGzipStream::WvGzipStream(), WvRSAStream::WvRSAStream(), WvTripleDESStream::WvTripleDESStream(), and WvXORStream::WvXORStream().

bool WvEncoder::encode WvBuf inbuf,
WvBuf outbuf,
bool  flush = false,
bool  finish = false
[inherited]
 

Reads data from the input buffer, encodes it, and writes the result to the output buffer.

If flush == true, the input buffer will be drained and the output buffer will contain all of the encoded data including any that might have been buffered internally from previous calls. Thus it is possible that new data will be written to the output buffer even though the input buffer was empty when encode() was called. If the buffer could not be fully drained because there was insufficient data, this function returns false and leaves the remaining unflushed data in the buffer.

If flush == false, the encoder will read and encode as much data as possible (or as it convenient) from the input buffer and store the results in the output buffer. Partial results may be buffered internally by the encoder to be written to the output buffer later when the encoder is flushed.

If finish = true, the encode() will be followed up by a call to finish(). The return values will be ANDed together to yield the final result. Most useful when flush is also true.

If a permanent error occurs, then isok() will return false, this function will return false and the input buffer will be left in an undefined state.

If a recoverable error occurs, the encoder should discard the problematic data from the input buffer and return false from this function, but isok() will remain true.

A stream might become isfinished() == true if an encoder- specific end-of-data marker was detected in the input.

"inbuf" is the input buffer "outbuf" is the output buffer "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success

See also:
_encode for the actual implementation

Reimplemented in WvTypedEncoder< unsigned char, float >, WvTypedEncoder< double, signed short >, WvTypedEncoder< signed short, double >, WvTypedEncoder< float, signed short >, WvTypedEncoder< signed short, float >, WvTypedEncoder< float, unsigned char >, WvTypedEncoder< double, double >, and WvTypedEncoder< IT, OT >.

Definition at line 34 of file wvencoder.cc.

References WvEncoder::_encode(), WvEncoder::finish(), WvEncoder::finished, WvEncoder::okay, WvBufBaseCommonImpl< unsigned char >::used(), and WvBuf.

Referenced by _encode(), WvCounterModeEncoder::_encode(), WvEncoder::encodebufmem(), WvEncoder::encodebufstr(), WvEncoder::flush(), WvEncoder::flushmembuf(), WvEncoder::flushstrbuf(), WvEncoder::flushstrstr(), main(), and WvDsp::uread().

bool WvEncoder::encodebufmem WvBuf inbuf,
void *  outmem,
size_t *  outlen,
bool  flush = false,
bool  finish = false
[inherited]
 

Encodes data from a buffer to memory.

The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.

"inmem" is the input data pointer "inlen" is the input data length "outmem" is the output data pointer "outlen" is the output data length, by reference "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success

Definition at line 138 of file wvencoder.cc.

References WvEncoder::encode(), WvBufBaseCommonImpl< unsigned >::used(), and WvBuf.

Referenced by WvEncoder::flushbufmem(), and WvEncoder::flushmemmem().

bool WvEncoder::encodebufstr WvBuf inbuf,
WvString outstr,
bool  flush = false,
bool  finish = false
[inherited]
 

Encodes data from a buffer to a string.

The output data is appended to the target string.

"inbuf" is the input buffer "outstr" is the output string "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success

Definition at line 95 of file wvencoder.cc.

References WvString::append(), WvEncoder::encode(), WvBuf, and WvDynBuf.

Referenced by WvEncoder::flushbufstr().

bool WvEncoder::finish WvBuf outbuf  )  [inherited]
 

Tells the encoder that NO MORE DATA will ever be encoded.

The encoder will flush out any internally buffered data and write out whatever end-of-data marking it needs to the supplied output buffer before returning.

Clients should invoke flush() on the input buffer before finish() if the input buffer was not yet empty.

It is safe to call this function multiple times. The implementation will simply return isok() and do nothing else.

"outbuf" is the output buffer Returns: true on success

See also:
_finish for the actual implementation

Reimplemented in WvTypedEncoder< unsigned char, float >, WvTypedEncoder< double, signed short >, WvTypedEncoder< signed short, double >, WvTypedEncoder< float, signed short >, WvTypedEncoder< signed short, float >, WvTypedEncoder< float, unsigned char >, WvTypedEncoder< double, double >, and WvTypedEncoder< IT, OT >.

Definition at line 47 of file wvencoder.cc.

References WvEncoder::_finish(), WvEncoder::finished, WvEncoder::okay, WvEncoder::setfinished(), and WvBuf.

Referenced by WvEncoder::encode(), WvEncoderStream::finish_read(), and WvEncoder::flush().

bool WvEncoder::flush WvBuf inbuf,
WvBuf outbuf,
bool  finish = false
[inline, inherited]
 

Flushes the encoder and optionally finishes it.

"inbuf" is the input buffer "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success

Reimplemented in WvTypedEncoder< unsigned char, float >, WvTypedEncoder< double, signed short >, WvTypedEncoder< signed short, double >, WvTypedEncoder< float, signed short >, WvTypedEncoder< signed short, float >, WvTypedEncoder< float, unsigned char >, WvTypedEncoder< double, double >, and WvTypedEncoder< IT, OT >.

Definition at line 163 of file wvencoder.h.

References WvEncoder::encode(), WvEncoder::finish(), and WvBuf.

Referenced by WvEncoderStream::finish_read(), and WvEncoderStream::flush_read().

bool WvEncoder::flushbufmem WvBuf inbuf,
void *  outmem,
size_t *  outlen,
bool  finish = false
[inline, inherited]
 

Flushes data through the encoder from a buffer to memory.

The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.

"inbuf" is the input buffer "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success

Definition at line 337 of file wvencoder.h.

References WvEncoder::encodebufmem(), and WvBuf.

Referenced by WvEncoder::flushstrmem().

bool WvEncoder::flushbufstr WvBuf inbuf,
WvString outstr,
bool  finish = false
[inline, inherited]
 

Flushes data through the encoder from a buffer to a string.

The output data is appended to the target string.

"inbuf" is the input buffer "outstr" is the output string "finish" is if true, calls finish() on success Returns: true on success

Definition at line 249 of file wvencoder.h.

References WvEncoder::encodebufstr(), and WvBuf.

Referenced by WvEncoder::strflushbuf().

bool WvEncoder::flushmembuf const void *  inmem,
size_t  inlen,
WvBuf outbuf,
bool  finish = false
[inherited]
 

Flushes data through the encoder from memory to a buffer.

"inmem" is the input data pointer "inlen" is the input data length "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success

Definition at line 121 of file wvencoder.cc.

References WvEncoder::encode(), and WvBuf.

Referenced by WvDsp::uwrite().

bool WvEncoder::flushmemmem const void *  inmem,
size_t  inlen,
void *  outmem,
size_t *  outlen,
bool  finish = false
[inherited]
 

Flushes data through the encoder from memory to memory.

The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.

"inmem" is the input data pointer "inlen" is the input data length "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success

Definition at line 130 of file wvencoder.cc.

References WvEncoder::encodebufmem().

bool WvEncoder::flushstrbuf WvStringParm  instr,
WvBuf outbuf,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a string to a buffer.

"instr" is the input string "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success

Definition at line 75 of file wvencoder.cc.

References WvEncoder::encode(), WvBuf, and WvStringParm.

bool WvEncoder::flushstrmem WvStringParm  instr,
void *  outmem,
size_t *  outlen,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a string to memory.

The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.

"instr" is the input string "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success

Definition at line 148 of file wvencoder.cc.

References WvEncoder::flushbufmem(), and WvStringParm.

bool WvEncoder::flushstrstr WvStringParm  instr,
WvString outstr,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a string to a string.

The output data is appended to the target string.

"instr" is the input string "outstr" is the output string "finish" is if true, calls finish() on success Returns: true on success

Definition at line 84 of file wvencoder.cc.

References WvString::append(), WvEncoder::encode(), WvDynBuf, and WvStringParm.

Referenced by encode64(), and WvEncoder::strflushstr().

WvString WvEncoder::geterror  )  const [inherited]
 

Returns an error message if any is available.

Returns: the error message, or the null string is isok() == true

Definition at line 21 of file wvencoder.cc.

References WvEncoder::_geterror(), WvEncoder::errstr, and WvEncoder::isok().

Referenced by WvOggSpeexDecoder::_geterror(), and WvOggSpeexEncoder::_geterror().

bool WvEncoder::isfinished  )  const [inline, inherited]
 

Returns true if the encoder can no longer encode data.

This will be set when the encoder detects and end-of-data mark in its input, or when finish() is called.

Returns: true if the encoder is finished

Definition at line 101 of file wvencoder.h.

References WvEncoder::_isfinished(), and WvEncoder::finished.

Referenced by WvSpeexDecoder::missing().

bool WvEncoder::isok  )  const [inline, inherited]
 

Returns true if the encoder has not encountered an error.

This should only be used to record permanent failures. Transient errors (eg. bad block, but recoverable) should be detected in a different fashion.

Returns: true if the encoder is ok

Definition at line 90 of file wvencoder.h.

References WvEncoder::_isok(), and WvEncoder::okay.

Referenced by WvOggSpeexDecoder::_isok(), WvOggSpeexEncoder::_isok(), WvEncoder::geterror(), and WvSpeexDecoder::missing().

void WvEncoderChain::prepend WvEncoder enc,
bool  auto_free
 

Prepends an encoder to the head of the chain.

"enc" is the encoder "auto_free" is if true, takes ownership of the encoder

Definition at line 373 of file wvencoder.cc.

bool WvEncoder::reset  )  [inherited]
 

Asks an encoder to reset itself to its initial state at creation time, if supported.

This function may be called at any time, even if isok() == false, or isfinished() == true.

If the behaviour is not supported or an error occurs, then false is returned and afterwards isok() == false.

Returns: true on success

See also:
_reset for the actual implementation

Definition at line 58 of file wvencoder.cc.

References WvEncoder::_reset(), WvEncoder::errstr, WvEncoder::finished, WvEncoder::okay, and WvEncoder::seterror().

void WvEncoder::seterror WVSTRING_FORMAT_DECL   )  [inline, protected, inherited]
 

Sets an error condition, then setnotok().

Definition at line 379 of file wvencoder.h.

References WvEncoder::seterror(), and WVSTRING_FORMAT_CALL.

void WvEncoder::seterror WvStringParm  message  )  [inline, protected, inherited]
 

Sets an error condition, then setnotok().

Definition at line 375 of file wvencoder.h.

References WvEncoder::errstr, WvEncoder::setnotok(), and WvStringParm.

Referenced by WvHexDecoder::_encode(), WvBase64Decoder::_encode(), WvOggVorbisDecoder::_typedencode(), WvOggVorbisEncoder::_typedencode(), WvOggSpeexDecoder::_typedencode(), WvOggVorbisDecoder::_typedfinish(), WvOggSpeexDecoder::_typedfinish(), WvEncoder::reset(), WvEncoder::seterror(), WvOggSpeexDecoder::WvOggSpeexDecoder(), WvOggSpeexEncoder::WvOggSpeexEncoder(), WvOggVorbisDecoder::WvOggVorbisDecoder(), WvOggVorbisEncoder::WvOggVorbisEncoder(), WvSpeexDecoder::WvSpeexDecoder(), and WvSpeexEncoder::WvSpeexEncoder().

void WvEncoder::setfinished  )  [inline, protected, inherited]
 

Sets 'finished' to true explicitly.

Definition at line 383 of file wvencoder.h.

References WvEncoder::finished.

Referenced by WvBase64Decoder::_encode(), WvOggVorbisDecoder::_typedencode(), WvOggSpeexDecoder::_typedencode(), and WvEncoder::finish().

void WvEncoder::setnotok  )  [inline, protected, inherited]
 

Sets 'okay' to false explicitly.

Definition at line 371 of file wvencoder.h.

References WvEncoder::okay.

Referenced by WvEncoder::seterror().

WvString WvEncoder::strflushbuf WvBuf inbuf,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a buffer to a string.

"inbuf" is the input buffer "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors

Definition at line 113 of file wvencoder.cc.

References WvEncoder::flushbufstr(), and WvBuf.

Referenced by WvEncoder::strflushmem().

WvString WvEncoder::strflushmem const void *  inmem,
size_t  inlen,
bool  finish = false
[inherited]
 

Flushes data through the encoder from memory to a string.

"inmem" is the input data pointer "inlen" is the input data length "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors

Definition at line 156 of file wvencoder.cc.

References WvEncoder::strflushbuf().

WvString WvEncoder::strflushstr WvStringParm  instr,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a string to a string.

"inbuf" is the input buffer "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors

Definition at line 105 of file wvencoder.cc.

References WvEncoder::flushstrstr(), and WvStringParm.

void WvEncoderChain::unlink WvEncoder enc  ) 
 

Unlinks the encoder from the chain.

Destroys the encoder if it was added with auto_free == true.

"enc" is the encoder

Definition at line 379 of file wvencoder.cc.

void WvEncoderChain::zap  ) 
 

Clears the encoder chain.

Destroys any encoders that were added with auto_free == true.

Definition at line 390 of file wvencoder.cc.


Member Data Documentation

WvString WvEncoder::errstr [protected, inherited]
 

the error message

Definition at line 72 of file wvencoder.h.

Referenced by WvEncoder::geterror(), WvEncoder::reset(), and WvEncoder::seterror().

bool WvEncoder::finished [protected, inherited]
 

true iff setfinished()/finish() was called

Definition at line 71 of file wvencoder.h.

Referenced by WvEncoder::encode(), WvEncoder::finish(), WvEncoder::isfinished(), WvEncoder::reset(), and WvEncoder::setfinished().

bool WvEncoder::okay [protected, inherited]
 

false iff setnotok() was called

Definition at line 70 of file wvencoder.h.

Referenced by WvEncoder::encode(), WvEncoder::finish(), WvEncoder::isok(), WvEncoder::reset(), and WvEncoder::setnotok().


The documentation for this class was generated from the following files:
Generated on Sat Mar 13 14:57:35 2004 for WvStreams by doxygen 1.3.6-20040222