00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __UT_FPStream__
00023 #define __UT_FPStream__
00024
00025 #include "UT_API.h"
00026
00027 #include <istream>
00028 #include <ostream>
00029 #include <streambuf>
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include "UT_Assert.h"
00033
00034 #ifdef GCC3
00035 using namespace std;
00036 #endif
00037
00038
00039
00040
00041
00042
00043 class UT_API UT_FPOutBuf : public std::streambuf {
00044 public:
00045 UT_FPOutBuf (FILE *_fp)
00046 : myFP(_fp)
00047 {
00048 }
00049 void close()
00050 {
00051 UT_ASSERT(myFP);
00052 ::fclose(myFP);
00053 myFP = 0;
00054 }
00055
00056 protected:
00057
00058 virtual int_type overflow(int_type c)
00059 {
00060 UT_ASSERT(myFP);
00061 return putc(c, myFP);
00062 }
00063
00064
00065 virtual pos_type seekoff(off_type _Off,
00066 ios_base::seekdir _Way,
00067 ios_base::openmode = ios::out)
00068 {
00069
00070
00071 UT_ASSERT(myFP);
00072 UT_ASSERT(_Off == 0);
00073 UT_ASSERT(_Way == ios_base::cur);
00074 return (pos_type)ftell(myFP);
00075 }
00076
00077
00078 virtual std::streamsize xsputn (const char* s, std::streamsize num)
00079 {
00080 UT_ASSERT(myFP);
00081 return fwrite(s, 1, num, myFP);
00082 }
00083
00084 protected:
00085 FILE *myFP;
00086 };
00087
00088 class UT_API UT_OFPStream : public std::ostream {
00089 protected:
00090 UT_FPOutBuf buf;
00091 public:
00092 UT_OFPStream (FILE *fp) : std::ostream(0), buf(fp)
00093 {
00094 rdbuf(&buf);
00095 }
00096 void close() { buf.close(); }
00097 };
00098
00099 #endif
00100