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

  1 karl  1.17 //%2004////////////////////////////////////////////////////////////////////////
  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 mike  1.8  //
 10            // Permission is hereby granted, free of charge, to any person obtaining a copy
 11 kumpf 1.9  // of this software and associated documentation files (the "Software"), to
 12            // deal in the Software without restriction, including without limitation the
 13            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 14 mike  1.8  // sell copies of the Software, and to permit persons to whom the Software is
 15            // furnished to do so, subject to the following conditions:
 16            // 
 17 kumpf 1.9  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 18 mike  1.8  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 19            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 20 kumpf 1.9  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 21            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 22            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 23 mike  1.8  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 24            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25            //
 26            //==============================================================================
 27            //
 28            // Author: Mike Brasher (mbrasher@bmc.com)
 29            //
 30 a.arora 1.14 // Modified By: Amit K Arora, IBM (amita@in.ibm.com)
 31 mike    1.8  //
 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 a.arora 1.14 #include <Pegasus/Common/AutoPtr.h> 
 42 mike    1.8  
 43              PEGASUS_NAMESPACE_BEGIN
 44              
 45 a.arora 1.15 #if defined(PEGASUS_OS_TYPE_WINDOWS)
 46              #include <io.h>
 47              typedef struct 
 48              {
 49                  long file;
 50                  struct _finddata_t findData;
 51              } DirRep;
 52              #elif defined(PEGASUS_OS_TYPE_UNIX)
 53 david.dillard 1.16 #ifdef PEGASUS_OS_SOLARIS
 54                    #include <sys/param.h>
 55                    #endif
 56 a.arora       1.15 #include <dirent.h>
 57                    
 58                    // ATTN: If a platform is found that does not have the readdir_r interface,
 59                    // this next line should be conditionally compiled out for that platform.
 60                    // Otherwise, the old readdir code can be removed.
 61                    #define PEGASUS_HAS_READDIR_R
 62                    
 63 david.dillard 1.19 struct DirRep
 64 a.arora       1.15 {
 65                        DIR* dir;
 66                    #ifdef PEGASUS_OS_OS400
 67                        struct dirent_lg* entry;
 68                    #else
 69                        struct dirent* entry;
 70                    #endif
 71                    #ifdef PEGASUS_HAS_READDIR_R
 72                    #ifdef PEGASUS_OS_OS400
 73                        struct dirent_lg buffer;
 74                    #else
 75                    #ifdef PEGASUS_OS_SOLARIS
 76                    private:
 77                            char buf[sizeof(dirent) + MAXNAMELEN];
 78                    public:
 79                            struct dirent &buffer;
 80                            inline DirRep()
 81                                    : buffer(*reinterpret_cast<struct dirent *>(buf))
 82                            { }
 83                    #else
 84                        struct dirent buffer;
 85 a.arora       1.15 #endif
 86                    #endif
 87                    #endif
 88 david.dillard 1.16 };
 89 a.arora       1.15 #endif
 90 mike          1.8  
 91                    /** The Dir class provides a platform independent way of iterating the
 92                        files in a directory.
 93                    */
 94                    class PEGASUS_COMMON_LINKAGE Dir
 95                    {
 96                    public:
 97                    
 98                        /** Starts this iterator class on the given path.
 99                    	@param String path is the path to the target directory 
100                    	@return
101                    	@exception throws CannotOpenDirectory if invalid directory.
102                    
103                    	<pre>
104                    	char* path = "."
105                    	try
106                    	{ 
107                    	   for (Dir dir(path); dir.more(); dir.next())
108                    	   {
109                    	       cout << "name: " << dir.getName() << endl;
110                    	   }
111 mike          1.8  	}
112                    	catch(CannotOpenDirectory&)
113                    	{
114                    	   // Error!
115                    	}
116                    	</pre>
117                        */
118                        Dir(const String& path);
119                    
120                        /** Release any iterator resources. */
121                        ~Dir();
122                    
123                        /** Return true if there are more file names to iterator. */
124                        Boolean more() const { return _more; }
125 bafna.mukesh  1.18  
126                        #if defined(PEGASUS_PLATFORM_DARWIN_PPC_GNU)
127                        /** Returns the file inode number. */
128                        const Uint32 getInode() const;
129                        #endif
130 mike          1.8  
131                        /** Returns the current file name. */
132                        const char* getName() const;
133                    
134                        /** Advance to next file in directory. */
135                        void next();
136                    
137                    private:
138                    
139                        Boolean _more;
140                        Boolean _isValid;
141 kumpf         1.12     String _path;
142 a.arora       1.15     DirRep _dirRep;
143 mike          1.8  };
144                    
145                    PEGASUS_NAMESPACE_END
146                    
147                    #endif /* Pegasus_Dir_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2