Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * I / O D e v i c e C l a s s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2005,2006 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXIO.h,v 1.8 2006/01/22 17:58:04 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXIO_H 00025 #define FXIO_H 00026 00027 00028 00029 namespace FX { 00030 00031 00032 /** 00033 * FXIO manipulates a handle to an abstract i/o device. 00034 * The various subclasses of FXIO perform i/o on files, sockets, 00035 * pipes, and possibly other devices. 00036 */ 00037 class FXAPI FXIO { 00038 protected: 00039 FXInputHandle device; // Device (file/pipe/socket/whatever) 00040 FXuint access; // Access being performed 00041 private: 00042 FXIO(const FXIO&); 00043 FXIO &operator=(const FXIO&); 00044 public: 00045 00046 /// File modes 00047 enum { 00048 00049 /// Permissions 00050 OtherRead = 0x00004, /// Others have read permission 00051 OtherWrite = 0x00002, /// Others have write permisson 00052 OtherExec = 0x00001, /// Others have execute permission 00053 OtherReadWrite = 0x00006, /// Others have read and write permission 00054 OtherFull = 0x00007, /// Others have full access 00055 00056 GroupRead = 0x00020, /// Group has read permission 00057 GroupWrite = 0x00010, /// Group has write permission 00058 GroupExec = 0x00008, /// Group has execute permission 00059 GroupReadWrite = 0x00030, /// Group has read and write permission 00060 GroupFull = 0x00038, /// Group has full access 00061 00062 OwnerRead = 0x00100, /// Owner has read permission 00063 OwnerWrite = 0x00080, /// Owner has write permission 00064 OwnerExec = 0x00040, /// Owner has execute permission 00065 OwnerReadWrite = 0x00180, /// Owner has read and write permission 00066 OwnerFull = 0x001C0, /// Owner has full access 00067 00068 /// Other flags 00069 Hidden = 0x00200, /// Hidden file 00070 Directory = 0x00400, /// Is directory 00071 File = 0x00800, /// Is regular file 00072 SymLink = 0x01000, /// Is symbolic link 00073 00074 /// Special mode bits 00075 SetUser = 0x02000, /// Set user id 00076 SetGroup = 0x04000, /// Set group id 00077 Sticky = 0x08000, /// Sticky bit 00078 00079 /// Device special files 00080 Character = 0x10000, /// Character device 00081 Block = 0x20000, /// Block device 00082 Socket = 0x40000, /// Socket device 00083 Fifo = 0x80000 /// Fifo device 00084 }; 00085 00086 /// Access modes 00087 enum { 00088 00089 /// Basic access options 00090 NoAccess = 0, /// No access 00091 ReadOnly = 1, /// Open for reading 00092 WriteOnly = 2, /// Open for writing 00093 ReadWrite = 3, /// Open for read and write 00094 Append = 4, /// Open for append 00095 Truncate = 8, /// Truncate to zero when writing 00096 Create = 16, /// Create if it doesn't exist 00097 Exclusive = 32, /// Fail if trying to create a file which already exists 00098 NonBlocking = 64, /// Non-blocking i/o 00099 00100 /// Convenience access options 00101 Reading = ReadOnly, /// Normal options for reading 00102 Writing = ReadWrite|Create|Truncate /// Normal options for writing 00103 }; 00104 00105 /// Positioning modes 00106 enum { 00107 Begin = 0, /// Position from the begin (default) 00108 Current = 1, /// Position relative to current position 00109 End = 2 /// Position from the end 00110 }; 00111 00112 public: 00113 00114 /// Construct 00115 FXIO(); 00116 00117 /// Open device with access mode and handle 00118 virtual bool open(FXInputHandle handle,FXuint mode); 00119 00120 /// Return true if open 00121 virtual bool isOpen() const; 00122 00123 /// Return access mode 00124 FXuint mode() const { return access; } 00125 00126 /// Return handle 00127 FXInputHandle handle() const { return device; } 00128 00129 /// Attach existing device handle 00130 virtual void attach(FXInputHandle handle,FXuint mode); 00131 00132 /// Detach device handle 00133 virtual void detach(); 00134 00135 /// Get current file position 00136 virtual FXlong position() const; 00137 00138 /// Change file position, returning new position from start 00139 virtual FXlong position(FXlong offset,FXuint from=FXIO::Begin); 00140 00141 /// Read block of bytes, returning number of bytes read 00142 virtual FXival readBlock(void* data,FXival count); 00143 00144 /// Write block of bytes, returning number of bytes written 00145 virtual FXival writeBlock(const void* data,FXival count); 00146 00147 /// Truncate file 00148 virtual FXlong truncate(FXlong size); 00149 00150 /// Flush to disk 00151 virtual bool flush(); 00152 00153 /// Test if we're at the end 00154 virtual bool eof(); 00155 00156 /// Return size of i/o device 00157 virtual FXlong size(); 00158 00159 /// Close handle 00160 virtual bool close(); 00161 00162 /// Destroy and close 00163 virtual ~FXIO(); 00164 }; 00165 00166 } 00167 00168 #endif
Copyright © 1997-2005 Jeroen van der Zijp |