pdirect.h

Go to the documentation of this file.
00001 /*
00002  * pdirect.h
00003  *
00004  * File system directory 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: pdirect.h,v $
00030  * Revision 1.43  2005/11/25 03:43:47  csoutheren
00031  * Fixed function argument comments to be compatible with Doxygen
00032  *
00033  * Revision 1.42  2004/09/17 03:51:15  csoutheren
00034  * More fixes for PDirectory problem
00035  *
00036  * Revision 1.42  2004/09/15 05:11:39  csoutheren
00037  * Fixed problem with PDirectory destructor not calling Close()
00038  * Thanks to Paul Long
00039  *
00040  * Revision 1.41  2003/09/17 05:41:58  csoutheren
00041  * Removed recursive includes
00042  *
00043  * Revision 1.40  2003/09/17 01:18:02  csoutheren
00044  * Removed recursive include file system and removed all references
00045  * to deprecated coooperative threading support
00046  *
00047  * Revision 1.39  2003/06/06 15:04:17  dsandras
00048  *
00049  * Fixed compilation warning with gcc 3.3 by removing the PINLINE
00050  *
00051  * Revision 1.38  2002/11/20 00:13:43  robertj
00052  * Fixed some documentation
00053  *
00054  * Revision 1.37  2002/11/19 12:07:02  robertj
00055  * Added function to get root directory.
00056  *
00057  * Revision 1.36  2002/11/19 10:34:59  robertj
00058  * Added function to extract a path as an array of directories components.
00059  *
00060  * Revision 1.35  2002/09/16 01:08:59  robertj
00061  * Added #define so can select if #pragma interface/implementation is used on
00062  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00063  *
00064  * Revision 1.34  2001/05/22 12:49:32  robertj
00065  * Did some seriously wierd rewrite of platform headers to eliminate the
00066  *   stupid GNU compiler warning about braces not matching.
00067  *
00068  * Revision 1.33  2001/02/13 06:55:21  robertj
00069  * Fixed problem with operator= in PDirectory class, part of larger change previously made.
00070  *
00071  * Revision 1.32  2000/06/26 11:17:19  robertj
00072  * Nucleus++ port (incomplete).
00073  *
00074  * Revision 1.31  2000/04/03 18:41:27  robertj
00075  * Fixed BeOS compatibility problem with openlog() function.
00076  *
00077  * Revision 1.30  1999/03/09 02:59:50  robertj
00078  * Changed comments to doc++ compatible documentation.
00079  *
00080  * Revision 1.29  1999/02/16 08:11:09  robertj
00081  * MSVC 6.0 compatibility changes.
00082  *
00083  * Revision 1.28  1998/09/23 06:21:06  robertj
00084  * Added open source copyright license.
00085  *
00086  * Revision 1.27  1998/03/05 12:44:34  robertj
00087  * Added cluster size.
00088  *
00089  * Revision 1.26  1997/03/31 11:34:00  robertj
00090  * Fixed default permissions for directories , different from that for files.
00091  *
00092  * Revision 1.25  1997/01/12 04:22:21  robertj
00093  * Added function to get disk size and free space.
00094  *
00095  * Revision 1.24  1995/12/23 03:45:31  robertj
00096  * Added constructor for C string literals.
00097  *
00098  * Revision 1.23  1995/11/09 12:17:23  robertj
00099  * Added platform independent base type access classes.
00100  *
00101  * Revision 1.22  1995/10/14 15:02:22  robertj
00102  * Added function to get parent directory.
00103  *
00104  * Revision 1.21  1995/06/17 11:12:52  robertj
00105  * Documentation update.
00106  *
00107  * Revision 1.20  1995/03/14 12:42:00  robertj
00108  * Updated documentation to use HTML codes.
00109  *
00110  * Revision 1.19  1995/03/12  04:42:48  robertj
00111  * Updated documentation.
00112  * Changed return type of functions to the correct case string.
00113  *
00114  * Revision 1.18  1995/02/22  10:50:33  robertj
00115  * Changes required for compiling release (optimised) version.
00116  *
00117  * Revision 1.17  1995/01/06  10:42:25  robertj
00118  * Moved identifiers into different scope.
00119  * Changed file size to 64 bit integer.
00120  * Documentation
00121  *
00122  * Revision 1.16  1994/10/24  00:07:03  robertj
00123  * Changed PFilePath and PDirectory so descends from either PString or
00124  *     PCaselessString depending on the platform.
00125  *
00126  * Revision 1.15  1994/10/23  04:49:25  robertj
00127  * Chnaged PDirectory to descend of PString.
00128  * Added PDirectory Exists() function.
00129  *
00130  * Revision 1.14  1994/08/23  11:32:52  robertj
00131  * Oops
00132  *
00133  * Revision 1.13  1994/08/22  00:46:48  robertj
00134  * Added pragma fro GNU C++ compiler.
00135  *
00136  * Revision 1.12  1994/06/25  11:55:15  robertj
00137  * Unix version synchronisation.
00138  *
00139  * Revision 1.11  1994/04/20  12:17:44  robertj
00140  * Split name into PFilePath
00141  *
00142  * Revision 1.10  1994/04/11  14:16:27  robertj
00143  * Added function for determining if character is a valid directory separator.
00144  *
00145  * Revision 1.9  1994/04/01  14:14:57  robertj
00146  * Put platform independent file permissions and type codes back.
00147  *
00148  * Revision 1.7  1994/01/13  03:17:55  robertj
00149  * Added functions to get the name of the volume the directory is contained in
00150  *    and a function to determine if the directory is a root directory of the
00151  *    volume (ie is does not have a parent directory).
00152  *
00153  * Revision 1.6  1994/01/03  04:42:23  robertj
00154  * Mass changes to common container classes and interactors etc etc etc.
00155  *
00156  * Revision 1.5  1993/12/31  06:45:38  robertj
00157  * Made inlines optional for debugging purposes.
00158  *
00159  * Revision 1.4  1993/08/21  01:50:33  robertj
00160  * Made Clone() function optional, default will assert if called.
00161  *
00162  * Revision 1.3  1993/07/14  12:49:16  robertj
00163  * Fixed RCS keywords.
00164  *
00165  */
00166 
00167 
00168 #ifndef _PDIRECTORY
00169 #define _PDIRECTORY
00170 
00171 #ifdef P_USE_PRAGMA
00172 #pragma interface
00173 #endif
00174 
00175 #ifdef Fifo
00176 #undef Fifo
00177 #endif
00178 
00179 #ifdef _WIN32
00180 #define PDIR_SEPARATOR '\\'
00181 const PINDEX P_MAX_PATH = _MAX_PATH;
00182 typedef PCaselessString PFilePathString;
00183 #else
00184 #define PDIR_SEPARATOR '/'
00185 #define P_MAX_PATH    (_POSIX_PATH_MAX)
00186 typedef PString PFilePathString;
00187 #endif
00188 
00190 // File System
00191 
00196 class PFileInfo : public PObject
00197 {
00198   PCLASSINFO(PFileInfo, PObject);
00199 
00200   public:
00205     enum FileTypes {
00207       RegularFile = 1,        
00209       SymbolicLink = 2,       
00211       SubDirectory = 4,       
00213       CharDevice = 8,         
00215       BlockDevice = 16,       
00217       Fifo = 32,              
00219       SocketDevice = 64,      
00221       UnknownFileType = 256,  
00223       AllFiles = 0x1ff        
00224     };
00225 
00227     FileTypes type;
00228 
00232     PTime created;
00233 
00235     PTime modified;
00236 
00240     PTime accessed;
00241 
00245     PUInt64 size;
00246 
00248     enum Permissions {
00250       WorldExecute = 1,   
00252       WorldWrite = 2,     
00254       WorldRead = 4,      
00256       GroupExecute = 8,   
00258       GroupWrite = 16,    
00260       GroupRead = 32,     
00262       UserExecute = 64,   
00264       UserWrite = 128,    
00266       UserRead = 256,     
00268       AllPermissions = 0x1ff,   
00270       DefaultPerms = UserRead|UserWrite|GroupRead|WorldRead,
00272       DefaultDirPerms = DefaultPerms|UserExecute|GroupExecute|WorldExecute
00273       
00274     };
00275 
00281     int permissions;
00282 
00287     BOOL hidden;
00288 };
00289 
00290 
00315 class PDirectory : public PFilePathString
00316 {
00317   PCONTAINERINFO(PDirectory, PFilePathString);
00318 
00319   public:
00322 
00323     PDirectory();
00324       
00329     PDirectory(
00330       const char * cpathname      
00331     );
00332 
00337     PDirectory(
00338       const PString & pathname    
00339     );
00340 
00343     PDirectory & operator=(
00344       const PString & pathname    
00345     );
00346 
00349     PDirectory & operator=(
00350       const char * cpathname      
00351     );
00353 
00363     PDirectory GetParent() const;
00364 
00375     PFilePathString GetVolume() const;
00376 
00382     BOOL IsRoot() const;
00383 
00389     PDirectory GetRoot() const;
00390 
00395     PStringArray GetPath() const;
00396 
00403     PINLINE static BOOL IsSeparator(
00404       char ch    
00405     );
00406 
00417     BOOL GetVolumeSpace(
00418       PInt64 & total,     
00419       PInt64 & free,      
00420       DWORD & clusterSize 
00421     ) const;
00423 
00431     BOOL Exists() const;
00432 
00438     static BOOL Exists(
00439       const PString & path   
00440     );
00441       
00447     BOOL Change() const;
00448 
00454     static BOOL Change(
00455       const PString & path   
00456     );
00457       
00463     BOOL Create(
00464       int perm = PFileInfo::DefaultDirPerms    // Permission on new directory.
00465     ) const;
00471     static BOOL Create(
00472       const PString & p,   
00473       int perm = PFileInfo::DefaultDirPerms    
00474     );
00475 
00481     BOOL Remove();
00482 
00488     static BOOL Remove(
00489       const PString & path   
00490     );
00492 
00510     virtual BOOL Open(
00511       int scanMask = PFileInfo::AllFiles    
00512     );
00513       
00528     virtual BOOL Restart(
00529       int scanMask = PFileInfo::AllFiles    
00530     );
00531       
00543     BOOL Next();
00544       
00546     virtual void Close();
00547 
00562     virtual PFilePathString GetEntryName() const;
00563 
00573     virtual BOOL IsSubDir() const;
00574 
00580     virtual BOOL GetInfo(
00581       PFileInfo & info    
00582     ) const;
00584 
00585 
00586   protected:
00587     // New functions for class
00588     void Construct();
00589     void Destruct()
00590     { Close(); PFilePathString::Destruct(); }
00591 
00592     // Member variables
00594     int scanMask;
00595 
00596 // Include platform dependent part of class
00597 #ifdef _WIN32
00598 #include "msos/ptlib/pdirect.h"
00599 #else
00600 #include "unix/ptlib/pdirect.h"
00601 #endif
00602 
00603 };
00604 
00605 #endif
00606 
00607 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1