OW_TmpFile.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 
00036 #ifndef OW_TMPFILE_HPP_INCLUDE_GUARD_
00037 #define OW_TMPFILE_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_IntrusiveReference.hpp"
00040 #include "OW_IntrusiveCountableBase.hpp"
00041 #include "OW_String.hpp"
00042 #ifdef OW_HAVE_UNISTD_H
00043 #include <unistd.h>
00044 #endif
00045 #ifdef OW_WIN32
00046 #include <io.h>
00047 #endif
00048 
00049 namespace OW_NAMESPACE
00050 {
00051 
00052 class OW_COMMON_API TmpFileImpl : public IntrusiveCountableBase
00053 {
00054 public:
00055    TmpFileImpl();
00056    TmpFileImpl(String const& filename);
00057    ~TmpFileImpl();
00058    size_t read(void* bfr, size_t numberOfBytes, long offset=-1L);
00059    size_t write(const void* bfr, size_t numberOfBytes, long offset=-1L);
00060 
00061 #ifdef OW_WIN32
00062    int seek(long offset, int whence=SEEK_SET);
00063    long tell();
00064    void rewind();
00065    int flush();
00066 #else
00067    int seek(long offset, int whence=SEEK_SET)
00068       { return ::lseek(m_hdl, offset, whence); }
00069    long tell() { return ::lseek(m_hdl, 0, SEEK_CUR); }
00070    void rewind() { ::lseek(m_hdl, 0, SEEK_SET); }
00071    int flush() { return 0; }
00072 #endif
00073 
00074    void newFile() { open(); }
00075    long getSize();
00076    String releaseFile();
00077 private:
00078    void open();
00079    int close();
00080    TmpFileImpl(const TmpFileImpl& arg);   // Not implemented
00081    TmpFileImpl& operator= (const TmpFileImpl& arg);   // Not implemented
00082    char* m_filename;
00083 #ifndef OW_WIN32
00084    int m_hdl;
00085 #else
00086    HANDLE m_hdl;
00087 #endif
00088 };
00089 
00090 class OW_COMMON_API TmpFile
00091 {
00092 public:
00093    TmpFile() :
00094       m_impl(new TmpFileImpl) {  }
00095    TmpFile(String const& filename)
00096       : m_impl(new TmpFileImpl(filename))
00097    {}
00098    TmpFile(const TmpFile& arg) :
00099       m_impl(arg.m_impl) {}
00100    TmpFile& operator= (const TmpFile& arg)
00101    {
00102       m_impl = arg.m_impl;
00103       return *this;
00104    }
00105    ~TmpFile()  {  }
00106    size_t read(void* bfr, size_t numberOfBytes, long offset=-1L)
00107    {
00108       return m_impl->read(bfr, numberOfBytes, offset);
00109    }
00110    size_t write(const void* bfr, size_t numberOfBytes, long offset=-1L)
00111    {
00112       return m_impl->write(bfr, numberOfBytes, offset);
00113    }
00114    int seek(long offset, int whence=SEEK_SET)
00115       { return m_impl->seek(offset, whence); }
00116    long tell() { return m_impl->tell(); }
00117    void rewind() { m_impl->rewind(); }
00118    int flush() { return m_impl->flush(); }
00119    void newFile() { m_impl->newFile(); }
00120    long getSize() { return m_impl->getSize(); }
00121    String releaseFile() { return m_impl->releaseFile(); }
00122 private:
00123 
00124 #ifdef OW_WIN32
00125 #pragma warning (push)
00126 #pragma warning (disable: 4251)
00127 #endif
00128 
00129    IntrusiveReference<TmpFileImpl> m_impl;
00130 
00131 #ifdef OW_WIN32
00132 #pragma warning (pop)
00133 #endif
00134 
00135 };
00136 
00137 } // end namespace OW_NAMESPACE
00138 
00139 #endif

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