![]() |
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,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (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 * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: FXIO.h,v 1.30 2009/01/06 13:07:24 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXIO_H 00024 #define FXIO_H 00025 00026 00027 00028 namespace FX { 00029 00030 00031 /** 00032 * FXIO manipulates a handle to an abstract i/o device. 00033 * The various subclasses of FXIO perform i/o on files, sockets, 00034 * pipes, and possibly other devices. 00035 */ 00036 class FXAPI FXIO { 00037 protected: 00038 FXInputHandle device; // Device (file/pipe/socket/whatever) 00039 FXuint access; // Access being performed 00040 private: 00041 FXIO(const FXIO&); 00042 FXIO &operator=(const FXIO&); 00043 public: 00044 00045 /// File modes 00046 enum { 00047 00048 /// Permissions 00049 OtherRead = 0x00004, /// Others have read permission 00050 OtherWrite = 0x00002, /// Others have write permisson 00051 OtherExec = 0x00001, /// Others have execute permission 00052 OtherReadWrite = OtherRead|OtherWrite, /// Others have read and write permission 00053 OtherFull = OtherReadWrite|OtherExec, /// Others have full access 00054 00055 GroupRead = 0x00020, /// Group has read permission 00056 GroupWrite = 0x00010, /// Group has write permission 00057 GroupExec = 0x00008, /// Group has execute permission 00058 GroupReadWrite = GroupRead|GroupWrite, /// Group has read and write permission 00059 GroupFull = GroupReadWrite|GroupExec, /// Group has full access 00060 00061 OwnerRead = 0x00100, /// Owner has read permission 00062 OwnerWrite = 0x00080, /// Owner has write permission 00063 OwnerExec = 0x00040, /// Owner has execute permission 00064 OwnerReadWrite = OwnerRead|OwnerWrite, /// Owner has read and write permission 00065 OwnerFull = OwnerReadWrite|OwnerExec, /// Owner has full access 00066 00067 AllRead = OtherRead|GroupRead|OwnerRead, /// Read permission for all 00068 AllWrite = OtherWrite|GroupWrite|OwnerWrite, /// Write permisson for all 00069 AllExec = OtherExec|GroupExec|OwnerExec, /// Execute permission for all 00070 AllReadWrite = AllRead|AllWrite, /// Read and write permission for all 00071 AllFull = AllReadWrite|AllExec, /// Full access for all 00072 00073 /// Other flags 00074 Hidden = 0x00200, /// Hidden file 00075 Directory = 0x00400, /// Is directory 00076 File = 0x00800, /// Is regular file 00077 SymLink = 0x01000, /// Is symbolic link 00078 00079 /// Special mode bits 00080 SetUser = 0x02000, /// Set user id 00081 SetGroup = 0x04000, /// Set group id 00082 Sticky = 0x08000, /// Sticky bit 00083 00084 /// Device special files 00085 Character = 0x10000, /// Character device 00086 Block = 0x20000, /// Block device 00087 Socket = 0x40000, /// Socket device 00088 Fifo = 0x80000 /// Fifo device 00089 }; 00090 00091 /// Access modes 00092 enum { 00093 00094 /// Basic access options 00095 NoAccess = 0, /// No access 00096 ReadOnly = 1, /// Open for reading 00097 WriteOnly = 2, /// Open for writing 00098 ReadWrite = ReadOnly|WriteOnly, /// Open for both read and write 00099 Append = 4, /// Open for append 00100 Truncate = 8, /// Truncate to zero when writing 00101 Create = 16, /// Create if it doesn't exist 00102 Exclusive = 32, /// Fail if trying to create a file which already exists 00103 NonBlocking = 64, /// Non-blocking i/o 00104 Executable = 128, /// Executable (memory map) 00105 OwnHandle = 256, /// File handle is ours 00106 NoAccessTime = 512, /// Don't change access time of file 00107 00108 /// Convenience access options 00109 Reading = ReadOnly, /// Normal options for reading 00110 Writing = ReadWrite|Create|Truncate /// Normal options for writing 00111 }; 00112 00113 /// Positioning modes 00114 enum { 00115 Begin = 0, /// Position from the begin (default) 00116 Current = 1, /// Position relative to current position 00117 End = 2 /// Position from the end 00118 }; 00119 00120 public: 00121 00122 /// Construct 00123 FXIO(); 00124 00125 /// Open device with access mode m and handle h 00126 virtual FXbool open(FXInputHandle h,FXuint m); 00127 00128 /// Is readable 00129 FXbool isReadable() const; 00130 00131 /// Is writable 00132 FXbool isWritable() const; 00133 00134 /// Return access mode 00135 FXuint mode() const { return access; } 00136 00137 /// Return handle 00138 FXInputHandle handle() const { return device; } 00139 00140 /// Return true if open 00141 virtual FXbool isOpen() const; 00142 00143 /// Return true if serial access only 00144 virtual FXbool isSerial() const; 00145 00146 /// Attach existing device handle, taking ownership of the handle 00147 virtual void attach(FXInputHandle h,FXuint m); 00148 00149 /// Detach device handle, disowning the handle 00150 virtual void detach(); 00151 00152 /// Get current file position 00153 virtual FXlong position() const; 00154 00155 /// Change file position, returning new position from start 00156 virtual FXlong position(FXlong offset,FXuint from=FXIO::Begin); 00157 00158 /// Read block of bytes, returning number of bytes read 00159 virtual FXival readBlock(void* data,FXival count); 00160 00161 /// Write block of bytes, returning number of bytes written 00162 virtual FXival writeBlock(const void* data,FXival count); 00163 00164 /// Truncate file 00165 virtual FXlong truncate(FXlong size); 00166 00167 /// Flush to disk 00168 virtual FXbool flush(); 00169 00170 /// Test if we're at the end 00171 virtual FXbool eof(); 00172 00173 /// Return size of i/o device 00174 virtual FXlong size(); 00175 00176 /// Close handle 00177 virtual FXbool close(); 00178 00179 /// Destroy and close 00180 virtual ~FXIO(); 00181 }; 00182 00183 } 00184 00185 #endif
![]() |