OW_TempFileStream.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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    // for input
00082    int underflow();
00083    // for output
00084    std::streamsize xsputn(const char* s, std::streamsize n);
00085    virtual int overflow(int c);
00086    //virtual int sync();
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    // prohibit copying and assigning
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    // disallow copying and assigning
00129    TempFileStream(const TempFileStream&);
00130    TempFileStream& operator=(const TempFileStream&);
00131 };
00132 
00133 } // end namespace OW_NAMESPACE
00134 
00135 #endif

Generated on Thu Feb 9 08:48:16 2006 for openwbem by  doxygen 1.4.6