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 kumpf 1.33 #if defined(PEGASUS_OS_SOLARIS)
|
44 jim.wunderlich 1.25 # include <sys/param.h>
45 #endif
|
46 kumpf 1.33
47 #if defined(PEGASUS_OS_TYPE_WINDOWS)
48 # include <io.h>
49 #else // if defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS)
|
50 carson.hovey 1.31 # include <dirent.h>
|
51 marek 1.26 #endif
|
52 jim.wunderlich 1.25
|
53 mike 1.8 PEGASUS_NAMESPACE_BEGIN
54
|
55 a.arora 1.15 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
56 kumpf 1.33
57 typedef struct
58 {
|
59 carson.hovey 1.31 # if _MSC_VER < 1300
|
60 a.arora 1.15 long file;
|
61 carson.hovey 1.31 # else
|
62 david.dillard 1.24 intptr_t file;
|
63 carson.hovey 1.31 # endif
|
64 a.arora 1.15 struct _finddata_t findData;
|
65 kumpf 1.33 } DirRep;
|
66 gs.keenan 1.21
|
67 kumpf 1.33 #else // if defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS)
|
68 gs.keenan 1.21
|
69 kumpf 1.33 struct DirRep
70 {
|
71 a.arora 1.15 DIR* dir;
72 struct dirent* entry;
|
73 kumpf 1.33
74 # ifdef PEGASUS_OS_SOLARIS
|
75 a.arora 1.15 private:
|
76 kumpf 1.33 char buf[sizeof(dirent) + MAXNAMELEN];
|
77 a.arora 1.15 public:
|
78 kumpf 1.33 struct dirent& buffer;
79 inline DirRep()
80 : buffer(*reinterpret_cast<struct dirent *>(buf))
81 { }
82 # else /* ifdef PEGASUS_OS_SOLARIS */
|
83 a.arora 1.15 struct dirent buffer;
|
84 kumpf 1.33 # endif /* ifdef PEGASUS_OS_SOLARIS */
|
85 david.dillard 1.23 };
|
86 kumpf 1.33 #endif
|
87 mike 1.8
88 /** The Dir class provides a platform independent way of iterating the
89 files in a directory.
90 */
91 class PEGASUS_COMMON_LINKAGE Dir
92 {
93 public:
94
95 /** Starts this iterator class on the given path.
|
96 kumpf 1.29 @param String path is the path to the target directory
97 @return
98 @exception throws CannotOpenDirectory if invalid directory.
99
100 <pre>
101 char* path = "."
102 try
103 {
104 for (Dir dir(path); dir.more(); dir.next())
105 {
106 cout << "name: " << dir.getName() << endl;
107 }
108 }
|
109 kumpf 1.30 catch (CannotOpenDirectory&)
|
110 kumpf 1.29 {
111 // Error!
112 }
113 </pre>
|
114 mike 1.8 */
115 Dir(const String& path);
116
117 /** Release any iterator resources. */
118 ~Dir();
119
120 /** Return true if there are more file names to iterator. */
121 Boolean more() const { return _more; }
|
122 david.dillard 1.24
|
123 mike 1.8
124 /** Returns the current file name. */
125 const char* getName() const;
126
127 /** Advance to next file in directory. */
128 void next();
129
130 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 */
|