(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            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34            #ifndef Pegasus_Dir_h
 35            #define Pegasus_Dir_h
 36            
 37            #include <Pegasus/Common/Config.h>
 38            #include <Pegasus/Common/String.h>
 39 kumpf 1.11 #include <Pegasus/Common/InternalException.h>
 40 kumpf 1.10 #include <Pegasus/Common/Linkage.h>
 41 david.dillard 1.24 #include <Pegasus/Common/AutoPtr.h>
 42 mike          1.8  
 43 jim.wunderlich 1.25 #if defined(PEGASUS_PLATFORM_SOLARIS_SPARC_GNU)
 44                     # include <sys/param.h>
 45                     # include <dirent.h>
 46                     #endif
 47 marek          1.26 #ifdef PEGASUS_OS_ZOS
 48 carson.hovey   1.30.4.1 # include <dirent.h>
 49 marek          1.26     #endif
 50 jim.wunderlich 1.25     
 51 mike           1.8      PEGASUS_NAMESPACE_BEGIN
 52                         
 53 a.arora        1.15     #if defined(PEGASUS_OS_TYPE_WINDOWS)
 54 carson.hovey   1.30.4.1 # include <io.h>
 55                          typedef struct
 56                          {
 57                         # if _MSC_VER < 1300
 58 a.arora        1.15         long file;
 59 carson.hovey   1.30.4.1 # else
 60 david.dillard  1.24         intptr_t file;
 61 carson.hovey   1.30.4.1 # endif
 62 a.arora        1.15         struct _finddata_t findData;
 63 carson.hovey   1.30.4.1  } DirRep;
 64 gs.keenan      1.21     #elif defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS)
 65 carson.hovey   1.30.4.1 # if defined(PEGASUS_OS_SOLARIS)
 66                         #  include <sys/param.h>
 67                         # endif /* if defined(PEGASUS_OS_SOLARIS) */
 68 gs.keenan      1.21     
 69 carson.hovey   1.30.4.1 # include <dirent.h>
 70 gs.keenan      1.21     
 71 carson.hovey   1.30.4.1 # define PEGASUS_HAS_READDIR_R
 72 a.arora        1.15     
 73 carson.hovey   1.30.4.1  struct DirRep
 74                          {
 75 a.arora        1.15         DIR* dir;
 76 carson.hovey   1.30.4.1 # ifdef PEGASUS_OS_OS400
 77 a.arora        1.15         struct dirent_lg* entry;
 78 carson.hovey   1.30.4.1 # else /* ifdef PEGASUS_OS_OS400 */
 79 a.arora        1.15         struct dirent* entry;
 80 carson.hovey   1.30.4.1 # endif /* ifdef PEGASUS_OS_OS400 */
 81                         # ifdef PEGASUS_HAS_READDIR_R
 82                         #  ifdef PEGASUS_OS_OS400
 83                              struct dirent_lg buffer;
 84                         #  else /* ifdef PEGASUS_OS_OS400 */
 85                         #   ifdef PEGASUS_OS_SOLARIS
 86 a.arora        1.15     private:
 87                                 char buf[sizeof(dirent) + MAXNAMELEN];
 88                         public:
 89                                 struct dirent &buffer;
 90                                 inline DirRep()
 91                                         : buffer(*reinterpret_cast<struct dirent *>(buf))
 92                                 { }
 93 carson.hovey   1.30.4.1 #   else /* ifdef PEGASUS_OS_SOLARIS */
 94 a.arora        1.15         struct dirent buffer;
 95 carson.hovey   1.30.4.1 #   endif /* ifdef PEGASUS_OS_SOLARIS */
 96                         #  endif /* ifdef PEGASUS_OS_OS400 */
 97                         # endif /* ifdef PEGASUS_HAS_READDIR_R */
 98 david.dillard  1.23     };
 99 gs.keenan      1.21     #endif /* elif defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS) */
100 mike           1.8      
101                         /** The Dir class provides a platform independent way of iterating the
102                             files in a directory.
103                         */
104                         class PEGASUS_COMMON_LINKAGE Dir
105                         {
106                         public:
107                         
108                             /** Starts this iterator class on the given path.
109 kumpf          1.29             @param String path is the path to the target directory
110                                 @return
111                                 @exception throws CannotOpenDirectory if invalid directory.
112                         
113                                 <pre>
114                                 char* path = "."
115                                 try
116                                 {
117                                    for (Dir dir(path); dir.more(); dir.next())
118                                    {
119                                        cout << "name: " << dir.getName() << endl;
120                                    }
121                                 }
122 kumpf          1.30             catch (CannotOpenDirectory&)
123 kumpf          1.29             {
124                                    // Error!
125                                 }
126                                 </pre>
127 mike           1.8          */
128                             Dir(const String& path);
129                         
130                             /** Release any iterator resources. */
131                             ~Dir();
132                         
133                             /** Return true if there are more file names to iterator. */
134                             Boolean more() const { return _more; }
135 david.dillard  1.24     
136 mike           1.8      
137                             /** Returns the current file name. */
138                             const char* getName() const;
139                         
140                             /** Advance to next file in directory. */
141                             void next();
142                         
143                         private:
144                         
145                             Boolean _more;
146                             Boolean _isValid;
147 kumpf          1.12         String _path;
148 a.arora        1.15         DirRep _dirRep;
149 mike           1.8      };
150                         
151                         PEGASUS_NAMESPACE_END
152                         
153                         #endif /* Pegasus_Dir_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2