Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

piodevice.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2003  Christian Prochnow <cproch@seculogix.de>
00004  *
00005  *   This library is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU Lesser General Public
00007  *   License as published by the Free Software Foundation; either
00008  *   version 2 of the License, or (at your option) any later version.
00009  *
00010  *   This library is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *   Lesser General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU Lesser General Public
00016  *   License along with this library; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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

Generated on Fri Mar 12 21:08:31 2004 for P::Classes by doxygen 1.3.3