root / trunk / tbeta / Linux / libs / poco / include / Poco / DirectoryIterator.h @ 164

View | Annotate | Download (4.5 KB)

1 164 ss
//
2 164 ss
// DirectoryIterator.h
3 164 ss
//
4 164 ss
// $Id: //poco/1.3/Foundation/include/Poco/DirectoryIterator.h#2 $
5 164 ss
//
6 164 ss
// Library: Foundation
7 164 ss
// Package: Filesystem
8 164 ss
// Module:  DirectoryIterator
9 164 ss
//
10 164 ss
// Definition of the DirectoryIterator class.
11 164 ss
//
12 164 ss
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13 164 ss
// and Contributors.
14 164 ss
//
15 164 ss
// Permission is hereby granted, free of charge, to any person or organization
16 164 ss
// obtaining a copy of the software and accompanying documentation covered by
17 164 ss
// this license (the "Software") to use, reproduce, display, distribute,
18 164 ss
// execute, and transmit the Software, and to prepare derivative works of the
19 164 ss
// Software, and to permit third-parties to whom the Software is furnished to
20 164 ss
// do so, all subject to the following:
21 164 ss
//
22 164 ss
// The copyright notices in the Software and this entire statement, including
23 164 ss
// the above license grant, this restriction and the following disclaimer,
24 164 ss
// must be included in all copies of the Software, in whole or in part, and
25 164 ss
// all derivative works of the Software, unless such copies or derivative
26 164 ss
// works are solely in the form of machine-executable object code generated by
27 164 ss
// a source language processor.
28 164 ss
//
29 164 ss
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 164 ss
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 164 ss
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32 164 ss
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33 164 ss
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34 164 ss
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 164 ss
// DEALINGS IN THE SOFTWARE.
36 164 ss
//
37 164 ss
38 164 ss
39 164 ss
#ifndef Foundation_DirectoryIterator_INCLUDED
40 164 ss
#define Foundation_DirectoryIterator_INCLUDED
41 164 ss
42 164 ss
43 164 ss
#include "Poco/Foundation.h"
44 164 ss
#include "Poco/File.h"
45 164 ss
#include "Poco/Path.h"
46 164 ss
47 164 ss
48 164 ss
namespace Poco {
49 164 ss
50 164 ss
51 164 ss
class DirectoryIteratorImpl;
52 164 ss
53 164 ss
54 164 ss
class Foundation_API DirectoryIterator
55 164 ss
        /// The DirectoryIterator class is used to enumerate
56 164 ss
        /// all files in a directory.
57 164 ss
        ///
58 164 ss
        /// DirectoryIterator has some limitations:
59 164 ss
        ///   * only forward iteration (++) is supported
60 164 ss
        ///   * an iterator copied from another one will always
61 164 ss
        ///     point to the same file as the original iterator,
62 164 ss
        ///     even is the original iterator has been advanced
63 164 ss
        ///     (all copies of an iterator share their state with
64 164 ss
        ///     the original iterator)
65 164 ss
        ///   * because of this you should only use the prefix
66 164 ss
        ///     increment operator
67 164 ss
{
68 164 ss
public:
69 164 ss
        DirectoryIterator();
70 164 ss
                /// Creates the end iterator.
71 164 ss
72 164 ss
        DirectoryIterator(const std::string& path);
73 164 ss
                /// Creates a directory iterator for the given path.
74 164 ss
75 164 ss
        DirectoryIterator(const DirectoryIterator& iterator);
76 164 ss
                /// Creates a directory iterator for the given path.
77 164 ss
78 164 ss
        DirectoryIterator(const File& file);
79 164 ss
                /// Creates a directory iterator for the given file.
80 164 ss
81 164 ss
        DirectoryIterator(const Path& path);
82 164 ss
                /// Creates a directory iterator for the given path.
83 164 ss
84 164 ss
        ~DirectoryIterator();
85 164 ss
                /// Destroys the DirectoryIterator.
86 164 ss
87 164 ss
        const std::string& name() const;
88 164 ss
                /// Returns the current filename.
89 164 ss
90 164 ss
        const Path& path() const;
91 164 ss
                /// Returns the current path.
92 164 ss
93 164 ss
        DirectoryIterator& operator = (const DirectoryIterator& it);
94 164 ss
        DirectoryIterator& operator = (const File& file);
95 164 ss
        DirectoryIterator& operator = (const Path& path);
96 164 ss
        DirectoryIterator& operator = (const std::string& path);
97 164 ss
98 164 ss
        DirectoryIterator& operator ++ ();   // prefix
99 164 ss
100 164 ss
        //@ deprecated
101 164 ss
        DirectoryIterator operator ++ (int); // postfix
102 164 ss
                /// Please use the prefix increment operator instead.
103 164 ss
104 164 ss
        const File& operator * () const;
105 164 ss
        File& operator * ();
106 164 ss
        const File* operator -> () const;
107 164 ss
        File* operator -> ();
108 164 ss
109 164 ss
        bool operator == (const DirectoryIterator& iterator) const;
110 164 ss
        bool operator != (const DirectoryIterator& iterator) const;
111 164 ss
112 164 ss
private:
113 164 ss
        Path _path;
114 164 ss
        File _file;
115 164 ss
        DirectoryIteratorImpl* _pImpl;
116 164 ss
};
117 164 ss
118 164 ss
119 164 ss
//
120 164 ss
// inlines
121 164 ss
//
122 164 ss
inline const std::string& DirectoryIterator::name() const
123 164 ss
{
124 164 ss
        return _path.getFileName();
125 164 ss
}
126 164 ss
127 164 ss
128 164 ss
inline const Path& DirectoryIterator::path() const
129 164 ss
{
130 164 ss
        return _path;
131 164 ss
}
132 164 ss
133 164 ss
134 164 ss
inline const File& DirectoryIterator::operator * () const
135 164 ss
{
136 164 ss
        return _file;
137 164 ss
}
138 164 ss
139 164 ss
140 164 ss
inline File& DirectoryIterator::operator * ()
141 164 ss
{
142 164 ss
        return _file;
143 164 ss
}
144 164 ss
145 164 ss
146 164 ss
inline const File* DirectoryIterator::operator -> () const
147 164 ss
{
148 164 ss
        return &_file;
149 164 ss
}
150 164 ss
151 164 ss
152 164 ss
inline File* DirectoryIterator::operator -> ()
153 164 ss
{
154 164 ss
        return &_file;
155 164 ss
}
156 164 ss
157 164 ss
158 164 ss
inline bool DirectoryIterator::operator == (const DirectoryIterator& iterator) const
159 164 ss
{
160 164 ss
        return name() == iterator.name();
161 164 ss
}
162 164 ss
163 164 ss
164 164 ss
inline bool DirectoryIterator::operator != (const DirectoryIterator& iterator) const
165 164 ss
{
166 164 ss
        return name() != iterator.name();
167 164 ss
}
168 164 ss
169 164 ss
170 164 ss
} // namespace Poco
171 164 ss
172 164 ss
173 164 ss
#endif // Foundation_DirectoryIterator_INCLUDED