📄 coder_strbuf_adapter.h
字号:
/*******************************************************************************++ LEDA 4.5 +++ coder_strbuf_adapter.h+++ Copyright (c) 1995-2004+ by Algorithmic Solutions Software GmbH+ All rights reserved.+ *******************************************************************************/// $Revision: 1.16 $ $Date: 2004/02/23 14:16:08 $#ifndef _LEDA_CODER_STRBUF_ADAPTER_H#define _LEDA_CODER_STRBUF_ADAPTER_H#if !defined(LEDA_ROOT_INCL_ID)#define LEDA_ROOT_INCL_ID 450355#include <LEDA/PREAMBLE.h>#endif#include <LEDA/string.h>#include <LEDA/impl/coder_base.h>#ifdef __mipspro__#define LEDA_COMPRESSION_WA4#endif#if (_MSC_VER >= 1300)#define LEDA_COMPRESSION_WA7#endifLEDA_BEGIN_NAMESPACE// work-around for Microsoft .NET#ifdef LEDA_COMPRESSION_WA7class local_streambuf : public streambuf {};#define LEDA_STREAMBUF local_streambuf#else#define LEDA_STREAMBUF streambuf#endif/// coder_strbuf_adapter ////////////////////////////////////////////////////////////////////class __exportC coder_strbuf_adapter : public LEDA_STREAMBUF {public: typedef coder_base::byte byte; typedef coder_base::uint32 uint32; enum { DefaultBufSize = 4, StreamBlocked = coder_base::StreamBlocked };public: coder_strbuf_adapter(coder_base* coder = 0, bool own_coder = false, streambuf* strbuf = 0, bool own_strbuf = false, uint32 buf_size = DefaultBufSize); virtual ~coder_strbuf_adapter(); coder_base* get_coder() const { return pCoder; } void set_coder(coder_base* coder, bool own_coder = false); streambuf* get_encoded_stream() const { return pEncodedStream; } void set_encoded_stream(streambuf* stream, bool own_stream = false); void set_encoded_file(const char* file_name, ios::openmode mode); void sputEOF(); virtual void reset(); // same state as the default ctor, but keeps coder and BufferSize bool fail() const { return State == s_error; }protected: enum state { s_init, s_encoding_first_pass, s_encoding_later_pass, s_decoding, s_finished, s_finalized, s_error };protected: // the following function should be called in the destructor of a derived class // (It has to be called if the virtual function sync() is overwritten!) void finalize(); void error(const char* err_msg = 0); virtual streambuf* create_internal_stream(string filename); virtual void destroy_internal_stream(streambuf* int_stream, string filename); virtual void observe_state_change(state new_state) {} // the following functions are inherited from streambuf virtual int overflow(int c); // called when put-buffer buffer full (puts the character to the stream) virtual int underflow(); // called when get-buffer buffer empty (gets a character from stream, but doesn' point past it) virtual int uflow(); // called when get-buffer buffer empty (gets a character from stream, and points past it) virtual streampos seekoff(streamoff off, ios::seekdir way, ios::openmode which); virtual streampos seekpos(streampos sp, ios::openmode which); virtual streambuf* setbuf(char*, streamsize) { return 0; } // do not allow to change buffer#ifdef LEDA_COMPRESSION_WA4 virtual streamsize xsgetn(char* buffer, streamsize count);#endif#ifdef LEDA_COMPRESSION_WA1// work-around for MSVC 6.0 and CXX 5.1 (alpha) and HPUX aCC (see also LEDA/PREAMBLE.h)public: virtual streampos seekpos(streampos sp, int mode) { return seekpos(sp, ios::openmode(mode)); } virtual streampos seekoff(streamoff off, ios::seek_dir way, int mode) { return seekoff(off, way, ios::openmode(mode)); }// Observe: sync must be public below!#endif virtual int sync(); // used to flush buffersprivate: void set_state(state new_state); void start_encoding(); void encode_internal_buffer(); void start_decoding(); int decode_into_internal_buffer();private: state State; char* InternalBuffer; uint32 BufferSize; char TinyBuffer[4]; coder_base* pCoder; streambuf* pEncodedStream; bool OwnCoder; bool OwnEncodedStream; bool SignalEof; int NumOverFlowChars; streambuf* pStreamForBuffering; string TmpFileName;};#ifdef LEDA_COMPRESSION_WA7#undef LEDA_STREAMBUF#endif#if LEDA_ROOT_INCL_ID == 450355#undef LEDA_ROOT_INCL_ID#include <LEDA/POSTAMBLE.h>#endifLEDA_END_NAMESPACE#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -