00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _piodevice_h_
00021 #define _piodevice_h_
00022
00023 #include <pclasses/pconfig.h>
00024 #include <pclasses/pexport.h>
00025 #include <pclasses/pexception.h>
00026 #include <pclasses/ptypes.h>
00027
00028 #ifdef WIN32
00029 #include <windows.h>
00030 #endif
00031
00032 namespace P {
00033
00034 #ifdef WIN32
00035 typedef HANDLE io_handle_t;
00036 #else
00037 typedef int io_handle_t;
00038 enum { INVALID_HANDLE_VALUE = -1 };
00039 #endif
00040
00042
00046 class PCORE_EXPORT IODevice {
00047 public:
00049
00052 enum accessMode_t {
00053 Read,
00054 Write,
00055 ReadWrite
00056 };
00057
00059
00063 enum shareMode_t {
00064 AllowNone,
00065 AllowRead,
00066 AllowWrite,
00067 AllowReadWrite
00068 };
00069
00071 enum seekMode_t {
00072 seekSet,
00073 seekCurrent,
00074 seekEnd
00075 };
00076
00078 IODevice() throw()
00079 : m_handle(INVALID_HANDLE_VALUE)
00080 { }
00081
00083
00086 IODevice(io_handle_t handle) throw(IOError);
00087
00089 IODevice(const IODevice& dev) throw(IOError);
00090
00092 virtual ~IODevice() throw();
00093
00095 virtual void close() throw(IOError);
00096
00098 virtual size_t write(const char* buffer, size_t count) throw(IOError);
00099
00101 virtual size_t read(char* buffer, size_t count) throw(IOError);
00102
00104
00110 virtual size_t peek(char* buffer, size_t count) throw(IOError)
00111 { throw IOError(0, "peek() is not supported on this type of device", P_SOURCEINFO); }
00112
00114 virtual void commit() throw(IOError);
00115
00116 #ifndef HAVE_LARGEFILE64
00117 virtual off_t seek(off_t offset, seekMode_t mode) throw(IOError);
00118 #else
00119 virtual off64_t seek(off64_t offset, seekMode_t mode) throw(IOError);
00120 #endif
00121
00123 virtual bool isSeekable() const throw();
00124
00126 inline bool isValid() const throw()
00127 { return (m_handle != INVALID_HANDLE_VALUE); }
00128
00129 IODevice& operator=(const IODevice& dev) throw(IOError);
00130
00132 inline io_handle_t handle() const throw()
00133 { return m_handle; }
00134
00135 static void copy(IODevice& src, IODevice& dst, bool commit = false);
00136
00137 protected:
00138 inline void setHandle(io_handle_t handle) throw()
00139 { m_handle = handle; }
00140
00141 private:
00142 io_handle_t m_handle;
00143 };
00144
00145 }
00146
00147 #endif