file.h

Go to the documentation of this file.
00001 /*
00002  * file.h
00003  *
00004  * Operating System file I/O channel class.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
00025  * All Rights Reserved.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Revision: 20385 $
00030  * $Author: rjongbloed $
00031  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00032  */
00033 
00034 
00035 #ifndef _PFILE
00036 #define _PFILE
00037 
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041 
00042 #ifndef _WIN32
00043 #include <sys/stat.h>
00044 #endif
00045 
00046 
00047 
00049 // Binary Files
00050 
00060 class PFile : public PChannel
00061 {
00062   PCLASSINFO(PFile, PChannel);
00063 
00064   public:
00071     PFile();
00072 
00077     enum OpenMode {
00079       ReadOnly,
00081       WriteOnly,
00083       ReadWrite
00084     };
00085 
00101     enum OpenOptions {
00103       ModeDefault = -1, 
00105       MustExist = 0,    
00107       Create = 1,       
00109       Truncate = 2,     
00111       Exclusive = 4,    
00113       Temporary = 8,
00115       DenySharedRead = 16,
00117       DenySharedWrite = 32
00118     };
00119 
00128     PFile(
00129       OpenMode mode,          
00130       int opts = ModeDefault  
00131     );
00132 
00139     PFile(
00140       const PFilePath & name,    
00141       OpenMode mode = ReadWrite, 
00142       int opts = ModeDefault     
00143     );
00144 
00146     ~PFile();
00148 
00149 
00158     Comparison Compare(
00159       const PObject & obj   
00160     ) const;
00162 
00163 
00172     virtual PString GetName() const;
00173 
00185     virtual PBoolean Read(
00186       void * buf,   
00187       PINDEX len    
00188     );
00189 
00199     virtual PBoolean Write(
00200       const void * buf, 
00201       PINDEX len        
00202     );
00203 
00207     virtual PBoolean Close();
00209 
00210 
00220     static PBoolean Exists(
00221       const PFilePath & name  
00222     );
00223 
00231     PBoolean Exists() const;
00232 
00242     static PBoolean Access(
00243       const PFilePath & name, 
00244       OpenMode mode         
00245     );
00246 
00257     PBoolean Access(
00258       OpenMode mode         
00259     );
00260 
00273     static PBoolean Remove(
00274       const PFilePath & name,   // Name of file to delete.
00275       PBoolean force = PFalse      // Force deletion even if file is protected.
00276     );
00277     static PBoolean Remove(
00278       const PString & name,   // Name of file to delete.
00279       PBoolean force = PFalse      // Force deletion even if file is protected.
00280     );
00281 
00294     PBoolean Remove(
00295       PBoolean force = PFalse      // Force deletion even if file is protected.
00296     );
00297 
00313     static PBoolean Rename(
00314       const PFilePath & oldname,  
00315       const PString & newname,    
00316       PBoolean force = PFalse
00318     );
00319 
00336     PBoolean Rename(
00337       const PString & newname,  
00338       PBoolean force = PFalse
00340     );
00341 
00347     static PBoolean Copy(
00348       const PFilePath & oldname,  
00349       const PFilePath & newname,  
00350       PBoolean force = PFalse
00352     );
00353 
00359     PBoolean Copy(
00360       const PFilePath & newname,  
00361       PBoolean force = PFalse
00363     );
00364 
00374     static PBoolean Move(
00375       const PFilePath & oldname,  
00376       const PFilePath & newname,  
00377       PBoolean force = PFalse
00379     );
00380 
00390     PBoolean Move(
00391       const PFilePath & newname,  
00392       PBoolean force = PFalse
00394     );
00396 
00405     const PFilePath & GetFilePath() const;
00406 
00410     void SetFilePath(
00411       const PString & path    
00412     );
00413 
00414 
00426     virtual PBoolean Open(
00427       OpenMode mode = ReadWrite,  // Mode in which to open the file.
00428       int opts = ModeDefault      // Options for open operation.
00429     );
00430 
00441     virtual PBoolean Open(
00442       const PFilePath & name,    // Name of file to open.
00443       OpenMode mode = ReadWrite, // Mode in which to open the file.
00444       int opts = ModeDefault     // #OpenOptions enum# for open operation.
00445     );
00446       
00452     virtual off_t GetLength() const;
00453       
00460     virtual PBoolean SetLength(
00461       off_t len   // New length of file.
00462     );
00463 
00465     enum FilePositionOrigin {
00467       Start = SEEK_SET,   
00469       Current = SEEK_CUR, 
00471       End = SEEK_END      
00472     };
00473 
00484     virtual PBoolean SetPosition(
00485       off_t pos,                         
00486       FilePositionOrigin origin = Start  
00487     );
00488 
00495     virtual off_t GetPosition() const;
00496 
00503     PBoolean IsEndOfFile() const;
00504       
00510     static PBoolean GetInfo(
00511       const PFilePath & name,  // Name of file to get the information on.
00512       PFileInfo & info
00513       // #PFileInfo# structure to receive the information.
00514     );
00515 
00521     PBoolean GetInfo(
00522       PFileInfo & info
00523       // #PFileInfo# structure to receive the information.
00524     );
00525 
00531     static PBoolean SetPermissions(
00532       const PFilePath & name,   // Name of file to change the permission of.
00533       int permissions           // New permissions mask for the file.
00534     );
00540     PBoolean SetPermissions(
00541       int permissions           // New permissions mask for the file.
00542     );
00544 
00545   protected:
00546     // Member variables
00548     PFilePath path;
00549 
00551     PBoolean removeOnClose;
00552 
00553 
00554 // Include platform dependent part of class
00555 #ifdef _WIN32
00556 #include "msos/ptlib/file.h"
00557 #else
00558 #include "unix/ptlib/file.h"
00559 #endif
00560 };
00561 
00562 #endif
00563 
00564 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 23 01:57:54 2009 for PTLib by  doxygen 1.5.1