Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

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  * $Log: file.h,v $
00030  * Revision 1.42  2003/09/26 09:58:50  rogerhardiman
00031  * Move #include <sys/stat.h> from the unix file.h to the main file.h
00032  * FreeBSD's sys/stat.h includes extern "C" for some prototypes and you
00033  * cannot have an extern "C" in the middle of a C++ class
00034  *
00035  * Revision 1.41  2003/09/17 05:41:58  csoutheren
00036  * Removed recursive includes
00037  *
00038  * Revision 1.40  2003/09/17 01:18:02  csoutheren
00039  * Removed recursive include file system and removed all references
00040  * to deprecated coooperative threading support
00041  *
00042  * Revision 1.39  2002/09/16 01:08:59  robertj
00043  * Added #define so can select if #pragma interface/implementation is used on
00044  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00045  *
00046  * Revision 1.38  2002/07/02 08:00:55  craigs
00047  * Also made GetPosition, SetPosition and SetLength virtual as well
00048  *
00049  * Revision 1.37  2002/07/02 07:59:42  craigs
00050  * Added virtual to GetLength call
00051  *
00052  * Revision 1.36  2002/01/13 20:54:55  rogerh
00053  * Make the other Open() virtual so it can be overridden (eg in PWAVFile)
00054  *
00055  * Revision 1.35  2001/05/22 12:49:32  robertj
00056  * Did some seriously wierd rewrite of platform headers to eliminate the
00057  *   stupid GNU compiler warning about braces not matching.
00058  *
00059  * Revision 1.34  2000/09/27 05:58:07  craigs
00060  * Added virtual to PFile::Open to allow overriding in descandant classes
00061  *
00062  * Revision 1.33  2000/07/09 14:05:46  robertj
00063  * Added file share options.
00064  *
00065  * Revision 1.32  1999/06/13 13:54:07  robertj
00066  * Added PConsoleChannel class for access to stdin/stdout/stderr.
00067  *
00068  * Revision 1.31  1999/06/09 02:05:20  robertj
00069  * Added ability to open file as standard input, output and error streams.
00070  *
00071  * Revision 1.30  1999/03/09 02:59:49  robertj
00072  * Changed comments to doc++ compatible documentation.
00073  *
00074  * Revision 1.29  1999/02/16 08:07:11  robertj
00075  * MSVC 6.0 compatibility changes.
00076  *
00077  * Revision 1.28  1998/09/23 06:20:35  robertj
00078  * Added open source copyright license.
00079  *
00080  * Revision 1.27  1995/07/31 12:15:43  robertj
00081  * Removed PContainer from PChannel ancestor.
00082  *
00083  * Revision 1.26  1995/06/17 11:12:33  robertj
00084  * Documentation update.
00085  *
00086  * Revision 1.25  1995/04/22 00:43:57  robertj
00087  * Added Move() function and changed semantics of Rename().
00088  * Changed all file name strings to PFilePath objects.
00089  *
00090  * Revision 1.24  1995/03/14 12:41:23  robertj
00091  * Updated documentation to use HTML codes.
00092  *
00093  * Revision 1.23  1995/03/12  04:37:13  robertj
00094  * Moved GetHandle() function from PFile to PChannel.
00095  *
00096  * Revision 1.22  1995/01/14  06:22:11  robertj
00097  * Documentation
00098  *
00099  * Revision 1.21  1994/12/21  11:52:54  robertj
00100  * Documentation and variable normalisation.
00101  *
00102  * Revision 1.20  1994/08/23  11:32:52  robertj
00103  * Oops
00104  *
00105  * Revision 1.19  1994/08/22  00:46:48  robertj
00106  * Added pragma fro GNU C++ compiler.
00107  *
00108  * Revision 1.18  1994/08/21  23:43:02  robertj
00109  * Added "remove on close" feature for temporary files.
00110  * Added "force" option to Remove/Rename etc to override write protection.
00111  * Added function to set file permissions.
00112  *
00113  * Revision 1.17  1994/07/17  10:46:06  robertj
00114  * Moved data to platform dependent files.
00115  *
00116  * Revision 1.16  1994/06/25  11:55:15  robertj
00117  * Unix version synchronisation.
00118  *
00119  * Revision 1.15  1994/04/20  12:17:44  robertj
00120  * Split name into PFilePath
00121  *
00122  * Revision 1.14  1994/04/01  14:11:03  robertj
00123  * Added const to functions.
00124  * Added SetName function.
00125  *
00126  * Revision 1.13  1994/03/07  07:38:19  robertj
00127  * Major enhancementsacross the board.
00128  *
00129  * Revision 1.12  1994/01/13  03:40:22  robertj
00130  * Added hidden flag to file info.
00131  *
00132  * Revision 1.12  1994/01/13  03:36:48  robertj
00133  * Created intermediate class PInteractorLayout for dialog-ish windows.
00134  *
00135  * Revision 1.11  1994/01/03  04:42:23  robertj
00136  * Mass changes to common container classes and interactors etc etc etc.
00137  *
00138  * Revision 1.10  1993/12/31  06:45:38  robertj
00139  * Made inlines optional for debugging purposes.
00140  *
00141  * Revision 1.9  1993/09/27  16:35:25  robertj
00142  * Changed GetName() to GetTitle(), better naming convention.
00143  * Moved internal functions to private section.
00144  *
00145  * Revision 1.8  1993/08/31  03:38:02  robertj
00146  * Changed PFile::Status to PFile::Info due to X-Windows compatibility.
00147  *
00148  * Revision 1.7  1993/08/27  18:17:47  robertj
00149  * Moved code from MS-DOS platform to common files.
00150  *
00151  * Revision 1.6  1993/08/21  04:40:19  robertj
00152  * Added Copy() function.
00153  *
00154  * Revision 1.5  1993/08/21  01:50:33  robertj
00155  * Made Clone() function optional, default will assert if called.
00156  *
00157  * Revision 1.4  1993/08/01  14:05:27  robertj
00158  * Added GetFileName() function required for proper portability.
00159  * Improved some comments.
00160  *
00161  * Revision 1.3  1993/07/14  12:49:16  robertj
00162  * Fixed RCS keywords.
00163  *
00164  */
00165 
00166 
00167 #ifndef _PFILE
00168 #define _PFILE
00169 
00170 #ifdef P_USE_PRAGMA
00171 #pragma interface
00172 #endif
00173 
00174 #ifndef _WIN32
00175 #include <sys/stat.h>
00176 #endif
00177 
00178 
00179 
00181 // Binary Files
00182 
00192 class PFile : public PChannel
00193 {
00194   PCLASSINFO(PFile, PChannel);
00195 
00196   public:
00203     PFile();
00204 
00209     enum OpenMode {
00211       ReadOnly,
00213       WriteOnly,
00215       ReadWrite
00216     };
00217 
00233     enum OpenOptions {
00235       ModeDefault = -1, 
00237       MustExist = 0,    
00239       Create = 1,       
00241       Truncate = 2,     
00243       Exclusive = 4,    
00245       Temporary = 8,
00247       DenySharedRead = 16,
00249       DenySharedWrite = 32
00250     };
00251 
00260     PFile(
00261       OpenMode mode,          
00262       int opts = ModeDefault  
00263     );
00264 
00271     PFile(
00272       const PFilePath & name,    
00273       OpenMode mode = ReadWrite, 
00274       int opts = ModeDefault     
00275     );
00276 
00278     ~PFile();
00280 
00281 
00290     Comparison Compare(
00291       const PObject & obj   
00292     ) const;
00294 
00295 
00304     virtual PString GetName() const;
00305 
00317     virtual BOOL Read(
00318       void * buf,   
00319       PINDEX len    
00320     );
00321 
00331     virtual BOOL Write(
00332       const void * buf, 
00333       PINDEX len        
00334     );
00335 
00339     virtual BOOL Close();
00341 
00342 
00352     static BOOL Exists(
00353       const PFilePath & name  
00354     );
00355 
00363     BOOL Exists() const;
00364 
00374     static BOOL Access(
00375       const PFilePath & name, 
00376       OpenMode mode         
00377     );
00378 
00389     BOOL Access(
00390       OpenMode mode         
00391     );
00392 
00405     static BOOL Remove(
00406       const PFilePath & name,   // Name of file to delete.
00407       BOOL force = FALSE      // Force deletion even if file is protected.
00408     );
00409 
00422     BOOL Remove(
00423       BOOL force = FALSE      // Force deletion even if file is protected.
00424     );
00425 
00441     static BOOL Rename(
00442       const PFilePath & oldname,  
00443       const PString & newname,    
00444       BOOL force = FALSE
00446     );
00447 
00464     BOOL Rename(
00465       const PString & newname,  
00466       BOOL force = FALSE
00468     );
00469 
00475     static BOOL Copy(
00476       const PFilePath & oldname,  
00477       const PFilePath & newname,  
00478       BOOL force = FALSE
00480     );
00481 
00487     BOOL Copy(
00488       const PFilePath & newname,  
00489       BOOL force = FALSE
00491     );
00492 
00502     static BOOL Move(
00503       const PFilePath & oldname,  
00504       const PFilePath & newname,  
00505       BOOL force = FALSE
00507     );
00508 
00518     BOOL Move(
00519       const PFilePath & newname,  
00520       BOOL force = FALSE
00522     );
00524 
00533     const PFilePath & GetFilePath() const;
00534 
00538     void SetFilePath(
00539       const PString & path    
00540     );
00541 
00542 
00554     virtual BOOL Open(
00555       OpenMode mode = ReadWrite,  // Mode in which to open the file.
00556       int opts = ModeDefault      // Options for open operation.
00557     );
00558 
00569     virtual BOOL Open(
00570       const PFilePath & name,    // Name of file to open.
00571       OpenMode mode = ReadWrite, // Mode in which to open the file.
00572       int opts = ModeDefault     // #OpenOptions enum# for open operation.
00573     );
00574       
00580     virtual off_t GetLength() const;
00581       
00588     virtual BOOL SetLength(
00589       off_t len   // New length of file.
00590     );
00591 
00593     enum FilePositionOrigin {
00595       Start = SEEK_SET,   
00597       Current = SEEK_CUR, 
00599       End = SEEK_END      
00600     };
00601 
00612     virtual BOOL SetPosition(
00613       off_t pos,                         
00614       FilePositionOrigin origin = Start  
00615     );
00616 
00623     virtual off_t GetPosition() const;
00624 
00631     BOOL IsEndOfFile() const;
00632       
00638     static BOOL GetInfo(
00639       const PFilePath & name,  // Name of file to get the information on.
00640       PFileInfo & info
00641       // #PFileInfo# structure to receive the information.
00642     );
00643 
00649     BOOL GetInfo(
00650       PFileInfo & info
00651       // #PFileInfo# structure to receive the information.
00652     );
00653 
00659     static BOOL SetPermissions(
00660       const PFilePath & name,   // Name of file to change the permission of.
00661       int permissions           // New permissions mask for the file.
00662     );
00668     BOOL SetPermissions(
00669       int permissions           // New permissions mask for the file.
00670     );
00672 
00673   protected:
00674     // Member variables
00676     PFilePath path;
00677 
00679     BOOL removeOnClose;
00680 
00681 
00682 // Include platform dependent part of class
00683 #ifdef _WIN32
00684 #include "msos/ptlib/file.h"
00685 #else
00686 #include "unix/ptlib/file.h"
00687 #endif
00688 };
00689 
00690 #endif
00691 
00692 // End Of File ///////////////////////////////////////////////////////////////

Generated on Sat Dec 22 16:46:50 2007 for PWLib by  doxygen 1.4.2