00001 #ifndef STRBUFBASE_H
00002 #define STRBUFBASE_H
00003 #if defined _MSC_VER && _MSC_VER >= 1000
00004 #pragma once
00005 #endif // _MSC_VER >= 1000
00006 #include "Env.h"
00007 #include <cstdio>
00008 #include <iostream>
00009
00010 #ifdef __BORLANDC__
00011 #define BCC_CDECL __cdecl
00012 #else
00013 #define BCC_CDECL
00014 #endif
00015
00016 namespace Spr {
00017
00018 template <class T>
00019 class UTPrintfStream:public T
00020 {
00021 public:
00022 explicit UTPrintfStream(std::streambuf *sb)
00023 :T(sb)
00024 {
00025 }
00026 int SPR_CDECL printf(char* fmt, ...)
00027 {
00028 char buf[4096];
00029 return _vsnprintf(buf, sizeof(buf), fmt, (char*)&fmt);
00030 }
00031 };
00032 class SPR_DLL UTStreambufBase:public std::streambuf
00033 {
00034 char* pbuf,*gbuf;
00035 int plen, glen;
00036 public:
00037 int lahead;
00038 #ifdef _MSC_VER
00039 UTStreambufBase(std::_Uninitialized);
00040 #endif
00041 UTStreambufBase(char* gb, int gl, char* pb, int pl);
00042 BCC_CDECL ~UTStreambufBase();
00043 protected:
00044 virtual int BCC_CDECL overflow(int c = EOF);
00045 virtual int BCC_CDECL underflow();
00046 virtual int BCC_CDECL sync();
00047 virtual pos_type BCC_CDECL seekoff(off_type off, std::ios_base::seekdir way,
00048 std::ios_base::openmode which = std::ios_base::in | std::ios_base::out);
00049
00050 virtual unsigned int read(void* buf, unsigned int bufLen)=0;
00051 virtual unsigned int write(void* buf, unsigned int bufLen)=0;
00052 virtual int in_avail_stream(){return 0;}
00053 };
00054
00055 }
00056 #endif