00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00047 #ifndef BLOCXX_TEMPFILESTREAM_HPP_INCLUDE_GUARD_
00048 #define BLOCXX_TEMPFILESTREAM_HPP_INCLUDE_GUARD_
00049 #include "blocxx/BLOCXX_config.h"
00050 #include "blocxx/Types.hpp"
00051 #include "blocxx/String.hpp"
00052 #include "blocxx/AutoPtr.hpp"
00053 #include "blocxx/CommonFwd.hpp"
00054
00055 #if defined(BLOCXX_HAVE_STREAMBUF)
00056 #include <streambuf>
00057 #elif defined(BLOCXX_HAVE_STREAMBUF_H)
00058 #include <streambuf.h>
00059 #endif
00060
00061 #if defined(BLOCXX_HAVE_ISTREAM) && defined(BLOCXX_HAVE_OSTREAM)
00062 #include <istream>
00063 #include <ostream>
00064 #else
00065 #include <iostream>
00066 #endif
00067
00068 namespace BLOCXX_NAMESPACE
00069 {
00070
00071 class BLOCXX_COMMON_API TempFileBuffer : public std::streambuf
00072 {
00073 public:
00074 TempFileBuffer(size_t bufSize);
00075 TempFileBuffer(String const& filename, size_t bufSize);
00076 ~TempFileBuffer();
00077 std::streamsize getSize();
00078 void rewind();
00079 void reset();
00080 String releaseFile();
00081 bool usingTempFile() const;
00082 protected:
00083
00084 int underflow();
00085
00086 std::streamsize xsputn(const char* s, std::streamsize n);
00087 virtual int overflow(int c);
00088
00089 void initBuffers();
00090 void initGetBuffer();
00091 void initPutBuffer();
00092 int buffer_to_device(const char* c, int n);
00093 int buffer_from_device(char* c, int n);
00094 private:
00095 size_t m_bufSize;
00096 char* m_buffer;
00097 TmpFile* m_tempFile;
00098 std::streamsize m_readPos;
00099 std::streamsize m_writePos;
00100 bool m_isEOF;
00101 int buffer_in();
00102 int buffer_out();
00103
00104 TempFileBuffer(const TempFileBuffer& arg);
00105 TempFileBuffer& operator=(const TempFileBuffer& arg);
00106 };
00107 class BLOCXX_COMMON_API TempFileStream : public std::iostream
00108 {
00109 public:
00110 TempFileStream(size_t bufSize = 4096);
00111 TempFileStream(String const& filename, size_t bufSize = 4096);
00112 std::streamsize getSize() { return m_buffer->getSize(); }
00113 void rewind();
00114 void reset();
00115 String releaseFile();
00116 bool usingTempFile() const;
00117 private:
00118
00119 #ifdef BLOCXX_WIN32
00120 #pragma warning (push)
00121 #pragma warning (disable: 4251)
00122 #endif
00123
00124 AutoPtr<TempFileBuffer> m_buffer;
00125
00126 #ifdef BLOCXX_WIN32
00127 #pragma warning (pop)
00128 #endif
00129
00130
00131 TempFileStream(const TempFileStream&);
00132 TempFileStream& operator=(const TempFileStream&);
00133 };
00134
00135 }
00136
00137 #endif
00138