1 martin 1.34 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.35 //
|
3 martin 1.34 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.35 //
|
10 martin 1.34 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.35 //
|
17 martin 1.34 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.35 //
|
20 martin 1.34 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.35 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.34 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.35 //
|
28 martin 1.34 //////////////////////////////////////////////////////////////////////////
|
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 david.dillard 1.24 #include <Pegasus/Common/AutoPtr.h>
|
40 mike 1.8
|
41 kumpf 1.33 #if defined(PEGASUS_OS_SOLARIS)
|
42 jim.wunderlich 1.25 # include <sys/param.h>
43 #endif
|
44 kumpf 1.33
45 #if defined(PEGASUS_OS_TYPE_WINDOWS)
46 # include <io.h>
47 #else // if defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS)
|
48 carson.hovey 1.31 # 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 kumpf 1.33
55 typedef struct
56 {
|
57 carson.hovey 1.31 # if _MSC_VER < 1300
|
58 a.arora 1.15 long file;
|
59 carson.hovey 1.31 # else
|
60 david.dillard 1.24 intptr_t file;
|
61 carson.hovey 1.31 # endif
|
62 a.arora 1.15 struct _finddata_t findData;
|
63 kumpf 1.33 } DirRep;
|
64 gs.keenan 1.21
|
65 kumpf 1.33 #else // if defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS)
|
66 gs.keenan 1.21
|
67 kumpf 1.33 struct DirRep
68 {
|
69 a.arora 1.15 DIR* dir;
70 struct dirent* entry;
|
71 kumpf 1.33
72 # ifdef PEGASUS_OS_SOLARIS
|
73 a.arora 1.15 private:
|
74 kumpf 1.33 char buf[sizeof(dirent) + MAXNAMELEN];
|
75 a.arora 1.15 public:
|
76 kumpf 1.33 struct dirent& buffer;
77 inline DirRep()
78 : buffer(*reinterpret_cast<struct dirent *>(buf))
79 { }
80 # else /* ifdef PEGASUS_OS_SOLARIS */
|
81 a.arora 1.15 struct dirent buffer;
|
82 kumpf 1.33 # endif /* ifdef PEGASUS_OS_SOLARIS */
|
83 david.dillard 1.23 };
|
84 kumpf 1.33 #endif
|
85 mike 1.8
86 /** The Dir class provides a platform independent way of iterating the
87 files in a directory.
88 */
89 class PEGASUS_COMMON_LINKAGE Dir
90 {
91 public:
92
93 /** Starts this iterator class on the given path.
|
94 kumpf 1.29 @param String path is the path to the target directory
95 @return
96 @exception throws CannotOpenDirectory if invalid directory.
97
98 <pre>
99 char* path = "."
100 try
101 {
102 for (Dir dir(path); dir.more(); dir.next())
103 {
104 cout << "name: " << dir.getName() << endl;
105 }
106 }
|
107 kumpf 1.30 catch (CannotOpenDirectory&)
|
108 kumpf 1.29 {
109 // Error!
110 }
111 </pre>
|
112 mike 1.8 */
113 Dir(const String& path);
114
115 /** Release any iterator resources. */
116 ~Dir();
117
118 /** Return true if there are more file names to iterator. */
119 Boolean more() const { return _more; }
|
120 david.dillard 1.24
|
121 mike 1.8
122 /** Returns the current file name. */
123 const char* getName() const;
124
125 /** Advance to next file in directory. */
126 void next();
127
128 private:
129
130 Boolean _more;
|
131 kumpf 1.12 String _path;
|
132 a.arora 1.15 DirRep _dirRep;
|
133 mike 1.8 };
134
135 PEGASUS_NAMESPACE_END
136
137 #endif /* Pegasus_Dir_h */
|