Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

wvencoder.h

00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * A top-level data encoder class and a few useful encoders.
00006  */
00007 #ifndef __WVENCODER_H
00008 #define __WVENCODER_H
00009 
00010 #include "wvbuf.h"
00011 #include "wvlinklist.h"
00012 #include "wvstring.h"
00013 
00067 class WvEncoder
00068 {
00069 protected:
00070     bool okay; 
00071     bool finished; 
00072     WvString errstr; 
00074 public:
00076     WvEncoder();
00077 
00079     virtual ~WvEncoder();
00080     
00090     bool isok() const
00091         { return okay && _isok(); }
00092 
00101     bool isfinished() const
00102         { return finished || _isfinished(); }
00103 
00109     WvString geterror() const;
00110 
00152     bool encode(WvBuf &inbuf, WvBuf &outbuf, bool flush = false,
00153         bool finish = false);
00154 
00163     bool flush(WvBuf &inbuf, WvBuf &outbuf,
00164         bool finish = false)
00165         { return encode(inbuf, outbuf, true, finish); }
00166 
00184     bool finish(WvBuf &outbuf);
00185 
00199     bool reset();
00200 
00209     bool flushstrbuf(WvStringParm instr, WvBuf &outbuf,
00210         bool finish = false);
00211         
00222     bool flushstrstr(WvStringParm instr, WvString &outstr,
00223         bool finish = false);
00224 
00236     bool encodebufstr(WvBuf &inbuf, WvString &outstr,
00237         bool flush = false, bool finish = false);
00238 
00249     bool flushbufstr(WvBuf &inbuf, WvString &outstr,
00250         bool finish = false)
00251         { return encodebufstr(inbuf, outstr, true, finish); }
00252     
00260     WvString strflushstr(WvStringParm instr, bool finish = false);
00261     
00269     WvString strflushbuf(WvBuf &inbuf, bool finish = false);
00270 
00280     bool flushmembuf(const void *inmem, size_t inlen, WvBuf &outbuf,
00281         bool finish = false);
00282         
00299     bool flushmemmem(const void *inmem, size_t inlen, void *outmem,
00300         size_t *outlen, bool finish = false);
00301         
00319     bool encodebufmem(WvBuf &inbuf, void *outmem, size_t *outlen,
00320         bool flush = false, bool finish = false);   
00321         
00337     bool flushbufmem(WvBuf &inbuf, void *outmem, size_t *outlen,
00338         bool finish = false)
00339         { return encodebufmem(inbuf, outmem, outlen, true, finish); }
00340 
00356     bool flushstrmem(WvStringParm instr, void *outmem, size_t *outlen,
00357         bool finish = false);
00358 
00367     WvString strflushmem(const void *inmem, size_t inlen, bool finish = false);
00368 
00369 protected:
00371     void setnotok()
00372         { okay = false; }
00373 
00375     void seterror(WvStringParm message)
00376         { errstr = message; setnotok(); }
00377 
00379     void seterror(WVSTRING_FORMAT_DECL)
00380         { seterror(WvString(WVSTRING_FORMAT_CALL)); }
00381 
00383     void setfinished()
00384         { finished = true; }
00385 
00386 protected:
00400     virtual bool _isok() const
00401         { return true; }
00402 
00416     virtual bool _isfinished() const
00417         { return false; }
00418 
00433     virtual WvString _geterror() const
00434         { return WvString::null; }
00435 
00459     virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush) = 0;
00460 
00483     virtual bool _finish(WvBuf &outbuf)
00484         { return true; }
00485 
00498     virtual bool _reset()
00499         { return false; }
00500 };
00501 
00502 
00504 class WvNullEncoder : public WvEncoder
00505 {
00506 protected:
00507     virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
00508     virtual bool _reset(); // supported: does nothing
00509 };
00510 
00511 
00521 class WvPassthroughEncoder : public WvEncoder
00522 {
00523     size_t total;
00524     
00525 public:
00526     WvPassthroughEncoder();
00527     virtual ~WvPassthroughEncoder() { }
00528 
00533     size_t bytes_processed() { return total; }
00534     
00535 protected:
00536     virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
00537     virtual bool _reset(); // supported: resets the count to zero
00538 };
00539 
00540 
00549 class WvEncoderChain : public WvEncoder
00550 {
00551     class WvEncoderChainElem
00552     {
00553     public:
00554         WvEncoder *enc;
00555         WvDynBuf out;
00556         bool autofree;
00557 
00558         WvEncoderChainElem(WvEncoder *enc, bool autofree) :
00559             enc(enc), autofree(autofree) { }
00560         ~WvEncoderChainElem() { if (autofree) delete enc; }
00561     };
00562     DeclareWvList2(WvEncoderChainElemListBase, WvEncoderChainElem);
00563 
00564     WvEncoderChainElemListBase encoders;
00565     WvPassthroughEncoder passthrough;
00566 public:
00568     WvEncoderChain();
00569 
00576     virtual ~WvEncoderChain();
00577 
00584     void append(WvEncoder *enc, bool autofree);
00585 
00592     void prepend(WvEncoder *enc, bool autofree);
00593 
00603     bool get_autofree(WvEncoder *enc);
00604 
00614     void set_autofree(WvEncoder *enc, bool autofree);
00615 
00623     void unlink(WvEncoder *enc);
00624 
00631     void zap();
00632 
00633 protected:
00644     virtual bool _isok() const;
00645     
00656     virtual bool _isfinished() const;
00657 
00667     virtual WvString _geterror() const;
00668     
00674     virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
00675     
00687     virtual bool _finish(WvBuf & out);
00688 
00697     virtual bool _reset();
00698 };
00699 
00700 #endif // __WVENCODER_H

Generated on Sun Jul 10 17:30:56 2005 for WvStreams by  doxygen 1.4.0