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 
00045 #ifndef OW_TEMPFILESTREAM_HPP_INCLUDE_GUARD_
00046 #define OW_TEMPFILESTREAM_HPP_INCLUDE_GUARD_
00047 #include "OW_config.h"
00048 #include "OW_Types.hpp"
00049 #include "OW_String.hpp"
00050 #include "OW_AutoPtr.hpp"
00051 #include "OW_CommonFwd.hpp"
00052 
00053 #if defined(OW_HAVE_STREAMBUF)
00054 #include <streambuf>
00055 #elif defined(OW_HAVE_STREAMBUF_H)
00056 #include <streambuf.h>
00057 #endif
00058 
00059 #if defined(OW_HAVE_ISTREAM) && defined(OW_HAVE_OSTREAM)
00060 #include <istream>
00061 #include <ostream>
00062 #else
00063 #include <iostream>
00064 #endif
00065 
00066 namespace OW_NAMESPACE
00067 {
00068 
00069 class OW_COMMON_API TempFileBuffer : public std::streambuf
00070 {
00071 public:
00072    TempFileBuffer(size_t bufSize);
00073    TempFileBuffer(String const& filename, size_t bufSize);
00074    ~TempFileBuffer();
00075    std::streamsize getSize();
00076    void rewind();
00077    void reset();
00078    String releaseFile();
00079    bool usingTempFile() const;
00080 protected:
00081    
00082    int underflow();
00083    
00084    std::streamsize xsputn(const char* s, std::streamsize n);
00085    virtual int overflow(int c);
00086    
00087    void initBuffers();
00088    void initGetBuffer();
00089    void initPutBuffer();
00090    int buffer_to_device(const char* c, int n);
00091    int buffer_from_device(char* c, int n);
00092 private:
00093    size_t m_bufSize;
00094    char* m_buffer;
00095    TmpFile* m_tempFile;
00096    std::streamsize m_readPos;
00097    std::streamsize m_writePos;
00098    bool m_isEOF;
00099    int buffer_in();
00100    int buffer_out();
00101    
00102    TempFileBuffer(const TempFileBuffer& arg);
00103    TempFileBuffer& operator=(const TempFileBuffer& arg);
00104 };
00105 class OW_COMMON_API TempFileStream : public std::iostream
00106 {
00107 public:
00108    TempFileStream(size_t bufSize = 4096);
00109    TempFileStream(String const& filename, size_t bufSize = 4096);
00110    std::streamsize getSize() { return m_buffer->getSize(); }
00111    void rewind();
00112    void reset();
00113    String releaseFile();
00114    bool usingTempFile() const;
00115 private:
00116 
00117 #ifdef OW_WIN32
00118 #pragma warning (push)
00119 #pragma warning (disable: 4251)
00120 #endif
00121 
00122    AutoPtr<TempFileBuffer> m_buffer;
00123 
00124 #ifdef OW_WIN32
00125 #pragma warning (pop)
00126 #endif
00127 
00128    
00129    TempFileStream(const TempFileStream&);
00130    TempFileStream& operator=(const TempFileStream&);
00131 };
00132 
00133 } 
00134 
00135 #endif