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  * $Revision: 21788 $
00030  * $Author: rjongbloed $
00031  * $Date: 2008-12-11 23:42:13 -0600 (Thu, 11 Dec 2008) $
00032  */
00033 
00034 
00035 #ifndef PTLIB_DIRECTORY_H
00036 #define PTLIB_DIRECTORY_H
00037 
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041 
00042 #ifdef Fifo
00043 #undef Fifo
00044 #endif
00045 
00046 #ifdef _WIN32
00047 #define PDIR_SEPARATOR '\\'
00048 const PINDEX P_MAX_PATH = _MAX_PATH;
00049 typedef PCaselessString PFilePathString;
00050 #else
00051 #define PDIR_SEPARATOR '/'
00052 #define P_MAX_PATH    (_POSIX_PATH_MAX)
00053 typedef PString PFilePathString;
00054 #endif
00055 
00057 // File System
00058 
00063 class PFileInfo : public PObject
00064 {
00065   PCLASSINFO(PFileInfo, PObject);
00066 
00067   public:
00072     enum FileTypes {
00074       RegularFile = 1,        
00076       SymbolicLink = 2,       
00078       SubDirectory = 4,       
00080       CharDevice = 8,         
00082       BlockDevice = 16,       
00084       Fifo = 32,              
00086       SocketDevice = 64,      
00088       UnknownFileType = 256,  
00090       AllFiles = 0x1ff        
00091     };
00092 
00094     FileTypes type;
00095 
00099     PTime created;
00100 
00102     PTime modified;
00103 
00107     PTime accessed;
00108 
00112     PUInt64 size;
00113 
00115     enum Permissions {
00117       WorldExecute = 1,   
00119       WorldWrite = 2,     
00121       WorldRead = 4,      
00123       GroupExecute = 8,   
00125       GroupWrite = 16,    
00127       GroupRead = 32,     
00129       UserExecute = 64,   
00131       UserWrite = 128,    
00133       UserRead = 256,     
00135       AllPermissions = 0x1ff,   
00137       DefaultPerms = UserRead|UserWrite|GroupRead|WorldRead,
00139       DefaultDirPerms = DefaultPerms|UserExecute|GroupExecute|WorldExecute
00140       
00141     };
00142 
00148     int permissions;
00149 
00154     PBoolean hidden;
00155 };
00156 
00157 
00182 class PDirectory : public PFilePathString
00183 {
00184   PCONTAINERINFO(PDirectory, PFilePathString);
00185 
00186   public:
00189 
00190     PDirectory();
00191       
00196     PDirectory(
00197       const char * cpathname      
00198     );
00199 
00204     PDirectory(
00205       const PString & pathname    
00206     );
00207 
00210     PDirectory & operator=(
00211       const PString & pathname    
00212     );
00213 
00216     PDirectory & operator=(
00217       const char * cpathname      
00218     );
00220 
00230     PDirectory GetParent() const;
00231 
00242     PFilePathString GetVolume() const;
00243 
00249     PBoolean IsRoot() const;
00250 
00256     PDirectory GetRoot() const;
00257 
00262     PStringArray GetPath() const;
00263 
00270     PINLINE static PBoolean IsSeparator(
00271       char ch    
00272     );
00273 
00284     PBoolean GetVolumeSpace(
00285       PInt64 & total,     
00286       PInt64 & free,      
00287       DWORD & clusterSize 
00288     ) const;
00290 
00298     PBoolean Exists() const;
00299 
00305     static PBoolean Exists(
00306       const PString & path   
00307     );
00308       
00314     PBoolean Change() const;
00315 
00321     static PBoolean Change(
00322       const PString & path   
00323     );
00324       
00330     PBoolean Create(
00331       int perm = PFileInfo::DefaultDirPerms    // Permission on new directory.
00332     ) const;
00338     static PBoolean Create(
00339       const PString & p,   
00340       int perm = PFileInfo::DefaultDirPerms    
00341     );
00342 
00348     PBoolean Remove();
00349 
00355     static PBoolean Remove(
00356       const PString & path   
00357     );
00359 
00377     virtual PBoolean Open(
00378       int scanMask = PFileInfo::AllFiles    
00379     );
00380       
00395     virtual PBoolean Restart(
00396       int scanMask = PFileInfo::AllFiles    
00397     );
00398       
00410     PBoolean Next();
00411       
00413     virtual void Close();
00414 
00429     virtual PFilePathString GetEntryName() const;
00430 
00440     virtual PBoolean IsSubDir() const;
00441 
00447     virtual PBoolean GetInfo(
00448       PFileInfo & info    
00449     ) const;
00451 
00452 
00453   protected:
00454     // New functions for class
00455     void Construct();
00456     void Destruct()
00457     { Close(); PFilePathString::Destruct(); }
00458 
00459     // Member variables
00461     int scanMask;
00462 
00463 // Include platform dependent part of class
00464 #ifdef _WIN32
00465 #include "msos/ptlib/pdirect.h"
00466 #else
00467 #include "unix/ptlib/pdirect.h"
00468 #endif
00469 
00470 };
00471 
00472 
00473 #endif // PTLIB_DIRECTORY_H
00474 
00475 
00476 // End Of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:48 2010 for PTLib by  doxygen 1.4.7