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