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