(file) Return to Dir.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 karl  1.27 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.8  //
  3 karl  1.17 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.13 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.17 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.22 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.27 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.8  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15 kumpf 1.9  // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18 mike  1.8  // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20 karl  1.27 // 
 21 kumpf 1.9  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.8  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24 kumpf 1.9  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27 mike  1.8  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            // Author: Mike Brasher (mbrasher@bmc.com)
 33            //
 34 a.arora 1.14 // Modified By: Amit K Arora, IBM (amita@in.ibm.com)
 35 david.dillard 1.24 //              David Dillard, VERITAS Software Corp.
 36                    //                  (david.dillard@veritas.com)
 37 mike          1.8  //
 38                    //%/////////////////////////////////////////////////////////////////////////////
 39                    
 40                    #ifndef Pegasus_Dir_h
 41                    #define Pegasus_Dir_h
 42                    
 43                    #include <Pegasus/Common/Config.h>
 44                    #include <Pegasus/Common/String.h>
 45 kumpf         1.11 #include <Pegasus/Common/InternalException.h>
 46 kumpf         1.10 #include <Pegasus/Common/Linkage.h>
 47 david.dillard 1.24 #include <Pegasus/Common/AutoPtr.h>
 48 mike          1.8  
 49 jim.wunderlich 1.25 #if defined(PEGASUS_PLATFORM_SOLARIS_SPARC_GNU)
 50                     # include <sys/param.h>
 51                     # include <dirent.h>
 52                     #endif
 53 marek          1.26 #ifdef PEGASUS_OS_ZOS
 54                     #include <dirent.h>
 55                     #endif
 56 jim.wunderlich 1.25 
 57 mike           1.8  PEGASUS_NAMESPACE_BEGIN
 58                     
 59 a.arora        1.15 #if defined(PEGASUS_OS_TYPE_WINDOWS)
 60 gs.keenan      1.21  #include <io.h>
 61 david.dillard  1.24 typedef struct
 62 a.arora        1.15 {
 63 david.dillard  1.24 #if _MSC_VER < 1300
 64 a.arora        1.15     long file;
 65 david.dillard  1.24 #else
 66                         intptr_t file;
 67                     #endif
 68 a.arora        1.15     struct _finddata_t findData;
 69                     } DirRep;
 70 gs.keenan      1.21 #elif defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS)
 71                      #if defined(PEGASUS_OS_SOLARIS)
 72                       #include <sys/param.h>
 73                      #endif /* if defined(PEGASUS_OS_SOLARIS) */
 74                     
 75                      #include <dirent.h>
 76                     
 77                      #ifndef PEGASUS_OS_VMS
 78                       #define PEGASUS_HAS_READDIR_R
 79                      #endif /* ifndef PEGASUS_OS_VMS */
 80 a.arora        1.15 
 81 david.dillard  1.23 struct DirRep
 82 a.arora        1.15 {
 83                         DIR* dir;
 84 gs.keenan      1.21  #ifdef PEGASUS_OS_OS400
 85 a.arora        1.15     struct dirent_lg* entry;
 86 gs.keenan      1.21  #else /* ifdef PEGASUS_OS_OS400 */
 87 a.arora        1.15     struct dirent* entry;
 88 gs.keenan      1.21  #endif /* ifdef PEGASUS_OS_OS400 */
 89                      #ifdef PEGASUS_HAS_READDIR_R
 90                       #ifdef PEGASUS_OS_OS400
 91 a.arora        1.15     struct dirent_lg buffer;
 92 gs.keenan      1.21   #else /* ifdef PEGASUS_OS_OS400 */
 93                        #ifdef PEGASUS_OS_SOLARIS
 94 a.arora        1.15 private:
 95                             char buf[sizeof(dirent) + MAXNAMELEN];
 96                     public:
 97                             struct dirent &buffer;
 98                             inline DirRep()
 99                                     : buffer(*reinterpret_cast<struct dirent *>(buf))
100                             { }
101 gs.keenan      1.21    #else /* ifdef PEGASUS_OS_SOLARIS */
102 a.arora        1.15     struct dirent buffer;
103 gs.keenan      1.21    #endif /* ifdef PEGASUS_OS_SOLARIS */
104                       #endif /* ifdef PEGASUS_OS_OS400 */
105                      #endif /* ifdef PEGASUS_HAS_READDIR_R */
106 david.dillard  1.23 };
107 gs.keenan      1.21 #endif /* elif defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS) */
108 mike           1.8  
109                     /** The Dir class provides a platform independent way of iterating the
110                         files in a directory.
111                     */
112                     class PEGASUS_COMMON_LINKAGE Dir
113                     {
114                     public:
115                     
116                         /** Starts this iterator class on the given path.
117 david.dillard  1.24 	@param String path is the path to the target directory
118 mike           1.8  	@return
119                     	@exception throws CannotOpenDirectory if invalid directory.
120                     
121                     	<pre>
122                     	char* path = "."
123                     	try
124 david.dillard  1.24 	{
125 mike           1.8  	   for (Dir dir(path); dir.more(); dir.next())
126                     	   {
127                     	       cout << "name: " << dir.getName() << endl;
128                     	   }
129                     	}
130                     	catch(CannotOpenDirectory&)
131                     	{
132                     	   // Error!
133                     	}
134                     	</pre>
135                         */
136                         Dir(const String& path);
137                     
138                         /** Release any iterator resources. */
139                         ~Dir();
140                     
141                         /** Return true if there are more file names to iterator. */
142                         Boolean more() const { return _more; }
143 david.dillard  1.24 
144 mike           1.8  
145                         /** Returns the current file name. */
146                         const char* getName() const;
147                     
148                         /** Advance to next file in directory. */
149                         void next();
150                     
151                     private:
152                     
153                         Boolean _more;
154                         Boolean _isValid;
155 kumpf          1.12     String _path;
156 a.arora        1.15     DirRep _dirRep;
157 mike           1.8  };
158                     
159                     PEGASUS_NAMESPACE_END
160                     
161                     #endif /* Pegasus_Dir_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2